@staticmethod
    def add_nodes(xml, nodes):
        network_elems = xml.xpath('//network')
        if len(network_elems) > 0:
            network_elem = network_elems[0]
        elif len(nodes) > 0 and nodes[0].get('component_manager_id'):
            network_urn = nodes[0]['component_manager_id']
            network_elem = xml.add_element('network', name = Xrn(network_urn).get_hrn())
        else:
            network_elem = xml

        # needs to be improuved to retreive the gateway addr dynamically.
        gateway_addr = 'nitlab.inf.uth.gr'

        node_elems = []       
        for node in nodes:
            node_fields = ['component_manager_id', 'component_id', 'boot_state']
            node_elem = network_elem.add_instance('node', node, node_fields)
            node_elems.append(node_elem)

            # determine network hrn
            network_hrn = None 
            if 'component_manager_id' in node and node['component_manager_id']:
                network_hrn = Xrn(node['component_manager_id']).get_hrn()

            # set component_name attribute and  hostname element
            if 'component_id' in node and node['component_id']:
                component_name = Xrn(xrn=node['component_id']).get_leaf()
                node_elem.set('component_name', component_name)
                hostname_elem = node_elem.add_element('hostname')
                hostname_elem.set_text(component_name)

            # set site id
            if 'authority_id' in node and node['authority_id']:
                node_elem.set('site_id', node['authority_id'])

            # add locaiton
            location = node.get('location')
            if location:
                node_elem.add_instance('location', location, Location.fields)

            # add 3D Position of the node
            position_3d = node.get('position_3d')
            if position_3d:
                node_elem.add_instance('position_3d', position_3d, Position3D.fields)

            # all nitos nodes are exculsive
            exclusive_elem = node_elem.add_element('exclusive')
            exclusive_elem.set_text('TRUE')
 
            # In order to access nitos nodes, one need to pass through the nitos gateway
            # here we advertise Nitos access gateway address
            gateway_elem = node_elem.add_element('gateway')
            gateway_elem.set_text(gateway_addr)

            # add granularity of the reservation system
            granularity = node.get('granularity')['grain']
            if granularity:
                #node_elem.add_instance('granularity', granularity, granularity.fields)
                granularity_elem = node_elem.add_element('granularity')
                granularity_elem.set_text(str(granularity))
            # add hardware type
            #hardware_type = node.get('hardware_type')
            #if hardware_type:
            #    node_elem.add_instance('hardware_type', hardware_type)
            hardware_type_elem = node_elem.add_element('hardware_type')
            hardware_type_elem.set_text(node.get('hardware_type'))


            if isinstance(node.get('interfaces'), list):
                for interface in node.get('interfaces', []):
                    node_elem.add_instance('interface', interface, ['component_id', 'client_id', 'ipv4']) 
            
            #if 'bw_unallocated' in node and node['bw_unallocated']:
            #    bw_unallocated = etree.SubElement(node_elem, 'bw_unallocated', units='kbps').text = str(int(node['bw_unallocated'])/1000)

            PGv2Services.add_services(node_elem, node.get('services', []))
            tags = node.get('tags', [])
            if tags:
                for tag in tags:
                    tag_elem = node_elem.add_element(tag['tagname'])
                    tag_elem.set_text(tag['value'])
            NITOSv1Sliver.add_slivers(node_elem, node.get('slivers', []))
dataset/ETHPy150Open fp7-ofelia/ocf/optin_manager/src/python/openflow/optin_manager/sfa/rspecs/elements/versions/nitosv1Node.py/NITOSv1Node.add_nodes/original