def add_slivers(self, hostnames, attributes=[], sliver_urn=None, append=False): # add slice name to network tag network_tags = self.xml.xpath('//network') if network_tags: network_tag = network_tags[0] network_tag.set('slice', urn_to_hrn(sliver_urn)[0]) # add slivers sliver = {'name': sliver_urn, 'pl_tags': attributes} for hostname in hostnames: if sliver_urn: sliver['name'] = sliver_urn node_elems = self.get_nodes({'component_id': '*%s*' % hostname}) if not node_elems: continue node_elem = node_elems[0] NITOSv1Sliver.add_slivers(node_elem.element, sliver) # remove all nodes without slivers if not append: for node_elem in self.get_nodes(): if not node_elem['slivers']: parent = node_elem.element.getparent() parent.remove(node_elem.element)
def add_slivers(self, hostnames, attributes=[], sliver_urn=None, append=False): # add slice name to network tag network_tags = self.xml.xpath('//network') if network_tags: network_tag = network_tags[0] network_tag.set('slice', urn_to_hrn(sliver_urn)[0]) # add slivers sliver = {'name':sliver_urn, 'pl_tags': attributes} for hostname in hostnames: if sliver_urn: sliver['name'] = sliver_urn node_elems = self.get_nodes({'component_id': '*%s*' % hostname}) if not node_elems: continue node_elem = node_elems[0] NITOSv1Sliver.add_slivers(node_elem.element, sliver) # remove all nodes without slivers if not append: for node_elem in self.get_nodes(): if not node_elem['slivers']: parent = node_elem.element.getparent() parent.remove(node_elem.element)
def get_sliver_attributes(self, component_id, network=None): nodes = self.get_nodes({'component_id': '*%s*' % component_id}) attribs = [] if nodes is not None and isinstance(nodes, list) and len(nodes) > 0: node = nodes[0] slivers = NITOSv1Sliver.get_slivers(node.element) if slivers is not None and isinstance(slivers, list) and len(slivers) > 0: sliver = slivers[0] attribs = NITOSv1Sliver.get_sliver_attributes(sliver.element) return attribs
def add_sliver_attribute(self, component_id, name, value, network=None): nodes = self.get_nodes({'component_id': '*%s*' % component_id}) if nodes is not None and isinstance(nodes, list) and len(nodes) > 0: node = nodes[0] slivers = NITOSv1Sliver.get_slivers(node) if slivers: sliver = slivers[0] NITOSv1Sliver.add_sliver_attribute(sliver, name, value) else: # should this be an assert / raise an exception? logger.error("WARNING: failed to find component_id %s" % component_id)
def add_slivers(xml, slivers): component_ids = [] for sliver in slivers: filter = {} if isinstance(sliver, str): filter['component_id'] = '*%s*' % sliver sliver = {} elif 'component_id' in sliver and sliver['component_id']: filter['component_id'] = '*%s*' % sliver['component_id'] if not filter: continue nodes = NITOSv1Node.get_nodes(xml, filter) if not nodes: continue node = nodes[0] NITOSv1Sliver.add_slivers(node, sliver)
def get_default_sliver_attributes(self, network=None): if network: defaults = self.xml.xpath("//network[@name='%s']/sliver_defaults" % network) else: defaults = self.xml.xpath("//sliver_defaults") if not defaults: return [] return NITOSv1Sliver.get_sliver_attributes(defaults[0])
def remove_slivers(xml, hostnames): for hostname in hostnames: nodes = NITOSv1Node.get_nodes(xml, {'component_id': '*%s*' % hostname}) for node in nodes: slivers = NITOSv1Sliver.get_slivers(node.element) for sliver in slivers: node.element.remove(sliver.element)
def add_default_sliver_attribute(self, name, value, network=None): if network: defaults = self.xml.xpath("//network[@name='%s']/sliver_defaults" % network) else: defaults = self.xml.xpath("//sliver_defaults") if not defaults: if network: network_tag = self.xml.xpath("//network[@name='%s']" % network) else: network_tag = self.xml.xpath("//network") if isinstance(network_tag, list): network_tag = network_tag[0] defaults = network_tag.add_element('sliver_defaults') elif isinstance(defaults, list): defaults = defaults[0] NITOSv1Sliver.add_sliver_attribute(defaults, name, value)
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'] = NITOSv1Sliver.get_slivers(node_elem) # get tags node['tags'] = NITOSv1PLTag.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_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'] = NITOSv1Sliver.get_slivers(node_elem) # get tags node['tags'] = NITOSv1PLTag.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 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', []))
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', []))