def get_node_objs(node_elems): nodes = [] for node_elem in node_elems: node = NodeElement(node_elem.attrib, node_elem) if 'site_id' in node_elem.attrib: node['authority_id'] = node_elem.attrib['site_id'] # get location location_elems = node_elem.xpath('./default:location | ./location') locations = [ loc_elem.get_instance(Location) for loc_elem in location_elems ] if len(locations) > 0: node['location'] = locations[0] # get bwlimit bwlimit_elems = node_elem.xpath('./default:bw_limit | ./bw_limit') bwlimits = [ bwlimit_elem.get_instance(BWlimit) for bwlimit_elem in bwlimit_elems ] if len(bwlimits) > 0: node['bwlimit'] = bwlimits[0] # get interfaces iface_elems = node_elem.xpath('./default:interface | ./interface') ifaces = [ iface_elem.get_instance(Interface) for iface_elem in iface_elems ] node['interfaces'] = ifaces # get services node['services'] = PGv2Services.get_services(node_elem) # get slivers node['slivers'] = NITOSv1Sliver.get_slivers(node_elem) # get tags node['tags'] = NITOSv1PLTag.get_pl_tags(node_elem, ignore=NodeElement.fields + ["hardware_type"]) # get hardware types hardware_type_elems = node_elem.xpath( './default:hardware_type | ./hardware_type') node['hardware_types'] = [ hw_type.get_instance(HardwareType) for hw_type in hardware_type_elems ] # temporary... play nice with old slice manager rspec if not node['component_name']: hostname_elem = node_elem.find("hostname") if hostname_elem != None: node['component_name'] = hostname_elem.text nodes.append(node) return nodes
def get_node_objs(node_elems): nodes = [] for node_elem in node_elems: node = NodeElement(node_elem.attrib, node_elem) nodes.append(node) if 'component_id' in node_elem.attrib: node['authority_id'] = \ Xrn(node_elem.attrib['component_id']).get_authority_urn() # get hardware types hardware_type_elems = node_elem.xpath('./default:hardware_type | \ ./hardware_type') node['hardware_types'] = [hw_type.get_instance(HardwareType) \ for hw_type in hardware_type_elems] # get location location_elems = node_elem.xpath('./default:location | ./location') locations = [location_elem.get_instance(Location) \ for location_elem in location_elems] if len(locations) > 0: node['location'] = locations[0] # get interfaces iface_elems = node_elem.xpath('./default:interface | ./interface') node['interfaces'] = [iface_elem.get_instance(Interface) \ for iface_elem in iface_elems] # get position position_elems = node_elem.xpath('./default:position | ./position') if position_elems: position_elem = position_elems[0] node['position'] = position_elem.get_instance(IotlabPosition) # get services #node['services'] = PGv2Services.get_services(node_elem) # get slivers node['slivers'] = Iotlabv1Sliver.get_slivers(node_elem) available_elems = node_elem.xpath('./default:available | \ ./available') if len(available_elems) > 0 and 'name' in available_elems[0].attrib: if available_elems[0].attrib.get('now', '').lower() == 'true': node['boot_state'] = 'boot' else: node['boot_state'] = 'disabled' logger.debug("SLABV1NODE \tget_nodes_objs \ #nodes %s"%(nodes)) return nodes
def node_to_rspec_node(self, node, options={}): rspec_node = NodeElement() site=self.driver.testbedInfo rspec_node['component_id'] = hostname_to_urn(self.driver.hrn, site['name'], node['hostname']) rspec_node['component_name'] = node['hostname'] rspec_node['component_manager_id'] = Xrn(self.driver.hrn, 'authority+cm').get_urn() rspec_node['authority_id'] = hrn_to_urn(DummyXrn.site_hrn(self.driver.hrn, site['name']), 'authority+sa') #distinguish between Shared and Reservable nodes rspec_node['exclusive'] = 'false' rspec_node['hardware_types'] = [HardwareType({'name': 'dummy-pc'}), HardwareType({'name': 'pc'})] if site['longitude'] and site['latitude']: location = Location({'longitude': site['longitude'], 'latitude': site['latitude'], 'country': 'unknown'}) rspec_node['location'] = location return rspec_node
def node_to_rspec_node(self, node, options={}): rspec_node = NodeElement() site = self.driver.testbedInfo rspec_node['component_id'] = hostname_to_urn(self.driver.hrn, site['name'], node['hostname']) rspec_node['component_name'] = node['hostname'] rspec_node['ip'] = node['ip'] rspec_node['protocol'] = node['protocol'] rspec_node['port'] = node['port'] rspec_node['component_manager_id'] = Xrn(self.driver.hrn, 'authority+cm').get_urn() rspec_node['authority_id'] = hrn_to_urn( unigetestbedXrn.site_hrn(self.driver.hrn, site['name']), 'authority+sa') #distinguish between Shared and Reservable nodes rspec_node['exclusive'] = 'false' rspec_node['hardware_types'] = [ HardwareType({'name': 'endpoint'}), HardwareType({'name': 'sensor'}) ] resources = [] for resource in node['resources']: resources.append( Resource({ 'name': resource.get('name'), 'path': resource.get('path'), 'type': resource.get('type'), 'unit': resource.get('unit'), 'data_type': resource.get('datatype') })) rspec_node['resources'] = resources logger.info(rspec_node) if site['longitude'] and site['latitude']: location = Location({ 'longitude': site['longitude'], 'latitude': site['latitude'], 'country': 'unknown' }) rspec_node['location'] = location logger.info(rspec_node) return rspec_node
def node_to_rspec_node(self, node): """ Creates a rspec node structure with the appropriate information based on the node information that can be found in the node dictionary. :param node: node data. this dict contains information about the node and must have the following keys : mobile, radio, archi, hostname, boot_state, site, x, y ,z (position). :type node: dictionary. :returns: node dictionary containing the following keys : mobile, archi, radio, component_id, component_name, component_manager_id, authority_id, boot_state, exclusive, hardware_types, location, position, granularity, tags. :rtype: dict """ grain = self.driver.testbed_shell.GetLeaseGranularity() rspec_node = NodeElement() # xxx how to retrieve site['login_base'] #site_id=node['site_id'] #site=sites_dict[site_id] rspec_node['mobile'] = node['mobile'] rspec_node['archi'] = node['archi'] rspec_node['radio'] = node['radio'] cortexlab_xrn = xrn_object(self.driver.testbed_shell.root_auth, node['hostname']) rspec_node['component_id'] = cortexlab_xrn.urn rspec_node['component_name'] = node['hostname'] rspec_node['component_manager_id'] = \ hrn_to_urn(self.driver.testbed_shell.root_auth, 'authority+sa') # Iotlab's nodes are federated : there is only one authority # for all Iotlab sites, registered in SFA. # Removing the part including the site # in authority_id SA 27/07/12 rspec_node['authority_id'] = rspec_node['component_manager_id'] # do not include boot state (<available> element) #in the manifest rspec rspec_node['boot_state'] = node['boot_state'] # if node['hostname'] in reserved_nodes: # rspec_node['boot_state'] = "Reserved" rspec_node['exclusive'] = 'true' rspec_node['hardware_types'] = [HardwareType({'name': \ 'iotlab-node'})] location = IotlabLocation({'country':'France', 'site': \ node['site']}) rspec_node['location'] = location position = IotlabPosition() for field in position: try: position[field] = node[field] except KeyError, error: logger.log_exc("Cortexlabaggregate\t node_to_rspec_node \ position %s " % (error))
def get_nodes(self, slice_xrn, slice=None, slivers={}, options={}): # if we are dealing with a slice that has no node just return # and empty list if slice_xrn: if not slice or not slivers: return [] else: nodes = [slivers[sliver] for sliver in slivers] else: nodes = self.driver.shell.getNodes({}, []) # get the granularity in second for the reservation system grain = self.driver.testbedInfo['grain'] #grain = 1800 rspec_nodes = [] for node in nodes: rspec_node = NodeElement() site_name = self.driver.testbedInfo['name'] rspec_node['component_id'] = hostname_to_urn( self.driver.hrn, site_name, node['hostname']) rspec_node['component_name'] = node['hostname'] rspec_node['component_manager_id'] = Xrn(self.driver.hrn, 'authority+cm').get_urn() rspec_node['authority_id'] = hrn_to_urn( NitosXrn.site_hrn(self.driver.hrn, site_name), 'authority+sa') # do not include boot state (<available> element) in the manifest rspec #if not slice: # rspec_node['boot_state'] = node['boot_state'] rspec_node['exclusive'] = 'true' # site location longitude = self.driver.testbedInfo['longitude'] latitude = self.driver.testbedInfo['latitude'] if longitude and latitude: location = Location({ 'longitude': longitude, 'latitude': latitude, 'country': 'unknown' }) rspec_node['location'] = location # 3D position position_3d = Position3D({ 'x': node['position']['X'], 'y': node['position']['Y'], 'z': node['position']['Z'] }) #position_3d = Position3D({'x': 1, 'y': 2, 'z': 3}) rspec_node['position_3d'] = position_3d # Granularity granularity = Granularity({'grain': grain}) rspec_node['granularity'] = granularity # HardwareType rspec_node['hardware_type'] = node['node_type'] #rspec_node['hardware_type'] = "orbit" #slivers if node['node_id'] in slivers: # add sliver info sliver = slivers[node['node_id']] rspec_node['sliver_id'] = sliver['node_id'] rspec_node['client_id'] = node['hostname'] rspec_node['slivers'] = [sliver] rspec_nodes.append(rspec_node) return rspec_nodes
def node_to_rspec_node(self, node, sites, interfaces, node_tags, pl_initscripts=[], grain=None, options={}): rspec_node = NodeElement() # xxx how to retrieve site['login_base'] site = sites[node['site_id']] rspec_node['component_id'] = hostname_to_urn(self.driver.hrn, site['login_base'], node['hostname']) rspec_node['component_name'] = node['hostname'] rspec_node['component_manager_id'] = Xrn(self.driver.hrn, 'authority+cm').get_urn() rspec_node['authority_id'] = hrn_to_urn( PlXrn.site_hrn(self.driver.hrn, site['login_base']), 'authority+sa') # do not include boot state (<available> element) in the manifest rspec rspec_node['boot_state'] = node['boot_state'] if node['boot_state'] == 'boot': rspec_node['available'] = 'true' else: rspec_node['available'] = 'false' #distinguish between Shared and Reservable nodes if node['node_type'] == 'reservable': rspec_node['exclusive'] = 'true' else: rspec_node['exclusive'] = 'false' rspec_node['hardware_types'] = [ HardwareType({'name': 'plab-pc'}), HardwareType({'name': 'pc'}) ] # only doing this because protogeni rspec needs # to advertise available initscripts rspec_node['pl_initscripts'] = pl_initscripts.values() # add site/interface info to nodes. # assumes that sites, interfaces and tags have already been prepared. if site['longitude'] and site['latitude']: location = Location({ 'longitude': site['longitude'], 'latitude': site['latitude'], 'country': 'unknown' }) rspec_node['location'] = location # Granularity granularity = Granularity({'grain': grain}) rspec_node['granularity'] = granularity rspec_node['interfaces'] = [] if_count = 0 for if_id in node['interface_ids']: interface = Interface(interfaces[if_id]) interface['ipv4'] = interface['ip'] interface['component_id'] = PlXrn( auth=self.driver.hrn, interface='node%s:eth%s' % (node['node_id'], if_count)).get_urn() # interfaces in the manifest need a client id if slice: interface['client_id'] = "%s:%s" % (node['node_id'], if_id) rspec_node['interfaces'].append(interface) if_count += 1 tags = [ PLTag(node_tags[tag_id]) for tag_id in node['node_tag_ids'] if tag_id in node_tags ] rspec_node['tags'] = tags return rspec_node
def get_node_objs(node_elems): nodes = [] for node_elem in node_elems: node = NodeElement(node_elem.attrib, node_elem) nodes.append(node) if 'component_id' in node_elem.attrib: node['authority_id'] = Xrn( node_elem.attrib['component_id']).get_authority_urn() # get hardware types hardware_type_elems = node_elem.xpath( './default:hardware_type | ./hardware_type') node['hardware_types'] = [ dict(hw_type.get_instance(HardwareType)) for hw_type in hardware_type_elems ] # get location location_elems = node_elem.xpath('./default:location | ./location') locations = [ dict(location_elem.get_instance(Location)) for location_elem in location_elems ] if len(locations) > 0: node['location'] = locations[0] # get granularity granularity_elems = node_elem.xpath( './default:granularity | ./granularity') if len(granularity_elems) > 0: node['granularity'] = granularity_elems[0].get_instance( Granularity) # get interfaces iface_elems = node_elem.xpath('./default:interface | ./interface') node['interfaces'] = [ dict(iface_elem.get_instance(Interface)) for iface_elem in iface_elems ] # get services node['services'] = PGv2Services.get_services(node_elem) # get slivers node['slivers'] = Clabv1Sliver.get_slivers(node_elem) # get boot state available_elems = node_elem.xpath( './default:available | ./available') if len(available_elems) > 0 and 'now' in available_elems[0].attrib: if available_elems[0].attrib.get('now', '').lower() == 'true': node['boot_state'] = 'boot' else: node['boot_state'] = 'disabled' # EXTENSION FOR CLab v1 RSpec # get group try: group_elems = node_elem.xpath('./clab:group | ./group') if len(group_elems) > 0: group_elem = group_elems[0] group = dict(group_elem.get_instance(Clabv1Group)) node['group'] = group except XPathEvalError: # there is no group element in the xml pass # get island try: island_elems = node_elem.xpath('./clab:island | ./island') if len(island_elems) > 0: island_elem = island_elems[0] island = dict(island_elem.get_instance(Clabv1Island)) node['island'] = island except XPathEvalError: # there is no island element in the xml pass return nodes
def get_node_objs(node_elems): nodes = [] for node_elem in node_elems: node = NodeElement(node_elem.attrib, node_elem) nodes.append(node) if 'component_id' in node_elem.attrib: node['authority_id'] = Xrn( node_elem.attrib['component_id']).get_authority_urn() # get hardware types hardware_type_elems = node_elem.xpath( './default:hardware_type | ./hardware_type') node['hardware_types'] = [ dict(hw_type.get_instance(HardwareType)) for hw_type in hardware_type_elems ] # get location location_elems = node_elem.xpath('./default:location | ./location') locations = [ dict(location_elem.get_instance(Location)) for location_elem in location_elems ] if len(locations) > 0: node['location'] = locations[0] # get granularity granularity_elems = node_elem.xpath( './default:granularity | ./granularity') if len(granularity_elems) > 0: node['granularity'] = granularity_elems[0].get_instance( Granularity) # get interfaces iface_elems = node_elem.xpath('./default:interface | ./interface') node['interfaces'] = [ dict(iface_elem.get_instance(Interface)) for iface_elem in iface_elems ] # get services node['services'] = PGv2Services.get_services(node_elem) # get slivers node['slivers'] = PGv2SliverType.get_slivers(node_elem) # get boot state available_elems = node_elem.xpath( './default:available | ./available') if len(available_elems) > 0 and 'now' in available_elems[0].attrib: if available_elems[0].attrib.get('now', '').lower() == 'true': node['boot_state'] = 'boot' else: node['boot_state'] = 'disabled' # get initscripts try: node['pl_initscripts'] = [] initscript_elems = node_elem.xpath( './default:sliver_type/planetlab:initscript | ./sliver_type/initscript' ) if len(initscript_elems) > 0: for initscript_elem in initscript_elems: if 'name' in initscript_elem.attrib: node['pl_initscripts'].append( dict(initscript_elem.attrib)) except: pass # get node tags try: tag_elems = node_elem.xpath( './planetlab:attribute | ./attribute') node['tags'] = [] if len(tag_elems) > 0: for tag_elem in tag_elems: tag = dict(tag_elem.get_instance(Attribute)) tag['tagname'] = tag.pop('name') node['tags'].append(tag) except: pass return nodes