def add_nodes(xml, nodes, rspec_content_type=None): node_elems = [] for node in nodes: node_fields = ['component_manager_id', 'component_id', 'client_id', 'sliver_id', 'exclusive'] node_elem = xml.add_instance('node', node, node_fields) node_elems.append(node_elem) # set component name if node.get('component_id'): component_name = Xrn.unescape(get_leaf(Xrn(node['component_id']).get_hrn())) node_elem.set('component_name', component_name) # set hardware types if node.get('hardware_types'): for hardware_type in node.get('hardware_types', []): node_elem.add_instance('hardware_type', hardware_type, HardwareType.fields) # set location if node.get('location'): node_elem.add_instance('location', node['location'], Location.fields) # set granularity if node.get('exclusive') == "true": granularity = node.get('granularity') node_elem.add_instance('granularity', granularity, granularity.fields) # set interfaces PGv2Interface.add_interfaces(node_elem, node.get('interfaces')) #if node.get('interfaces'): # for interface in node.get('interfaces', []): # node_elem.add_instance('interface', interface, ['component_id', 'client_id']) # set available element if node.get('available'): available_elem = node_elem.add_element('available', now=node['available']) # add services PGv2Services.add_services(node_elem, node.get('services', [])) # add slivers slivers = node.get('slivers', []) if not slivers: # we must still advertise the available sliver types if node.get('sliver_type'): slivers = Sliver({'type': node['sliver_type']}) else: # Planet lab slivers = Sliver({'type': 'plab-vserver'}) # we must also advertise the available initscripts slivers['tags'] = [] if node.get('pl_initscripts'): for initscript in node.get('pl_initscripts', []): slivers['tags'].append({'name': 'initscript', 'value': initscript['name']}) PGv2SliverType.add_slivers(node_elem, slivers) # advertise the node tags tags = node.get('tags', []) if tags: for tag in tags: tag['name'] = tag.pop('tagname') node_elem.add_instance('{%s}attribute' % xml.namespaces['planetlab'], tag, ['name', 'value']) # add sliver tag in Request Rspec #if rspec_content_type == "request": # node_elem.add_instance('sliver', '', []) return node_elems
def get_node_objs(node_elems): nodes = [] for node_elem in node_elems: node = Node(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 services node["services"] = PGv2Services.get_services(node_elem) # get slivers node["slivers"] = PGv2SliverType.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" return nodes
def add_services(self, services): # Receives a list of dicts that implement the different services # It will be used with the 'Login' service # Example of services argument: # services = [ { 'login':{'authentication':'ssh-keys', 'hostname':'ipv6_of_sliver', # 'port':'22', 'username':'******'} } ] # return PGv2Services.add_services(self.xml, services)
def add_nodes(xml, nodes): node_elems = [] for node in nodes: node_fields = ["component_manager_id", "component_id", "client_id", "sliver_id", "exclusive"] node_elem = xml.add_instance("node", node, node_fields) node_elems.append(node_elem) # set component name if node.get("component_id"): component_name = xrn_to_hostname(node["component_id"]) node_elem.set("component_name", component_name) # set hardware types if node.get("hardware_types"): for hardware_type in node.get("hardware_types", []): node_elem.add_instance("hardware_type", hardware_type, HardwareType.fields) # set location if node.get("location"): node_elem.add_instance("location", node["location"], Location.fields) # set interfaces PGv2Interface.add_interfaces(node_elem, node.get("interfaces")) # if node.get('interfaces'): # for interface in node.get('interfaces', []): # node_elem.add_instance('interface', interface, ['component_id', 'client_id']) # set available element if node.get("boot_state"): if node.get("boot_state").lower() == "boot": available_elem = node_elem.add_element("available", now="true") else: available_elem = node_elem.add_element("available", now="false") # add services PGv2Services.add_services(node_elem, node.get("services", [])) # add slivers slivers = node.get("slivers", []) if not slivers: # we must still advertise the available sliver types slivers = Sliver({"type": "plab-vserver"}) # we must also advertise the available initscripts slivers["tags"] = [] if node.get("pl_initscripts"): for initscript in node.get("pl_initscripts", []): slivers["tags"].append({"name": "initscript", "value": initscript["name"]}) PGv2SliverType.add_slivers(node_elem, slivers) return node_elems
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) 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 = Node(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"] = SFAv1Sliver.get_slivers(node_elem) # get tags node["tags"] = SFAv1PLTag.get_pl_tags(node_elem, ignore=Node.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_services(self): # Method to get the services when returning the RSpec, for exmaple in xml format return PGv2Services.get_services(self.xml)
def add_nodes(xml, nodes, rspec_content_type=None): 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', [])) # add sliver tag in Request Rspec if rspec_content_type == "request": node_elem.add_instance('sliver', '', [])
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
def add_nodes(xml, nodes, rspec_content_type=None): node_elems = [] for node in nodes: node_fields = [ 'component_manager_id', 'component_id', 'client_id', 'sliver_id', 'exclusive' ] node_elem = xml.add_instance('node', node, node_fields) node_elems.append(node_elem) # set component name if node.get('component_id'): component_name = Xrn.unescape( get_leaf(Xrn(node['component_id']).get_hrn())) node_elem.set('component_name', component_name) # set hardware types if node.get('hardware_types'): for hardware_type in node.get('hardware_types', []): node_elem.add_instance('hardware_type', hardware_type, HardwareType.fields) # set location if node.get('location'): node_elem.add_instance('location', node['location'], Location.fields) # set granularity if node.get('exclusive') == "true": granularity = node.get('granularity') node_elem.add_instance('granularity', granularity, granularity.fields) # set interfaces PGv2Interface.add_interfaces(node_elem, node.get('interfaces')) #if node.get('interfaces'): # for interface in node.get('interfaces', []): # node_elem.add_instance('interface', interface, ['component_id', 'client_id']) # set available element if node.get('available'): available_elem = node_elem.add_element('available', now=node['available']) # add services PGv2Services.add_services(node_elem, node.get('services', [])) # add slivers slivers = node.get('slivers', []) if not slivers: # we must still advertise the available sliver types if node.get('sliver_type'): slivers = Sliver({'type': node['sliver_type']}) else: # Planet lab slivers = Sliver({'type': 'plab-vserver'}) # we must also advertise the available initscripts slivers['tags'] = [] if node.get('pl_initscripts'): for initscript in node.get('pl_initscripts', []): slivers['tags'].append({ 'name': 'initscript', 'value': initscript['name'] }) PGv2SliverType.add_slivers(node_elem, slivers) # advertise the node tags tags = node.get('tags', []) if tags: for tag in tags: tag['name'] = tag.pop('tagname') node_elem.add_instance( '{%s}attribute' % xml.namespaces['planetlab'], tag, ['name', 'value']) # add sliver tag in Request Rspec #if rspec_content_type == "request": # node_elem.add_instance('sliver', '', []) return node_elems
def add_nodes(xml, nodes, rspec_content_type=None): 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', [])) # add sliver tag in Request Rspec if rspec_content_type == "request": node_elem.add_instance('sliver', '', [])
def add_nodes(xml, nodes, rspec_content_type=None): node_elems = [] for node in nodes: node_fields = [ 'component_manager_id', 'component_id', 'client_id', 'sliver_id', 'exclusive' ] node_elem = xml.add_instance('node', node, node_fields) node_elems.append(node_elem) # set component name if node.get('component_id'): component_name = Xrn.unescape( get_leaf(Xrn(node['component_id']).get_hrn())) node_elem.set('component_name', component_name) # set hardware types if node.get('hardware_types'): for hardware_type in node.get('hardware_types', []): node_elem.add_instance('hardware_type', hardware_type, HardwareType.fields) # set location if node.get('location'): node_elem.add_instance('location', node['location'], Location.fields) # set granularity if node.get('exclusive') == "true": granularity = node.get('granularity') node_elem.add_instance('granularity', granularity, granularity.fields) # set interfaces Clabv1Interface.add_interfaces(node_elem, node.get('nodeInterfaces')) # set available element if node.get('available'): available_elem = node_elem.add_element('available', now=node['available']) # add services PGv2Services.add_services(node_elem, node.get('services', [])) # add slivers slivers = node.get('slivers', []) if not slivers: # we must still advertise the available sliver types if node.get('sliver_type'): sliver_elem = node_elem.add_element('sliver_type') sliver_elem.set('name', node['sliver_type']) else: # Add the slivers of the node Clabv1Sliver.add_slivers(node_elem, slivers) # EXTENSION for C-Lab v1 RSpec Nodes # Add group group = node.get('group') if group: group_elem = node_elem.add_element('{%s}group' % xml.namespaces['clab'], name=group['name'], id=group['id']) island = node.get('island') if island: island_elem = node_elem.add_element('{%s}island' % xml.namespaces['clab'], name=island['name'], id=island['id']) # Add Node Network Interfaces #node_ifaces = node.get('nodeInterfaces') #if node_ifaces: # node_ifaces_elem = node_elem.add_element('node_interfaces') # for node_iface in node_ifaces: # node_ifaces_elem.add_element('node_interface', name=node_iface['name'], type=node_iface['type']) # Add Management Network Information mgmt_net = node.get('mgmt_net') if mgmt_net: mgmt_net_elem = node_elem.add_element( '{%s}management_network' % xml.namespaces['clab'], addr=mgmt_net['addr']) return node_elems
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 add_nodes(xml, nodes, rspec_content_type=None): 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 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.unescape(get_leaf(Xrn(node['component_id']).get_hrn())) 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 exclusive tag to distinguish between Reservable and Shared nodes exclusive_elem = node_elem.add_element('exclusive') if node.get('exclusive') and node.get('exclusive') == 'true': exclusive_elem.set_text('TRUE') # add granularity of the reservation system granularity = node.get('granularity') if granularity: node_elem.add_instance('granularity', granularity, granularity.fields) else: exclusive_elem.set_text('FALSE') 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: # backdoor for FITeagle # Alexander Willner <*****@*****.**> if tag['tagname']=="fiteagle_settings": tag_elem = node_elem.add_element(tag['tagname']) for subtag in tag['value']: subtag_elem = tag_elem.add_element('setting') subtag_elem.set('name', str(subtag['tagname'])) subtag_elem.set('description', str(subtag['description'])) subtag_elem.set_text(subtag['value']) else: tag_elem = node_elem.add_element(tag['tagname']) tag_elem.set_text(tag['value']) SFAv1Sliver.add_slivers(node_elem, node.get('slivers', [])) # add sliver tag in Request Rspec if rspec_content_type == "request": node_elem.add_instance('sliver', '', [])
def add_nodes(xml, nodes, rspec_content_type=None): 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 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.unescape(get_leaf(Xrn(node['component_id']).get_hrn())) 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 exclusive tag to distinguish between Reservable and Shared nodes exclusive_elem = node_elem.add_element('exclusive') if node.get('exclusive') and node.get('exclusive') == 'true': exclusive_elem.set_text('TRUE') # add granularity of the reservation system granularity = node.get('granularity') if granularity: node_elem.add_instance('granularity', granularity, granularity.fields) else: exclusive_elem.set_text('FALSE') 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: # backdoor for FITeagle # Alexander Willner <*****@*****.**> if tag['tagname']=="fiteagle_settings": tag_elem = node_elem.add_element(tag['tagname']) for subtag in tag['value']: subtag_elem = tag_elem.add_element('setting') subtag_elem.set('name', str(subtag['tagname'])) subtag_elem.set('description', str(subtag['description'])) subtag_elem.set_text(subtag['value']) else: tag_elem = node_elem.add_element(tag['tagname']) tag_elem.set_text(tag['value']) SFAv1Sliver.add_slivers(node_elem, node.get('slivers', [])) # add sliver tag in Request Rspec if rspec_content_type == "request": node_elem.add_instance('sliver', '', [])
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 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_to_hostname(node["component_id"]) 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 exclusive tag to distinguish between Reservable and Shared nodes exclusive_elem = node_elem.add_element("exclusive") if node.get("exclusive") and node.get("exclusive") == "true": exclusive_elem.set_text("TRUE") # add granularity of the reservation system granularity = node.get("granularity") if granularity: node_elem.add_instance("granularity", granularity, granularity.fields) else: exclusive_elem.set_text("FALSE") 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: # backdoor for FITeagle # Alexander Willner <*****@*****.**> if tag["tagname"] == "fiteagle_settings": tag_elem = node_elem.add_element(tag["tagname"]) for subtag in tag["value"]: subtag_elem = tag_elem.add_element("setting") subtag_elem.set("name", str(subtag["tagname"])) subtag_elem.set("description", str(subtag["description"])) subtag_elem.set_text(subtag["value"]) else: tag_elem = node_elem.add_element(tag["tagname"]) tag_elem.set_text(tag["value"]) SFAv1Sliver.add_slivers(node_elem, node.get("slivers", []))
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