Ejemplo n.º 1
0
    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]
            SFAv1Sliver.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)
Ejemplo n.º 2
0
 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 = SFAv1Node.get_nodes(xml, filter)
         if not nodes:
             continue
         node = nodes[0]
         SFAv1Sliver.add_slivers(node, sliver)
Ejemplo n.º 3
0
    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:
                    tag_elem = node_elem.add_element(tag['tagname'])
                    tag_elem.set_text(tag['value'])
            SFAv1Sliver.add_slivers(node_elem, node.get('slivers', []))