Ejemplo n.º 1
0
    def add_slivers(self, hostnames, attributes=None, sliver_urn=None, append=False):
        if attributes is None: attributes=[]
        # all nodes hould already be present in the rspec. Remove all
        # nodes that done have slivers
        print>>sys.stderr, "\r\n \r\n \r\n \t\t\t Iotlabv1.PY add_slivers  ----->get_node "
        for hostname in hostnames:
            node_elems = self.get_nodes({'component_id': '*%s*' % hostname})
            if not node_elems:
                continue
            node_elem = node_elems[0]

            # determine sliver types for this node
            #TODO : add_slivers valid type of sliver needs to be changed 13/07/12 SA
            valid_sliver_types = ['iotlab-node', 'emulab-openvz', 'raw-pc', 'plab-vserver', 'plab-vnode']
            #valid_sliver_types = ['emulab-openvz', 'raw-pc', 'plab-vserver', 'plab-vnode']
            requested_sliver_type = None
            for sliver_type in node_elem.get('slivers', []):
                if sliver_type.get('type') in valid_sliver_types:
                    requested_sliver_type = sliver_type['type']

            if not requested_sliver_type:
                continue
            sliver = {'type': requested_sliver_type,
                     'pl_tags': attributes}
            print>>sys.stderr, "\r\n \r\n \r\n \t\t\t Iotlabv1.PY add_slivers  node_elem %s sliver_type %s \r\n \r\n " %(node_elem, sliver_type)
            # remove available element
            for available_elem in node_elem.xpath('./default:available | ./available'):
                node_elem.remove(available_elem)

            # remove interface elements
            for interface_elem in node_elem.xpath('./default:interface | ./interface'):
                node_elem.remove(interface_elem)

            # remove existing sliver_type elements
            for sliver_type in node_elem.get('slivers', []):
                node_elem.element.remove(sliver_type.element)

            # set the client id
            node_elem.element.set('client_id', hostname)
            if sliver_urn:
                pass
                # TODO
                # set the sliver id
                #slice_id = sliver_info.get('slice_id', -1)
                #node_id = sliver_info.get('node_id', -1)
                #sliver_id = urn_to_sliver_id(sliver_urn, slice_id, node_id)
                #node_elem.set('sliver_id', sliver_id)

            # add the sliver type elemnt
            Iotlabv1Sliver.add_slivers(node_elem.element, sliver)
            #Iotlabv1SliverType.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['client_id']:
                    parent = node_elem.element.getparent()
                    parent.remove(node_elem.element)
Ejemplo n.º 2
0
 def add_slivers(xml, slivers):
     logger.debug("Iotlabv1NODE \tadd_slivers ")
     component_ids = []
     for sliver in slivers:
         filter_sliver = {}
         if isinstance(sliver, str):
             filter_sliver['component_id'] = '*%s*' % sliver
             sliver = {}
         elif 'component_id' in sliver and sliver['component_id']:
             filter_sliver['component_id'] = '*%s*' % sliver['component_id']
         if not filter_sliver:
             continue
         nodes = Iotlabv1Node.get_nodes(xml, filter_sliver)
         if not nodes:
             continue
         node = nodes[0]
         Iotlabv1Sliver.add_slivers(node, sliver)
Ejemplo n.º 3
0
 def remove_slivers(xml, hostnames):
     for hostname in hostnames:
         nodes = Iotlabv1Node.get_nodes(xml, \
                                 {'component_id': '*%s*' % hostname})
         for node in nodes:
             slivers = Iotlabv1Sliver.get_slivers(node.element)
             for sliver in slivers:
                 node.element.remove(sliver.element)
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    def add_nodes(xml, nodes,rspec_content_type=None):
        """Adds the nodes to the xml.

        Adds the nodes as well as dedicated iotlab fields to the node xml
        element.

        :param xml: the xml being constructed.
        :type xml: xml
        :param nodes: list of node dict
        :type nodes: list
        :returns: a list of node elements.
        :rtype: list

        """
        #Add network item in the xml
        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 = []
        #Then add nodes items to the network item in the xml
        for node in nodes:
            #Attach this node to the network element
            node_fields = ['component_manager_id', 'component_id', 'exclusive',
                           'boot_state', 'mobile']
            node_elem = network_elem.add_instance('node', node, node_fields)
            node_elems.append(node_elem)

            #Set the attibutes of this node element
            for attribute in node:
            # set component name
                if attribute is 'component_name':
                    component_name = node['component_name']
                    node_elem.set('component_name', component_name)

            # set hardware types, extend fields to add Iotlab's architecture
            #and radio type

                if attribute is 'hardware_types':
                    for hardware_type in node.get('hardware_types', []):
                        fields = HardwareType.fields
                        fields.extend(['archi', 'radio'])
                        node_elem.add_instance('hardware_types', node, fields)

            # set mobility
                if attribute is 'mobility':
                    node_elem.add_instance('mobility', node['mobility'],
                                           IotlabMobility.fields)
            # set location
                if attribute is 'location':
                    node_elem.add_instance('location', node['location'],
                                            IotlabLocation.fields)

             # add granularity of the reservation system
             #TODO put the granularity in network instead SA 18/07/12
                if attribute is 'granularity':
                    granularity = node['granularity']
                    if granularity:
                        node_elem.add_instance('granularity',
                                               granularity, granularity.fields)

            # set available element
                if attribute is 'boot_state':
                    if node.get('boot_state').lower() == 'alive':
                        available_elem = node_elem.add_element('available',
                                                               now='true')
                    else:
                        available_elem = node_elem.add_element('available',
                                                               now='false')

            #set position
                if attribute is 'position':
                    node_elem.add_instance('position', node['position'],
                                           IotlabPosition.fields)
            ## add services
            #PGv2Services.add_services(node_elem, node.get('services', []))
            # add slivers
                if attribute is 'slivers':
                    slivers = node.get('slivers', [])
                    if not slivers:
                    # we must still advertise the available sliver types
                        slivers = Sliver({'type': 'iotlab-node'})
                    # 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']})

                    Iotlabv1Sliver.add_slivers(node_elem, slivers)
                # add sliver tag in Request Rspec
            if rspec_content_type == "request":
                node_elem.add_instance('sliver', '', [])
        return node_elems