Пример #1
0
    def describe(self, urns, version=None, options={}):
        # update nova connection
        tenant_name = OSXrn(xrn=urns[0], type='slice').get_tenant_name()
        self.driver.shell.nova_manager.connect(tenant=tenant_name)
        instances = self.get_instances(urns)
        # lookup the sliver allocations
        sliver_ids = [sliver['sliver_id'] for sliver in slivers]
        constraint = SliverAllocation.sliver_id.in_(sliver_ids)
        sliver_allocations = self.driver.api.dbsession().query(SliverAllocation).filter(constraint)
        sliver_allocation_dict = {}
        for sliver_allocation in sliver_allocations:
            sliver_allocation_dict[sliver_allocation.sliver_id] = sliver_allocation

        geni_slivers = []
        rspec_nodes = []
        for instance in instances:
            rspec_nodes.append(self.instance_to_rspec_node(instance))
            geni_sliver = self.instance_to_geni_sliver(instance, sliver_sllocation_dict)
            geni_slivers.append(geni_sliver)
        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(version.type, version.version, 'manifest')
        rspec = RSpec(version=rspec_version, user_options=options)
        rspec.xml.set('expires',  datetime_to_string(utcparse(time.time())))
        rspec.version.add_nodes(rspec_nodes)
        result = {'geni_urn': Xrn(urns[0]).get_urn(),
                  'geni_rspec': rspec.toxml(), 
                  'geni_slivers': geni_slivers}
        
        return result
Пример #2
0
    def merge(self, in_rspec):
        """
        Merge contents for specified rspec with current rspec
        """

        if not in_rspec:
            return

        from sfa.rspecs.rspec import RSpec
        if isinstance(in_rspec, RSpec):
            rspec = in_rspec
        else:
            rspec = RSpec(in_rspec)
        if rspec.version.type.lower() == 'protogeni':
            from sfa.rspecs.rspec_converter import RSpecConverter
            in_rspec = RSpecConverter.to_sfa_rspec(rspec.toxml())
            rspec = RSpec(in_rspec)

        # just copy over all networks
        current_networks = self.get_networks()
        networks = rspec.version.get_networks()
        for network in networks:
            current_network = network.get('name')
            if current_network and current_network not in current_networks:
                self.xml.append(network.element)
                current_networks.append(current_network)
Пример #3
0
    def create_sliver (self, slice_urn, slice_hrn, creds, rspec_string, users, options):
   
        aggregate = OSAggregate(self)

        # assume first user is the caller and use their context
        # for the ec2/euca api connection. Also, use the first users
        # key as the project key.
        key_name = None
        if len(users) > 1:
            key_name = aggregate.create_instance_key(slice_hrn, users[0])

        # collect public keys
        pubkeys = []
        for user in users:
            pubkeys.extend(user['keys'])
           
        rspec = RSpec(rspec_string)
        instance_name = hrn_to_os_slicename(slice_hrn)
        tenant_name = OSXrn(xrn=slice_hrn, type='slice').get_tenant_name()
        instances = aggregate.run_instances(instance_name, tenant_name, rspec_string, key_name, pubkeys)
        rspec_nodes = []
        for instance in instances:
            rspec_nodes.append(aggregate.instance_to_rspec_node(slice_urn, instance))    
        version_manager = VersionManager()
        manifest_version = version_manager._get_version(rspec.version.type, rspec.version.version, 'manifest')
        manifest_rspec = RSpec(version=manifest_version, user_options=options)
        manifest_rspec.version.add_nodes(rspec_nodes) 
         
        return manifest_rspec.toxml()
Пример #4
0
    def describe(self, urns, version=None, options=None):
        if options is None: options={}
        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(version.type, version.version, 'manifest')
        rspec = RSpec(version=rspec_version, user_options=options)

        # Update connection for the current user
        xrn = Xrn(urns[0], type='slice')
        user_name = xrn.get_authority_hrn() + '.' + xrn.leaf.split('-')[0]
        tenant_name = OSXrn(xrn=urns[0], type='slice').get_hrn()
        self.driver.shell.compute_manager.connect(username=user_name, tenant=tenant_name, password=user_name)

        # For delay to collect instance info 
        time.sleep(3)
        # Get instances from the Openstack
        instances = self.get_instances(xrn)

        # Add sliver(s) from instance(s)
        geni_slivers = []
        rspec.xml.set( 'expires',  datetime_to_string(utcparse(time.time())) )
        rspec_nodes = []
        for instance in instances:
            rspec_nodes.append(self.instance_to_rspec_node(instance))
            geni_sliver = self.instance_to_geni_sliver(instance)
            geni_slivers.append(geni_sliver)
        rspec.version.add_nodes(rspec_nodes)

        result = { 'geni_urn': xrn.get_urn(),
                   'geni_rspec': rspec.toxml(), 
                   'geni_slivers': geni_slivers }
        return result
Пример #5
0
    def list_resources(self, parent, typename):
        assert(typename == "SFAPNode" or not typename)
        assert(parent == None)
        list_resources = self.__sfi.bootstrap.server_proxy(self.__sfi.sm_url).ListResources(self.__credentials,self.__options)
        self.__sfi.bootstrap.server_proxy(self.__sfi.sm_url)
        logger.debug( "ListResources at %s returned : %s"%(self.__sfi.sm_url,list_resources['value']))
        rspec = RSpec(list_resources['value'])
        nodes = rspec.version.get_nodes()
        networks = rspec.version.get_networks()
        for node in nodes:
            version = {'namespace': None, 'version': '1', 'type': 'SFA', 'extensions': [], 'schema': None}
            rspec_tmp = RSpec(version = version)
            rspec_tmp.version.add_network(networks[0]['name'])	
            rspec_tmp.version.add_nodes([node])
            component_name = ''
            component_name = node['component_name']

            rspec_tmp.version.add_slivers(hostnames = [component_name])
            rspec_tmp_xml = RSpecConverter.to_sfa_rspec(rspec_tmp.toxml())
 
            self.__instances.add(component_name)
            rspec_xml = {}
            rspec_xml['xmlRspec'] = rspec_tmp_xml
            self.__rspecs['/SFAPNode-%s' %component_name] = rspec_xml
            logger.debug("PNodes %s " %component_name)

        logger.debug(self.__rspecs)
        return [ Identifier("/SFAPNode-%s"  %i) for i in self.__instances ]
Пример #6
0
    def get_rspec(self, slice_xrn=None, version = None, options={}):

        version_manager = VersionManager()
        version = version_manager.get_version(version)
        if not slice_xrn:
            rspec_version = version_manager._get_version(version.type, version.version, 'ad')
        else:
            rspec_version = version_manager._get_version(version.type, version.version, 'manifest')

        slice, slivers = self.get_slice_and_slivers(slice_xrn)
        rspec = RSpec(version=rspec_version, user_options=options)
        if slice and 'expires' in slice:
            rspec.xml.set('expires',  datetime_to_string(utcparse(slice['expires'])))

        nodes = self.get_nodes(slice_xrn, slice, slivers, options)
        rspec.version.add_nodes(nodes)
        # add sliver defaults
        default_sliver = slivers.get(None, [])
        if default_sliver:
            default_sliver_attribs = default_sliver.get('tags', [])
            for attrib in default_sliver_attribs:
                 logger.info(attrib)
                 rspec.version.add_default_sliver_attribute(attrib['tagname'], attrib['value'])
        
        return rspec.toxml()
Пример #7
0
    def Provision(self, api, xrn, creds, options):
        call_id = options.get('call_id')
        if Callids().already_handled(call_id): return ""

        version_manager = VersionManager()
        def _Provision(aggregate, server, xrn, credential, options):
            tStart = time.time()
            try:
                # Need to call GetVersion at an aggregate to determine the supported
                # rspec type/format beofre calling CreateSliver at an Aggregate.
                server_version = api.get_cached_server_version(server)
                result = server.Provision(xrn, credential, options)
                return {"aggregate": aggregate, "result": result, "elapsed": time.time()-tStart, "status": "success"}
            except:
                logger.log_exc('Something wrong in _Allocate with URL %s'%server.url)
                return {"aggregate": aggregate, "elapsed": time.time()-tStart, "status": "exception", "exc_info": sys.exc_info()}

        # attempt to use delegated credential first
        cred = api.getDelegatedCredential(creds)
        if not cred:
            cred = api.getCredential()

        # get the callers hrn
        valid_cred = api.auth.checkCredentials(creds, 'createsliver', xrn)[0]
        caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn()
        multiclient = MultiClient()
        for aggregate in api.aggregates:
            # prevent infinite loop. Dont send request back to caller
            # unless the caller is the aggregate's SM
            if caller_hrn == aggregate and aggregate != api.hrn:
                continue
            interface = api.aggregates[aggregate]
            server = api.server_proxy(interface, cred)
            # Just send entire RSpec to each aggregate
            multiclient.run(_Provision, aggregate, server, xrn, [cred], options)

        results = multiclient.get_results()
        # Set the manifest of KOREN
        manifest_version = version_manager._get_version('KOREN', '1', 'manifest')
#        manifest_version = version_manager._get_version('GENI', '3', 'manifest')
        result_rspec = RSpec(version=manifest_version)
        geni_slivers = []
        geni_urn  = None  
        for result in results:
            self.add_slicemgr_stat(result_rspec, "Provision", result["aggregate"], result["elapsed"],
                                   result["status"], result.get("exc_info",None))
            if result["status"]=="success":
                try:
                    res = result['result']['value']
                    geni_urn = res['geni_urn']
                    result_rspec.version.merge(ReturnValue.get_value(res['geni_rspec']))
                    geni_slivers.extend(res['geni_slivers'])
                except:
                    api.logger.log_exc("SM.Provision: Failed to merge aggregate rspec")
        return {
            'geni_urn': geni_urn,
            'geni_rspec': result_rspec.toxml(),
            'geni_slivers': geni_slivers
        }            
Пример #8
0
 def list_resources(self, version=None, options={}):
     version_manager = VersionManager()
     version = version_manager.get_version(version)
     rspec_version = version_manager._get_version(version.type, version.version, 'ad')
     rspec = RSpec(version=version, user_options=options)
     nodes = self.get_aggregate_nodes()
     rspec.version.add_nodes(nodes)
     return rspec.toxml()
Пример #9
0
    def list_resources(self, version = None, options=None):
        """
        Returns an advertisement Rspec of available resources at this
        aggregate. This Rspec contains a resource listing along with their
        description, providing sufficient information for clients to be able to
        select among available resources.

        :param options: various options. The valid options are: {boolean
            geni_compressed <optional>; struct geni_rspec_version { string type;
            #case insensitive , string version; # case insensitive}} . The only
            mandatory options if options is specified is geni_rspec_version.
        :type options: dictionary

        :returns: On success, the value field of the return struct will contain
            a geni.rspec advertisment RSpec
        :rtype: Rspec advertisement in xml.

        .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3/CommonConcepts#RSpecdatatype
        .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3#ListResources
        """

        if options is None: options={}
        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(version.type,
                                                    version.version, 'ad')
        rspec = RSpec(version=rspec_version, user_options=options)
        # variable ldap_username to be compliant with  get_all_leases
        # prototype. Now unused in geni-v3 since we are getting all the leases
        # here
        ldap_username = None
        if not options.get('list_leases') or options['list_leases'] != 'leases':
            # get nodes
            nodes_dict  = self.get_nodes(options)

            # no interfaces on iotlab nodes
            # convert nodes to rspec nodes
            rspec_nodes = []
            for node_id in nodes_dict:
                node = nodes_dict[node_id]
                rspec_node = self.node_to_rspec_node(node)
                rspec_nodes.append(rspec_node)
            rspec.version.add_nodes(rspec_nodes)

            # add links
            # links = self.get_links(sites, nodes_dict, interfaces)
            # rspec.version.add_links(links)

        if not options.get('list_leases') or options.get('list_leases') \
            and options['list_leases'] != 'resources':
            leases = self.get_all_leases(ldap_username)
            rspec.version.add_leases(leases)

        return rspec.toxml()
Пример #10
0
 def get_rspec(self, slice_xrn=None, version=None, options={}):
     version_manager = VersionManager()
     version = version_manager.get_version(version)
     if not slice_xrn:
         rspec_version = version_manager._get_version(version.type, version.version, 'ad')
         nodes = self.get_aggregate_nodes()
     else:
         rspec_version = version_manager._get_version(version.type, version.version, 'manifest')
         nodes = self.get_slice_nodes(slice_xrn)
     rspec = RSpec(version=rspec_version, user_options=options)
     rspec.version.add_nodes(nodes)
     return rspec.toxml()
Пример #11
0
    def to_sfa_rspec(rspec, content_type = None):
        if not isinstance(rspec, RSpec):
            pg_rspec = RSpec(rspec)
        else:
            pg_rspec = rspec
        
        version_manager = VersionManager()
        sfa_version = version_manager._get_version('sfa', '1')    
        sfa_rspec = RSpec(version=sfa_version)

        #nodes = pg_rspec.version.get_nodes()
        #sfa_rspec.version.add_nodes(nodes())
        #sfa_rspec.version.add_links(pg_rspec.version.get_links())
        #return sfa_rspec.toxml() 

        # get network
        networks = pg_rspec.version.get_networks()
        network_hrn = networks[0]["name"]
        network_element = sfa_rspec.xml.add_element('network', name=network_hrn, id=network_hrn)
        
        # get nodes
        pg_nodes_elements = pg_rspec.version.get_nodes()
        nodes_with_slivers = pg_rspec.version.get_nodes_with_slivers()
        i = 1
        for pg_node in pg_nodes_elements:
            attribs = dict(pg_node.items())
            attribs['id'] = 'n'+str(i)
            
            node_element = network_element.add_element('node')
            for attrib in attribs:
                if type(attribs[attrib]) == str:
                    node_element.set(attrib, attribs[attrib])
            urn = pg_node["component_id"]
            if urn:
                if type(urn)==list:
                    # legacy code, not sure if urn is ever a list...
                    urn = urn[0]
                hostname = Xrn.urn_split(urn)[-1]
                hostname_element = node_element.add_element('hostname')
                hostname_element.set_text(hostname)
                if hostname in nodes_with_slivers:
                    node_element.add_element('sliver')

            for hardware_type in pg_node["hardware_types"]:
                if "name" in hardware_type:
                    node_element.add_element("hardware_type", name=hardware_type["name"])
                     
            # just copy over remaining child elements  
            #for child in pg_node_element.getchildren():
            #    node_element.append(transform(child).getroot())
            i = i+1
 
        return sfa_rspec.toxml()
Пример #12
0
    def create(self, opts, args):
        server = self.get_server_from_opts(opts)
        server_version = self.get_cached_server_version(server)
        slice_hrn = args[0]
        slice_urn = hrn_to_urn(slice_hrn, 'slice') 
        user_cred = self.get_user_cred()
        slice_cred = self.get_slice_cred(slice_hrn).save_to_string(save_parents=True)
        # delegate the cred to the callers root authority
        delegated_cred = self.delegate_cred(slice_cred, get_authority(self.authority)+'.slicemanager')
        #delegated_cred = self.delegate_cred(slice_cred, get_authority(slice_hrn))
        #creds.append(delegated_cred)
        rspec_file = self.get_rspec_file(args[1])
        rspec = open(rspec_file).read()

        # need to pass along user keys to the aggregate.  
        # users = [
        #  { urn: urn:publicid:IDN+emulab.net+user+alice
        #    keys: [<ssh key A>, <ssh key B>] 
        #  }]
        users = []
        slice_records = self.registry.Resolve(slice_urn, [user_cred.save_to_string(save_parents=True)])
        if slice_records and 'researcher' in slice_records[0] and slice_records[0]['researcher']!=[]:
            slice_record = slice_records[0]
            user_hrns = slice_record['researcher']
            user_urns = [hrn_to_urn(hrn, 'user') for hrn in user_hrns]
            user_records = self.registry.Resolve(user_urns, [user_cred.save_to_string(save_parents=True)])
            
            if 'sfa' not in server_version:
                users = pg_users_arg(user_records)
                rspec = RSpec(rspec)
                rspec.filter({'component_manager_id': server_version['urn']})
                rspec = RSpecConverter.to_pg_rspec(rspec.toxml(), content_type='request')
                creds = [slice_cred]
            else:
                users = sfa_users_arg(user_records, slice_record)
                creds = [slice_cred, delegated_cred]
        call_args = [slice_urn, creds, rspec, users]
        if self.server_supports_call_id_arg(server):
            call_args.append(unique_call_id())
           
        result = server.CreateSliver(*call_args)
        if opts.file is None:
            print result
        else:
            save_rspec_to_file (result, opts.file)
        return result
Пример #13
0
 def _CreateSliver(aggregate, server, xrn, credential, rspec, users, options):
     tStart = time.time()
     try:
         # Need to call GetVersion at an aggregate to determine the supported
         # rspec type/format beofre calling CreateSliver at an Aggregate.
         server_version = api.get_cached_server_version(server)
         requested_users = users
         if 'sfa' not in server_version and 'geni_api' in server_version:
             # sfa aggregtes support both sfa and pg rspecs, no need to convert
             # if aggregate supports sfa rspecs. otherwise convert to pg rspec
             rspec = RSpec(RSpecConverter.to_pg_rspec(rspec, 'request'))
             filter = {'component_manager_id': server_version['urn']}
             rspec.filter(filter)
             rspec = rspec.toxml()
             requested_users = sfa_to_pg_users_arg(users)
         rspec = server.CreateSliver(xrn, credential, rspec, requested_users, options)
         return {"aggregate": aggregate, "rspec": rspec, "elapsed": time.time()-tStart, "status": "success"}
     except:
         logger.log_exc('Something wrong in _CreateSliver with URL %s'%server.url)
         return {"aggregate": aggregate, "elapsed": time.time()-tStart, "status": "exception", "exc_info": sys.exc_info()}
Пример #14
0
    def describe(self, urns, version=None, options=None):
        if options is None: options={}
        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(version.type, version.version, 'manifest')
        rspec = RSpec(version=rspec_version, user_options=options)

        # get slivers
        geni_slivers = []
        slivers = self.get_slivers(urns, options)
        if slivers:
            rspec_expires = datetime_to_string(utcparse(slivers[0]['expires']))
        else:
            rspec_expires = datetime_to_string(utcparse(time.time()))
        rspec.xml.set('expires',  rspec_expires)

        # lookup the sliver allocations
        geni_urn = urns[0]
        sliver_ids = [sliver['sliver_id'] for sliver in slivers]
        constraint = SliverAllocation.sliver_id.in_(sliver_ids)
        sliver_allocations = self.driver.api.dbsession().query(SliverAllocation).filter(constraint)
        sliver_allocation_dict = {}
        for sliver_allocation in sliver_allocations:
            geni_urn = sliver_allocation.slice_urn
            sliver_allocation_dict[sliver_allocation.sliver_id] = sliver_allocation

        # add slivers
        nodes_dict = {}
        for sliver in slivers:
            nodes_dict[sliver['node_id']] = sliver
        rspec_nodes = []
        for sliver in slivers:
            rspec_node = self.sliver_to_rspec_node(sliver, sliver_allocation_dict)
            rspec_nodes.append(rspec_node)
            geni_sliver = self.rspec_node_to_geni_sliver(rspec_node, sliver_allocation_dict)
            geni_slivers.append(geni_sliver)
        rspec.version.add_nodes(rspec_nodes)

        return {'geni_urn': geni_urn,
                'geni_rspec': rspec.toxml(),
                'geni_slivers': geni_slivers}
Пример #15
0
    def to_sfa_rspec(rspec, content_type = None):
        if not isinstance(rspec, RSpec):
            pg_rspec = RSpec(rspec)
        else:
            pg_rspec = rspec
        
        version_manager = VersionManager()
        sfa_version = version_manager._get_version('sfa', '1')    
        sfa_rspec = RSpec(version=sfa_version)

        # get network
        network_urn = pg_rspec.version.get_network()
        network,  _ = urn_to_hrn(network_urn)
        network_element = sfa_rspec.xml.add_element('network', {'name': network, 'id': network})
        
        # get nodes
        pg_nodes_elements = pg_rspec.version.get_node_elements()
        nodes_with_slivers = pg_rspec.version.get_nodes_with_slivers()
        i = 1
        for pg_node_element in pg_nodes_elements:
            attribs = dict(pg_node_element.attrib.items()) 
            attribs['id'] = 'n'+str(i)
            
            node_element = sfa_rspec.xml.add_element('node', attribs, parent=network_element)
            urn = pg_node_element.xpath('@component_id', namespaces=pg_rspec.namespaces)
            if urn:
                urn = urn[0]
                hostname = Xrn.urn_split(urn)[-1]
                hostname_element = sfa_rspec.xml.add_element('hostname', parent=node_element, text=hostname)
                if hostname in nodes_with_slivers:
                    sfa_rspec.xml.add_element('sliver', parent=node_element)
                     
            urn_element = sfa_rspec.xml.add_element('urn', parent=node_element, text=urn)


            # just copy over remaining child elements  
            for child in pg_node_element.getchildren():
                node_element.append(transform(child).getroot())
            i = i+1
 
        return sfa_rspec.toxml()
Пример #16
0
    def Describe(self, api, creds, xrns, options):
        def _Describe(server, xrn, creds, options):
            return server.Describe(xrn, creds, options)

        call_id = options.get('call_id')
        if Callids().already_handled(call_id): return {}
        # attempt to use delegated credential first
        cred = api.getDelegatedCredential(creds)
        if not cred:
            cred = api.getCredential()
        multiclient = MultiClient()
        for aggregate in api.aggregates:
            interface = api.aggregates[aggregate]
            server = api.server_proxy(interface, cred)
            multiclient.run (_Describe, server, xrns, [cred], options)
        results = [ReturnValue.get_value(result) for result in multiclient.get_results()]

        # get rid of any void result - e.g. when call_id was hit, where by convention we return {}
        results = [ result for result in results if result and result.get('geni_urn')]

        # do not try to combine if there's no result
        if not results : return {}

        # otherwise let's merge stuff
        version_manager = VersionManager()
        manifest_version = version_manager._get_version('GENI', '3', 'manifest')
        result_rspec = RSpec(version=manifest_version)
        geni_slivers = []
        geni_urn  = None
        for result in results:
            try:
                geni_urn = result['geni_urn']
                result_rspec.version.merge(ReturnValue.get_value(result['geni_rspec']))
                geni_slivers.extend(result['geni_slivers'])
            except:
                api.logger.log_exc("SM.Provision: Failed to merge aggregate rspec")
        return {
            'geni_urn': geni_urn,
            'geni_rspec': result_rspec.toxml(),    
            'geni_slivers': geni_slivers
        }  
Пример #17
0
    def list_resources(self, version = None, options={}):

        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(version.type, version.version, 'ad')
        rspec = RSpec(version=rspec_version, user_options=options)

        # get nodes
        nodes  = self.get_nodes(options)
        nodes_dict = {}
        for node in nodes:
            nodes_dict[node['node_id']] = node

        # convert nodes to rspec nodes
        rspec_nodes = []
        for node in nodes:
            rspec_node = self.node_to_rspec_node(node)
            rspec_nodes.append(rspec_node)
        rspec.version.add_nodes(rspec_nodes)

        return rspec.toxml()
Пример #18
0
    def list_resources(self, version = None, options=None):
        if options is None: options={}

        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(version.type, version.version, 'ad')
        rspec = RSpec(version=rspec_version, user_options=options)
       
        if not options.get('list_leases') or options['list_leases'] != 'leases':
            # get nodes
            nodes  = self.get_nodes(options)
            site_ids = []
            interface_ids = []
            tag_ids = []
            nodes_dict = {}
            for node in nodes:
                site_ids.append(node['site_id'])
                interface_ids.extend(node['interface_ids'])
                tag_ids.extend(node['node_tag_ids'])
                nodes_dict[node['node_id']] = node
            sites = self.get_sites({'site_id': site_ids})
            interfaces = self.get_interfaces({'interface_id':interface_ids})
            node_tags = self.get_node_tags({'node_tag_id': tag_ids})
            pl_initscripts = self.get_pl_initscripts()
            # convert nodes to rspec nodes
            rspec_nodes = []
            for node in nodes:
                rspec_node = self.node_to_rspec_node(node, sites, interfaces, node_tags, pl_initscripts)
                rspec_nodes.append(rspec_node)
            rspec.version.add_nodes(rspec_nodes)

            # add links
            links = self.get_links(sites, nodes_dict, interfaces)        
            rspec.version.add_links(links)

        if not options.get('list_leases') or options.get('list_leases') and options['list_leases'] != 'resources':
           leases = self.get_leases()
           rspec.version.add_leases(leases)

        return rspec.toxml()
Пример #19
0
    def get_rspec(self, slice_xrn=None, version = None, options=None):
        if options is None: options={}

        version_manager = VersionManager()
        version = version_manager.get_version(version)

        if not slice_xrn:
            rspec_version = version_manager._get_version(version.type, version.version, 'ad')
        else:
            rspec_version = version_manager._get_version(version.type, version.version, 'manifest')

        slice, slivers = self.get_slice_and_slivers(slice_xrn)

        rspec = RSpec(version=rspec_version, user_options=options)

        if slice and 'expires' in slice:
            rspec.xml.set('expires',  datetime_to_string(utcparse(slice['expires'])))

        if not options.get('list_leases') or options.get('list_leases') and options['list_leases'] != 'leases':
           nodes = self.get_nodes(slice_xrn, slice, slivers, options)
           rspec.version.add_nodes(nodes)
           # add sliver defaults
           default_sliver = slivers.get(None, [])
           if default_sliver:
              default_sliver_attribs = default_sliver.get('tags', [])
              for attrib in default_sliver_attribs:
                  logger.info(attrib)
                  rspec.version.add_default_sliver_attribute(attrib['tagname'], attrib['value'])
           # add wifi channels
           channels = self.get_channels(slice, options)
           rspec.version.add_channels(channels)

        if not options.get('list_leases') or options.get('list_leases') and options['list_leases'] != 'resources':
           leases_channels = self.get_leases_and_channels(slice, slice_xrn)
           rspec.version.add_leases(leases_channels)

        return rspec.toxml()
Пример #20
0
    def build_sfa_rspec(self, slice_id, resources, properties, leases):
        """
        Build the XML RSpec from list of resources' urns.
        eg. resources = ["urn:publicid:IDN+ple:modenaple+node+planetlab-1.ing.unimo.it"]
        """
        #if isinstance(resources, str):
        #    resources = eval(resources)
        # rspec_type and rspec_version should be set in the config of the platform,
        # we use GENIv3 as default one if not
        if self.config:
            if 'rspec_type' and 'rspec_version' in self.config:
                rspec_version = self.config['rspec_type'] + ' ' + self.config['rspec_version']
        else:
            rspec_version = 'GENI 3'

        # extend rspec version with "content_type"
        rspec_version += ' request'
        
        rspec = RSpec(version=rspec_version)

        nodes = []
        channels = []
        links = []
        self._log.debug("Building RSpec for resources %s" % resources)
        cardinal = 0
        wilab = False
        for urn in resources:
            # XXX TO BE CORRECTED, this handles None values
            if not urn:
                continue
            self._log.debug(urn)
            resource = dict()
            # TODO: take into account the case where we send a dict of URNs without keys
            #resource['component_id'] = resource.pop('urn')
            resource['component_id'] = urn
            resource_hrn, resource_type = urn_to_hrn(resource['component_id'])
            # build component_manager_id
            top_auth = resource_hrn.split('.')[0]
            cm = urn.split("+")
            resource['component_manager_id'] = "%s+%s+authority+cm" % (cm[0],top_auth)

            if resource_type == 'node':
                # XXX dirty hack WiLab !!!
#                Commented Lucia, doesn't work for wilabt  
#                if self.config:
#                    if 'wilab2' in self.config['sm']:
#                        resource['client_id'] = "PC"
#                        resource['sliver_type'] = "raw-pc"
                if 'wilab2' in urn:
                    wilab = True
                    resource['client_id'] = "node%s" % cardinal
                    resource['sliver_type'] = "raw-pc"
                    resource['disk_image'] = "hola"
                    top_auth = resource_hrn.replace("\\", "").split('.')
                    top_auth.pop()
                    top_auth = '.'.join(top_auth)
                    cm = urn.split("+")
                    resource['component_manager_id'] = "%s+%s+authority+cm" % (cm[0],top_auth)
                    cardinal += 1
                nodes.append(resource)
            elif resource_type == 'link':
                links.append(resource)
            elif resource_type == 'channel':
                channels.append(resource)
            else:
                raise Exception, "Not supported type of resource" 
        
        rspec.version.add_nodes(nodes, rspec_content_type="request")
        #rspec.version.add_leases(leases)
        #rspec.version.add_links(links)
        #rspec.version.add_channels(channels)

        #self._log.debug("request rspec: %s"%rspec.toxml())
        string = rspec.toxml()
        if wilab and properties is not None:
            ## dirty hack for the f4f demo
            b = string.split('\n')
            for i, n in enumerate(b):
                if 'sliver_type name="raw-pc"' in n:
                    b[i] = '<sliver_type name="raw-pc">'
                    b.insert(i+1, '<disk_image name="urn:publicid:IDN+wall2.ilabt.iminds.be+image+emulab-ops//%s"/>' % properties['disk_image'])
                    #b.insert(i+1, '<disk_image name="urn:publicid:IDN+wilab2.ilabt.iminds.be+image+nepi:%s"/>' % properties['disk_image'])
                    b.insert(i+2, '</sliver_type>')
            string = ''.join(b)
        self._log.debug("request rspec : %s" % string)
        return string
Пример #21
0
    def build_rspec(cls, slice_urn, resources, leases, flowspace, vms, rspec_version='GENI 3 request'):
        """
        Builds a RSpecs based on the specified resources and leases.

        Args:
            slice_urn (string) : the urn of the slice [UNUSED] [HRN in NITOS ?]

        Returns:
            string : the string version of the created RSpec.
        """
        import time
        start_time = None
        end_time = None

        # Default duration for WiLab is 2 hours
        duration_default = 120
        for lease in leases:
            if 'end_time' in lease:
                end_time = lease['end_time']
                start_time = lease['start_time']
                break

        if start_time is None:
            # start_time = Now
            start_time = time.time()

        if end_time is None:
            end_time = int(start_time + duration_default*60)
            #raise Exception, "end_time is mandatory in leases"

        # duration in seconds from now till end_time
        duration = end_time - start_time
        # duration in minutes
        duration = duration / 60
        duration = int(duration)
        if duration < duration_default:
            duration = duration_default
        Log.tmp("start_time = ",start_time)
        Log.tmp("end_time = ",end_time)
        Log.tmp("duration = ",duration)
        # RSpec will have expires date = now + duration
        rspec = RSpec(version=rspec_version, ttl=duration, expires=end_time)

        nodes = []
        channels = []
        links = []

        # XXX Here it is only about mappings and hooks between ontologies
        i = 0
        for urn in resources:
            # XXX TO BE CORRECTED, this handles None values
            if not urn:
                continue
            resource = dict()
            # TODO: take into account the case where we send a dict of URNs without keys
            #resource['component_id'] = resource.pop('urn')
            resource['component_id'] = urn
            resource_hrn, resource_type = urn_to_hrn(urn) # resource['component_id'])
            # build component_manager_id

            # The only change for WiLab compared to Generic SFAWrapParser
            cm = urn.split("+")
            resource['component_manager_id'] = "%s+%s+authority+cm" % (cm[0],cm[1])

            #print "resource_type", resource_type
            if resource_type == 'node':
                #print "NODE", resource, cls
                resource['client_id'] = "PC" + str(i)
                resource = cls.on_build_resource_hook(resource)
                nodes.append(resource)
            elif resource_type == 'link':
                links.append(resource)
            elif resource_type == 'channel':
                channels.append(resource)
            else:
                raise Exception, "Not supported type of resource" 

            i = i + 1
        #for node in nodes:
        #    print "NODE:", node

        rspec.version.add_nodes(nodes, rspec_content_type="request")
        #rspec.version.add_links(links)
        #rspec.version.add_channels(channels)

        #sfa_leases = cls.manifold_to_sfa_leases(leases, slice_urn)
        ##print "sfa_leases", sfa_leases
        #if sfa_leases:
        #    # SFAWRAP BUG ???
        #    # rspec.version.add_leases bugs with an empty set of leases
        #    # slice_id = leases[0]['slice_id']
        #    # TypeError: list indices must be integers, not str
        #    rspec.version.add_leases(sfa_leases, []) # XXX Empty channels for now
        return rspec.toxml()
Пример #22
0
#! /usr/bin/env python

import sys
from sfa.client.sfi_commands import Commands
from sfa.rspecs.rspec import RSpec
from sfa.util.xrn import Xrn

command = Commands(usage="%prog [options]",
                   description="List all links in the RSpec. " +
                   "Use this to display the list of available links. ")
command.prep()

if command.opts.infile:
    rspec = RSpec(command.opts.infile)
    links = rspec.version.get_links()
    if command.opts.outfile:
        sys.stdout = open(command.opts.outfile, 'w')

    for link in links:
        ifname1 = Xrn(link['interface1']['component_id']).get_leaf()
        ifname2 = Xrn(link['interface2']['component_id']).get_leaf()
        print "%s %s" % (ifname1, ifname2)
Пример #23
0
    def merge(self, in_rspec):
        """
        Merge contents for specified rspec with current rspec
        """

        from sfa.rspecs.rspec import RSpec
        if isinstance(in_rspec, RSpec):
            rspec = in_rspec
        else:
            rspec = RSpec(in_rspec)
        if rspec.version.type.lower() == 'protogeni':
            from sfa.rspecs.rspec_converter import RSpecConverter
            in_rspec = RSpecConverter.to_sfa_rspec(rspec.toxml())
            rspec = RSpec(in_rspec)

        # just copy over all networks
        current_networks = self.get_networks()
        networks = rspec.version.get_network_elements()
        for network in networks:
            current_network = network.get('name')
            if current_network and current_network not in current_networks:
                self.xml.root.append(network)
                current_networks.append(current_network)

if __name__ == '__main__':
    from sfa.rspecs.rspec import RSpec
    from sfa.rspecs.rspec_elements import *
    r = RSpec('/tmp/resources.rspec')
    r.load_rspec_elements(SFAv1.elements)
    print r.get(RSpecElements.NODE)
Пример #24
0
    def describe(self, urns, version=None, options={}):
        """
        Retrieve a manifest RSpec describing the resources contained by the
        named entities, e.g. a single slice or a set of the slivers in a slice.
        This listing and description should be sufficiently descriptive to allow
        experimenters to use the resources.

        :param urns: If a slice urn is supplied and there are no slivers in the
            given slice at this aggregate, then geni_rspec shall be a valid
            manifest RSpec, containing no node elements - no resources.
        :type urns: list  or strings
        :param options: various options. the valid options are: {boolean
            geni_compressed <optional>; struct geni_rspec_version { string type;
            #case insensitive , string version; # case insensitive}}
        :type options: dictionary

        :returns: On success returns the following dictionary {geni_rspec:
            <geni.rspec, a Manifest RSpec>, geni_urn: <string slice urn of the
            containing slice>, geni_slivers:{ geni_sliver_urn:
            <string sliver urn>, geni_expires:  <dateTime.rfc3339 allocation
            expiration string, as in geni_expires from SliversStatus>,
            geni_allocation_status: <string sliver state - e.g. geni_allocated
            or geni_provisioned >, geni_operational_status:
            <string sliver operational state>, geni_error: <optional string.
            The field may be omitted entirely but may not be null/None,
            explaining any failure for a sliver.>}

        .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3#Describe
        .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3/CommonConcepts#urns
        """
        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(version.type,
                                                     version.version,
                                                     'manifest')
        rspec = RSpec(version=rspec_version, user_options=options)

        # get slivers
        geni_slivers = []
        slivers = self.get_slivers(urns, options)
        if slivers:
            rspec_expires = datetime_to_string(utcparse(slivers[0]['expires']))
        else:
            rspec_expires = datetime_to_string(utcparse(time.time()))
        rspec.xml.set('expires', rspec_expires)

        # lookup the sliver allocations
        geni_urn = urns[0]
        sliver_ids = [sliver['sliver_id'] for sliver in slivers]
        logger.debug(" IOTLAB_API.PY \tDescribe  sliver_ids %s " %
                     (sliver_ids))
        constraint = SliverAllocation.sliver_id.in_(sliver_ids)
        query = self.driver.api.dbsession().query(SliverAllocation)
        sliver_allocations = query.filter((constraint)).all()
        logger.debug(" IOTLAB_API.PY \tDescribe  sliver_allocations %s " %
                     (sliver_allocations))
        sliver_allocation_dict = {}
        for sliver_allocation in sliver_allocations:
            geni_urn = sliver_allocation.slice_urn
            sliver_allocation_dict[sliver_allocation.sliver_id] = \
                                                            sliver_allocation

        # add slivers
        nodes_dict = {}
        for sliver in slivers:
            nodes_dict[sliver['node_id']] = sliver
        rspec_nodes = []
        for sliver in slivers:
            rspec_node = self.sliver_to_rspec_node(sliver,
                                                   sliver_allocation_dict)
            rspec_nodes.append(rspec_node)
            logger.debug(
                " IOTLAB_API.PY \tDescribe  sliver_allocation_dict %s " %
                (sliver_allocation_dict))
            geni_sliver = self.rspec_node_to_geni_sliver(
                rspec_node, sliver_allocation_dict)
            geni_slivers.append(geni_sliver)

        logger.debug(" IOTLAB_API.PY \tDescribe rspec_nodes %s\
                        rspec %s " % (rspec_nodes, rspec))
        rspec.version.add_nodes(rspec_nodes)

        return {
            'geni_urn': geni_urn,
            'geni_rspec': rspec.toxml(),
            'geni_slivers': geni_slivers
        }
Пример #25
0
    def describe(self, urns, version=None, options=None):
        """
        Retrieve a manifest RSpec describing the resources contained by the
        named entities, e.g. a single slice or a set of the slivers in a slice.
        This listing and description should be sufficiently descriptive to allow
        experimenters to use the resources.

        :param urns: If a slice urn is supplied and there are no slivers in the
            given slice at this aggregate, then geni_rspec shall be a valid
            manifest RSpec, containing no node elements - no resources.
        :type urns: list  or strings
        :param options: various options. the valid options are: {boolean
            geni_compressed <optional>; struct geni_rspec_version { string type;
            #case insensitive , string version; # case insensitive}}
        :type options: dictionary

        :returns: On success returns the following dictionary {geni_rspec:
            <geni.rspec, a Manifest RSpec>, geni_urn: <string slice urn of the
            containing slice>, geni_slivers:{ geni_sliver_urn:
            <string sliver urn>, geni_expires:  <dateTime.rfc3339 allocation
            expiration string, as in geni_expires from SliversStatus>,
            geni_allocation_status: <string sliver state - e.g. geni_allocated
            or geni_provisioned >, geni_operational_status:
            <string sliver operational state>, geni_error: <optional string.
            The field may be omitted entirely but may not be null/None,
            explaining any failure for a sliver.>}

        .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3#Describe
        .. seealso:: http://groups.geni.net/geni/wiki/GAPI_AM_API_V3/CommonConcepts#urns
        """
        if options is None: options={}
        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(
                                    version.type, version.version, 'manifest')
        rspec = RSpec(version=rspec_version, user_options=options)

        # get slivers
        geni_slivers = []
        slivers = self.get_slivers(urns, options)
        if slivers:
            rspec_expires = datetime_to_string(utcparse(slivers[0]['expires']))
        else:
            rspec_expires = datetime_to_string(utcparse(time.time()))
        rspec.xml.set('expires',  rspec_expires)

        # lookup the sliver allocations
        geni_urn = urns[0]
        sliver_ids = [sliver['sliver_id'] for sliver in slivers]
        constraint = SliverAllocation.sliver_id.in_(sliver_ids)
        query = self.driver.api.dbsession().query(SliverAllocation)
        sliver_allocations = query.filter((constraint)).all()
        sliver_allocation_dict = {}
        for sliver_allocation in sliver_allocations:
            geni_urn = sliver_allocation.slice_urn
            sliver_allocation_dict[sliver_allocation.sliver_id] = \
                                                            sliver_allocation
        if not options.get('list_leases') or options['list_leases'] != 'leases':                                                    
            # add slivers
            nodes_dict = {}
            for sliver in slivers:
                nodes_dict[sliver['node_id']] = sliver
            rspec_nodes = []
            for sliver in slivers:
                rspec_node = self.sliver_to_rspec_node(sliver,
                                                        sliver_allocation_dict)
                rspec_nodes.append(rspec_node)
                geni_sliver = self.rspec_node_to_geni_sliver(rspec_node,
                                sliver_allocation_dict)
                geni_slivers.append(geni_sliver)
            rspec.version.add_nodes(rspec_nodes)

        if not options.get('list_leases') or options['list_leases'] == 'resources':
            if slivers:
                leases = self.get_leases(slivers[0])
                rspec.version.add_leases(leases)

        return {'geni_urn': geni_urn,
                'geni_rspec': rspec.toxml(),
                'geni_slivers': geni_slivers}
Пример #26
0
    def get_rspec(self, slice_xrn=None, login=None, version=None,
                  options=None):
        """
        Returns xml rspec:
        - a full advertisement rspec with the testbed resources if slice_xrn is
        not specified.If a lease option is given, also returns the leases
        scheduled on the testbed.
        - a manifest Rspec with the leases and nodes in slice's leases if
        slice_xrn is not None.

        :param slice_xrn: srn of the slice
        :type slice_xrn: string
        :param login: user'uid (ldap login) on iotlab
        :type login: string
        :param version: can be set to sfa or iotlab
        :type version: RSpecVersion
        :param options: used to specify if the leases should also be included in
            the returned rspec.
        :type options: dict

        :returns: Xml Rspec.
        :rtype: XML


        """

        ldap_username = None
        rspec = None
        version_manager = VersionManager()
        version = version_manager.get_version(version)
        logger.debug("IotlabAggregate \t get_rspec ***version %s \
                    version.type %s  version.version %s options %s \r\n"
                     % (version, version.type, version.version, options))

        if slice_xrn is None:
            rspec_version = version_manager._get_version(version.type,
                                                         version.version, 'ad')

        else:
            rspec_version = version_manager._get_version(
                version.type, version.version, 'manifest')

        slices, slivers = self.get_slice_and_slivers(slice_xrn, login)
        if slice_xrn and slices is not None:
            #Get user associated with this slice
            #for one_slice in slices :
            ldap_username = self.find_ldap_username_from_slice(slices[0])
            # ldap_username = slices[0]['reg_researchers'][0].__dict__['hrn']
            #  # ldap_username = slices[0]['user']
            # tmp = ldap_username.split('.')
            # ldap_username = tmp[1]
            logger.debug("IotlabAggregate \tget_rspec **** \
                    LDAP USERNAME %s \r\n" \
                    % (ldap_username))
        #at this point sliver may be empty if no iotlab job
        #is running for this user/slice.
        rspec = RSpec(version=rspec_version, user_options=options)

        logger.debug("\r\n \r\n IotlabAggregate \tget_rspec *** \
                      slice_xrn %s slices  %s\r\n \r\n"
                     % (slice_xrn, slices))

        if options is not None:
            lease_option = options['list_leases']
        else:
            #If no options are specified, at least print the resources
            lease_option = 'all'
           #if slice_xrn :
               #lease_option = 'all'

        if lease_option in ['all', 'resources']:
        #if not options.get('list_leases') or options.get('list_leases')
        #and options['list_leases'] != 'leases':
            nodes = self.get_nodes()
            logger.debug("\r\n")
            logger.debug("IotlabAggregate \t lease_option %s \
                          get rspec  ******* nodes %s"
                         % (lease_option, nodes))

            sites_set = set([node['location']['site'] for node in nodes])

            #In case creating a job,  slice_xrn is not set to None
            rspec.version.add_nodes(nodes)
            if slice_xrn and slices is not None:
            #     #Get user associated with this slice
            #     #for one_slice in slices :
            #     ldap_username = slices[0]['reg_researchers']
            #      # ldap_username = slices[0]['user']
            #     tmp = ldap_username.split('.')
            #     ldap_username = tmp[1]
            #      # ldap_username = tmp[1].split('_')[0]

                logger.debug("IotlabAggregate \tget_rspec **** \
                        version type %s ldap_ user %s \r\n" \
                        % (version.type, ldap_username))
                if version.type == "Iotlab":
                    rspec.version.add_connection_information(
                        ldap_username, sites_set)

            default_sliver = slivers.get('default_sliver', [])
            if default_sliver and len(nodes) is not 0:
                #default_sliver_attribs = default_sliver.get('tags', [])
                logger.debug("IotlabAggregate \tget_rspec **** \
                        default_sliver%s \r\n" % (default_sliver))
                for attrib in default_sliver:
                    rspec.version.add_default_sliver_attribute(
                        attrib, default_sliver[attrib])

        if lease_option in ['all','leases']:
            leases = self.get_all_leases(ldap_username)
            rspec.version.add_leases(leases)
            logger.debug("IotlabAggregate \tget_rspec **** \
                       FINAL RSPEC %s \r\n" % (rspec.toxml()))
        return rspec.toxml()
Пример #27
0
            self.xml.remove_element('//default:available | //available')

class PGv2Ad(PGv2):
    enabled = True
    content_type = 'ad'
    schema = 'http://www.protogeni.net/resources/rspec/2/ad.xsd'
    template = '<rspec type="advertisement" xmlns="http://www.protogeni.net/resources/rspec/2" xmlns:flack="http://www.protogeni.net/resources/rspec/ext/flack/1" xmlns:plos="http://www.planet-lab.org/resources/sfa/ext/plos/1" xmlns:planetlab="http://www.planet-lab.org/resources/sfa/ext/planetlab/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.protogeni.net/resources/rspec/2 http://www.protogeni.net/resources/rspec/2/ad.xsd http://www.planet-lab.org/resources/sfa/ext/planetlab/1 http://www.planet-lab.org/resources/sfa/ext/planetlab/1/planetlab.xsd http://www.planet-lab.org/resources/sfa/ext/plos/1 http://www.planet-lab.org/resources/sfa/ext/plos/1/plos.xsd"/>'

class PGv2Request(PGv2):
    enabled = True
    content_type = 'request'
    schema = 'http://www.protogeni.net/resources/rspec/2/request.xsd'
    template = '<rspec type="request" xmlns="http://www.protogeni.net/resources/rspec/2" xmlns:flack="http://www.protogeni.net/resources/rspec/ext/flack/1" xmlns:plos="http://www.planet-lab.org/resources/sfa/ext/plos/1" xmlns:planetlab="http://www.planet-lab.org/resources/sfa/ext/planetlab/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.protogeni.net/resources/rspec/2 http://www.protogeni.net/resources/rspec/2/request.xsd http://www.planet-lab.org/resources/sfa/ext/planetlab/1 http://www.planet-lab.org/resources/sfa/ext/planetlab/1/planetlab.xsd http://www.planet-lab.org/resources/sfa/ext/plos/1 http://www.planet-lab.org/resources/sfa/ext/plos/1/plos.xsd"/>'

class PGv2Manifest(PGv2):
    enabled = True
    content_type = 'manifest'
    schema = 'http://www.protogeni.net/resources/rspec/2/manifest.xsd'
    template = '<rspec type="manifest" xmlns="http://www.protogeni.net/resources/rspec/2" xmlns:plos="http://www.planet-lab.org/resources/sfa/ext/plos/1" xmlns:flack="http://www.protogeni.net/resources/rspec/ext/flack/1" xmlns:planetlab="http://www.planet-lab.org/resources/sfa/ext/planetlab/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.protogeni.net/resources/rspec/2 http://www.protogeni.net/resources/rspec/2/manifest.xsd http://www.planet-lab.org/resources/sfa/ext/planetlab/1 http://www.planet-lab.org/resources/sfa/ext/planetlab/1/planetlab.xsd http://www.planet-lab.org/resources/sfa/ext/plos/1 http://www.planet-lab.org/resources/sfa/ext/plos/1/plos.xsd"/>'

     


if __name__ == '__main__':
    from sfa.rspecs.rspec import RSpec
    from sfa.rspecs.rspec_elements import *
    r = RSpec('/tmp/pg.rspec')
    r.load_rspec_elements(PGv2.elements)
    r.namespaces = PGv2.namespaces
    print r.get(RSpecElements.NODE)
Пример #28
0
Файл: pgv2.py Проект: tubav/sfa
            self.xml.remove_element('//default:available | //available')

class PGv2Ad(PGv2):
    enabled = True
    content_type = 'ad'
    schema = 'http://www.protogeni.net/resources/rspec/2/ad.xsd'
    template = '<rspec type="advertisement" xmlns="http://www.protogeni.net/resources/rspec/2" xmlns:flack="http://www.protogeni.net/resources/rspec/ext/flack/1" xmlns:plos="http://www.planet-lab.org/resources/sfa/ext/plos/1" xmlns:planetlab="http://www.planet-lab.org/resources/sfa/ext/planetlab/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.protogeni.net/resources/rspec/2 http://www.protogeni.net/resources/rspec/2/ad.xsd http://www.planet-lab.org/resources/sfa/ext/planetlab/1 http://www.planet-lab.org/resources/sfa/ext/planetlab/1/planetlab.xsd http://www.planet-lab.org/resources/sfa/ext/plos/1 http://www.planet-lab.org/resources/sfa/ext/plos/1/plos.xsd"/>'

class PGv2Request(PGv2):
    enabled = True
    content_type = 'request'
    schema = 'http://www.protogeni.net/resources/rspec/2/request.xsd'
    template = '<rspec type="request" xmlns="http://www.protogeni.net/resources/rspec/2" xmlns:flack="http://www.protogeni.net/resources/rspec/ext/flack/1" xmlns:plos="http://www.planet-lab.org/resources/sfa/ext/plos/1" xmlns:planetlab="http://www.planet-lab.org/resources/sfa/ext/planetlab/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.protogeni.net/resources/rspec/2 http://www.protogeni.net/resources/rspec/2/request.xsd http://www.planet-lab.org/resources/sfa/ext/planetlab/1 http://www.planet-lab.org/resources/sfa/ext/planetlab/1/planetlab.xsd http://www.planet-lab.org/resources/sfa/ext/plos/1 http://www.planet-lab.org/resources/sfa/ext/plos/1/plos.xsd"/>'

class PGv2Manifest(PGv2):
    enabled = True
    content_type = 'manifest'
    schema = 'http://www.protogeni.net/resources/rspec/2/manifest.xsd'
    template = '<rspec type="manifest" xmlns="http://www.protogeni.net/resources/rspec/2" xmlns:plos="http://www.planet-lab.org/resources/sfa/ext/plos/1" xmlns:flack="http://www.protogeni.net/resources/rspec/ext/flack/1" xmlns:planetlab="http://www.planet-lab.org/resources/sfa/ext/planetlab/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.protogeni.net/resources/rspec/2 http://www.protogeni.net/resources/rspec/2/manifest.xsd http://www.planet-lab.org/resources/sfa/ext/planetlab/1 http://www.planet-lab.org/resources/sfa/ext/planetlab/1/planetlab.xsd http://www.planet-lab.org/resources/sfa/ext/plos/1 http://www.planet-lab.org/resources/sfa/ext/plos/1/plos.xsd"/>'

     


if __name__ == '__main__':
    from sfa.rspecs.rspec import RSpec
    from sfa.rspecs.rspec_elements import *
    r = RSpec('/tmp/pg.rspec')
    r.load_rspec_elements(PGv2.elements)
    r.namespaces = PGv2.namespaces
    print r.get(RSpecElements.NODE)
Пример #29
0
    def build_sfa_rspec(self, slice_id, resources, properties, leases):
        """
        Build the XML RSpec from list of resources' urns.
        eg. resources = ["urn:publicid:IDN+ple:modenaple+node+planetlab-1.ing.unimo.it"]
        """
        #if isinstance(resources, str):
        #    resources = eval(resources)
        # rspec_type and rspec_version should be set in the config of the platform,
        # we use GENIv3 as default one if not
        if self.config:
            if 'rspec_type' and 'rspec_version' in self.config:
                rspec_version = self.config['rspec_type'] + ' ' + self.config[
                    'rspec_version']
        else:
            rspec_version = 'GENI 3'

        # extend rspec version with "content_type"
        rspec_version += ' request'

        rspec = RSpec(version=rspec_version)

        nodes = []
        channels = []
        links = []
        self._log.debug("Building RSpec for resources %s" % resources)
        cardinal = 0
        wilab = False
        for urn in resources:
            # XXX TO BE CORRECTED, this handles None values
            if not urn:
                continue
            self._log.debug(urn)
            resource = dict()
            # TODO: take into account the case where we send a dict of URNs without keys
            #resource['component_id'] = resource.pop('urn')
            resource['component_id'] = urn
            resource_hrn, resource_type = urn_to_hrn(resource['component_id'])
            # build component_manager_id
            top_auth = resource_hrn.split('.')[0]
            cm = urn.split("+")
            resource['component_manager_id'] = "%s+%s+authority+cm" % (
                cm[0], top_auth)

            if resource_type == 'node':
                # XXX dirty hack WiLab !!!
                #                Commented Lucia, doesn't work for wilabt
                #                if self.config:
                #                    if 'wilab2' in self.config['sm']:
                #                        resource['client_id'] = "PC"
                #                        resource['sliver_type'] = "raw-pc"
                if 'wilab2' in urn:
                    wilab = True
                    resource['client_id'] = "node%s" % cardinal
                    resource['sliver_type'] = "raw-pc"
                    resource['disk_image'] = "hola"
                    top_auth = resource_hrn.replace("\\", "").split('.')
                    top_auth.pop()
                    top_auth = '.'.join(top_auth)
                    cm = urn.split("+")
                    resource['component_manager_id'] = "%s+%s+authority+cm" % (
                        cm[0], top_auth)
                    cardinal += 1
                nodes.append(resource)
            elif resource_type == 'link':
                links.append(resource)
            elif resource_type == 'channel':
                channels.append(resource)
            else:
                raise Exception, "Not supported type of resource"

        rspec.version.add_nodes(nodes, rspec_content_type="request")
        #rspec.version.add_leases(leases)
        #rspec.version.add_links(links)
        #rspec.version.add_channels(channels)

        #self._log.debug("request rspec: %s"%rspec.toxml())
        string = rspec.toxml()
        if wilab and properties is not None:
            ## dirty hack for the f4f demo
            b = string.split('\n')
            for i, n in enumerate(b):
                if 'sliver_type name="raw-pc"' in n:
                    b[i] = '<sliver_type name="raw-pc">'
                    b.insert(
                        i + 1,
                        '<disk_image name="urn:publicid:IDN+wall2.ilabt.iminds.be+image+emulab-ops//%s"/>'
                        % properties['disk_image'])
                    #b.insert(i+1, '<disk_image name="urn:publicid:IDN+wilab2.ilabt.iminds.be+image+nepi:%s"/>' % properties['disk_image'])
                    b.insert(i + 2, '</sliver_type>')
            string = ''.join(b)
        self._log.debug("request rspec : %s" % string)
        return string
Пример #30
0
    def get_rspec(self,
                  slice_xrn=None,
                  login=None,
                  version=None,
                  options=None):
        """
        Returns xml rspec:
        - a full advertisement rspec with the testbed resources if slice_xrn is
        not specified.If a lease option is given, also returns the leases
        scheduled on the testbed.
        - a manifest Rspec with the leases and nodes in slice's leases if
        slice_xrn is not None.

        :param slice_xrn: srn of the slice
        :type slice_xrn: string
        :param login: user'uid (ldap login) on iotlab
        :type login: string
        :param version: can be set to sfa or iotlab
        :type version: RSpecVersion
        :param options: used to specify if the leases should also be included in
            the returned rspec.
        :type options: dict

        :returns: Xml Rspec.
        :rtype: XML


        """

        ldap_username = None
        rspec = None
        version_manager = VersionManager()
        version = version_manager.get_version(version)
        logger.debug("IotlabAggregate \t get_rspec ***version %s \
                    version.type %s  version.version %s options %s \r\n" %
                     (version, version.type, version.version, options))

        if slice_xrn is None:
            rspec_version = version_manager._get_version(
                version.type, version.version, 'ad')

        else:
            rspec_version = version_manager._get_version(
                version.type, version.version, 'manifest')

        slices, slivers = self.get_slice_and_slivers(slice_xrn, login)
        if slice_xrn and slices is not None:
            #Get user associated with this slice
            #for one_slice in slices :
            ldap_username = self.find_ldap_username_from_slice(slices[0])
            # ldap_username = slices[0]['reg_researchers'][0].__dict__['hrn']
            #  # ldap_username = slices[0]['user']
            # tmp = ldap_username.split('.')
            # ldap_username = tmp[1]
            logger.debug("IotlabAggregate \tget_rspec **** \
                    LDAP USERNAME %s \r\n" \
                    % (ldap_username))
        #at this point sliver may be empty if no iotlab job
        #is running for this user/slice.
        rspec = RSpec(version=rspec_version, user_options=options)

        logger.debug("\r\n \r\n IotlabAggregate \tget_rspec *** \
                      slice_xrn %s slices  %s\r\n \r\n" % (slice_xrn, slices))

        if options is not None:
            lease_option = options['list_leases']
        else:
            #If no options are specified, at least print the resources
            lease_option = 'all'
        #if slice_xrn :
        #lease_option = 'all'

        if lease_option in ['all', 'resources']:
            #if not options.get('list_leases') or options.get('list_leases')
            #and options['list_leases'] != 'leases':
            nodes = self.get_nodes()
            logger.debug("\r\n")
            logger.debug("IotlabAggregate \t lease_option %s \
                          get rspec  ******* nodes %s" % (lease_option, nodes))

            sites_set = set([node['location']['site'] for node in nodes])

            #In case creating a job,  slice_xrn is not set to None
            rspec.version.add_nodes(nodes)
            if slice_xrn and slices is not None:
                #     #Get user associated with this slice
                #     #for one_slice in slices :
                #     ldap_username = slices[0]['reg_researchers']
                #      # ldap_username = slices[0]['user']
                #     tmp = ldap_username.split('.')
                #     ldap_username = tmp[1]
                #      # ldap_username = tmp[1].split('_')[0]

                logger.debug("IotlabAggregate \tget_rspec **** \
                        version type %s ldap_ user %s \r\n" \
                        % (version.type, ldap_username))
                if version.type == "Iotlab":
                    rspec.version.add_connection_information(
                        ldap_username, sites_set)

            default_sliver = slivers.get('default_sliver', [])
            if default_sliver and len(nodes) is not 0:
                #default_sliver_attribs = default_sliver.get('tags', [])
                logger.debug("IotlabAggregate \tget_rspec **** \
                        default_sliver%s \r\n" % (default_sliver))
                for attrib in default_sliver:
                    rspec.version.add_default_sliver_attribute(
                        attrib, default_sliver[attrib])

        if lease_option in ['all', 'leases']:
            leases = self.get_all_leases(ldap_username)
            rspec.version.add_leases(leases)
            logger.debug("IotlabAggregate \tget_rspec **** \
                       FINAL RSPEC %s \r\n" % (rspec.toxml()))
        return rspec.toxml()
Пример #31
0
    def describe(self, urns, version=None, options=None):
        if options is None: options={}
        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(version.type, version.version, 'manifest')
        rspec = RSpec(version=rspec_version, user_options=options)

        # get slivers
        geni_slivers = []
        slivers = self.get_slivers(urns, options)
        if slivers:
            rspec_expires = datetime_to_string(utcparse(slivers[0]['expires']))
        else:
            rspec_expires = datetime_to_string(utcparse(time.time()))      
        rspec.xml.set('expires',  rspec_expires)

        # lookup the sliver allocations
        geni_urn = urns[0]
        sliver_ids = [sliver['sliver_id'] for sliver in slivers]
        constraint = SliverAllocation.sliver_id.in_(sliver_ids)
        sliver_allocations = self.driver.api.dbsession().query(SliverAllocation).filter(constraint)
        sliver_allocation_dict = {}
        for sliver_allocation in sliver_allocations:
            geni_urn = sliver_allocation.slice_urn
            sliver_allocation_dict[sliver_allocation.sliver_id] = sliver_allocation
      
        if not options.get('list_leases') or options['list_leases'] != 'leases':
            # add slivers
            site_ids = []
            interface_ids = []
            tag_ids = []
            nodes_dict = {}
            for sliver in slivers:
                site_ids.append(sliver['site_id'])
                interface_ids.extend(sliver['interface_ids'])
                tag_ids.extend(sliver['node_tag_ids'])
                nodes_dict[sliver['node_id']] = sliver
            sites = self.get_sites({'site_id': site_ids})
            interfaces = self.get_interfaces({'interface_id':interface_ids})
            node_tags = self.get_node_tags({'node_tag_id': tag_ids})
            pl_initscripts = self.get_pl_initscripts()
            rspec_nodes = []
            for sliver in slivers:
                if sliver['slice_ids_whitelist'] and sliver['slice_id'] not in sliver['slice_ids_whitelist']:
                    continue
                rspec_node = self.sliver_to_rspec_node(sliver, sites, interfaces, node_tags, 
                                                       pl_initscripts, sliver_allocation_dict)
                # manifest node element shouldn't contain available attribute
                rspec_node.pop('available')
                rspec_nodes.append(rspec_node) 
                geni_sliver = self.rspec_node_to_geni_sliver(rspec_node, sliver_allocation_dict)
                geni_slivers.append(geni_sliver)
            rspec.version.add_nodes(rspec_nodes)

            # add sliver defaults
            #default_sliver = slivers.get(None, [])
            #if default_sliver:
            #    default_sliver_attribs = default_sliver.get('tags', [])
            #    for attrib in default_sliver_attribs:
            #        rspec.version.add_default_sliver_attribute(attrib['tagname'], attrib['value'])

            # add links 
            links = self.get_links(sites, nodes_dict, interfaces)        
            rspec.version.add_links(links)

        if not options.get('list_leases') or options['list_leases'] != 'resources':
            if slivers:
                leases = self.get_leases(slivers[0])
                rspec.version.add_leases(leases)

               
        return {'geni_urn': geni_urn, 
                'geni_rspec': rspec.toxml(),
                'geni_slivers': geni_slivers}
Пример #32
0
command.prep()

if not command.opts.linkfile:
    print "Missing link list -- exiting"
    command.parser.print_help()
    sys.exit(1)

if command.opts.infile:
    infile = file(command.opts.infile)
else:
    infile = sys.stdin
if command.opts.outfile:
    outfile = file(command.opts.outfile, "w")
else:
    outfile = sys.stdout
ad_rspec = RSpec(infile)
links = file(command.opts.linkfile).read().split('\n')
link_tuples = map(lambda x: tuple(x.split()), links)

version_manager = VersionManager()
try:
    type = ad_rspec.version.type
    version_num = ad_rspec.version.version
    request_version = version_manager._get_version(type, version_num,
                                                   'request')
    request_rspec = RSpec(version=request_version)
    request_rspec.version.merge(ad_rspec)
    request_rspec.version.add_link_requests(link_tuples)
except:
    logger.log_exc("sfiAddLinks FAILED with links %s" % links)
    sys.exit(1)
Пример #33
0
logger.enable_console()
command = Commands(usage="%prog [options] [node1 node2...]",
                   description="Delete sliver attributes from the RSpec. " +
                   "This command reads in an RSpec and outputs a modified " +
                   "RSpec. Use this to remove attributes from nodes " +
                   "in your slice.  If no nodes are specified, the " +
                   "attributes will be removed from ALL nodes.",
                   epilog="NOTE: Only admins can actually set these " +
                   "attributes, with the exception of --delegations")
command.add_nodefile_option()
command.add_attribute_options()
command.prep()

if command.opts.infile:
    attrs = command.get_attribute_dict()
    rspec = RSpec(command.opts.infile)
    nodes = []
    if command.opts.nodefile:
        f = open(command.opts.nodefile, "r")
        nodes = f.read().split()
        f.close()

    for name in attrs:
        print >> sys.stderr, name, attrs[name]
        for value in attrs[name]:
            if not nodes:
                try:
                    rspec.version.remove_default_sliver_attribute(name, value)
                except:
                    logger.log_exc(
                        "sfiDeleteAttribute FAILED on all nodes: %s=%s" %
Пример #34
0
    template = '<rspec type="advertisement" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.protogeni.net/resources/rspec/2 https://github.com/fp7-ofelia/ocf/blob/ocf.rspecs/server_schema.xsd http://www.protogeni.net/resources/rspec/2/ad.xsd"/>'
    #template = '<rspec type="advertisement" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.protogeni.net/resources/rspec/2 /opt/ofelia/vt_manager/src/python/vt_manager/communication/sfa/tests/server_schema.xsd http://www.protogeni.net/resources/rspec/2/ad.xsd"/>'


class OcfVtRequest(OcfVt):
    enabled = True
    content_type = 'request'
    schema = 'https://github.com/fp7-ofelia/ocf/blob/ocf.rspecs/vm_schema.xsd'  #'/opt/ofelia/vt_manager/src/python/vt_manager/communication/sfa/tests/vm_schema.xsd'#'http://www.protogeni.net/resources/rspec/2/ad.xsd'
    template = '<rspec type="request" xmlns="http://www.protogeni.net/resources/rspec/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.protogeni.net/resources/rspec/2 https://github.com/fp7-ofelia/ocf/blob/ocf.rspecs/vm_schema.xsd http://www.protogeni.net/resources/rspec/2/ad.xsd "/>'
    #template = '<rspec type="request" xmlns="http://www.protogeni.net/resources/rspec/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.protogeni.net/resources/rspec/2 /opt/ofelia/vt_manager/src/python/vt_manager/communication/sfa/tests/vm_schema.xsd http://www.protogeni.net/resources/rspec/2/ad.xsd "/>'
    #schema = 'http://www.protogeni.net/resources/rspec/2/request.xsd'
    #template = '<rspec type="request" xmlns="http://www.protogeni.net/resources/rspec/2" xmlns:flack="http://www.protogeni.net/resources/rspec/ext/flack/1" xmlns:plos="http://www.planet-lab.org/resources/sfa/ext/plos/1" xmlns:planetlab="http://www.planet-lab.org/resources/sfa/ext/planetlab/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.protogeni.net/resources/rspec/2 http://www.protogeni.net/resources/rspec/2/request.xsd http://www.planet-lab.org/resources/sfa/ext/planetlab/1 http://www.planet-lab.org/resources/sfa/ext/planetlab/1/planetlab.xsd http://www.planet-lab.org/resources/sfa/ext/plos/1 http://www.planet-lab.org/resources/sfa/ext/plos/1/plos.xsd"/>'


class OcfVtManifest(OcfVt):
    enabled = True
    content_type = 'manifest'
    schema = 'https://github.com/fp7-ofelia/ocf/blob/ocf.rspecs/server_schema.xsd'  #'/opt/ofelia/vt_manager/src/python/vt_manager/communication/sfa/tests/server_schema.xsd'#'http://www.protogeni.net/resources/rspec/2/manifest.xsd'
    template = '<rspec type="manifest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.protogeni.net/resources/rspec/2 https://github.com/fp7-ofelia/ocf/blob/ocf.rspecs/server_schema.xsd http://www.protogeni.net/resources/rspec/2/ad.xsd"/>'
    #template = '<rspec type="manifest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.protogeni.net/resources/rspec/2 /opt/ofelia/vt_manager/src/python/vt_manager/communication/sfa/tests/server_schema.xsd http://www.protogeni.net/resources/rspec/2/ad.xsd"/>'


#    template = '<rspec type="manifest" xmlns="http://www.protogeni.net/resources/rspec/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.protogeni.net/resources/rspec/2 /opt/ofelia/vt_manager/src/python/vt_manager/communication/sfa/tests/server_schema.xsd http://www.protogeni.net/resources/rspec/2/ad.xsd"/>'

if __name__ == '__main__':
    from vt_manager.communication.sfa.rspecs.rspec import RSpec
    from vt_manager.communication.sfa.rspecs.rspec_elements import *
    r = RSpec('/tmp/ocf.rspec')
    r.load_rspec_elements(OcfVt.elements)
    print r.get(RSpecElements.NODE)
Пример #35
0
    enabled = True
    content_type = 'ad'
    schema = 'http://senslab.info/resources/rspec/1/ad.xsd'
    #http://www.geni.net/resources/rspec/3/ad.xsd'
    template = '<rspec type="advertisement" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://senslab.info/resources/rspec/1" xmlns:flack="http://senslab.info/resources/rspec/ext/flack/1" xmlns:planetlab="http://www.planet-lab.org/resources/sfa/ext/planetlab/1" xsi:schemaLocation="http://senslab.info/resources/rspec/1 http://senslab.info/resources/rspec/1/ad.xsd http://www.planet-lab.org/resources/sfa/ext/planetlab/1 http://www.planet-lab.org/resources/sfa/ext/planetlab/1/planetlab.xsd"/>'


class Iotlabv1Request(Iotlabv1):
    enabled = True
    content_type = 'request'
    schema = 'http://senslab.info/resources/rspec/1/request.xsd'
    #http://www.geni.net/resources/rspec/3/request.xsd
    template = '<rspec type="request" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://senslab.info/resources/rspec/1" xmlns:flack="http://senslab.info/resources/rspec/ext/flack/1" xmlns:planetlab="http://www.planet-lab.org/resources/sfa/ext/planetlab/1" xsi:schemaLocation="http://senslab.info/resources/rspec/1 http://senslab.info/resources/rspec/1/request.xsd http://www.planet-lab.org/resources/sfa/ext/planetlab/1 http://www.planet-lab.org/resources/sfa/ext/planetlab/1/planetlab.xsd"/>'


class Iotlabv1Manifest(Iotlabv1):
    enabled = True
    content_type = 'manifest'
    schema = 'http://senslab.info/resources/rspec/1/manifest.xsd'
    #http://www.geni.net/resources/rspec/3/manifest.xsd
    template = '<rspec type="manifest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://senslab.info/resources/rspec/1" xmlns:flack="http://senslab.info/resources/rspec/ext/flack/1" xmlns:planetlab="http://www.planet-lab.org/resources/sfa/ext/planetlab/1" xsi:schemaLocation="http://senslab.info/resources/rspec/1 http://senslab.info/resources/rspec/1/manifest.xsd http://www.planet-lab.org/resources/sfa/ext/planetlab/1 http://www.planet-lab.org/resources/sfa/ext/planetlab/1/planetlab.xsd"/>'


if __name__ == '__main__':
    from sfa.rspecs.rspec import RSpec
    from sfa.rspecs.rspec_elements import *
    r = RSpec('/tmp/iotlab.rspec')
    r.load_rspec_elements(Iotlabv1.elements)
    r.namespaces = Iotlabv1.namespaces
    print r.get(RSpecElements.NODE)
Пример #36
0
class Iotlabv1Ad(Iotlabv1):
    enabled = True
    content_type = 'ad'
    schema = 'http://senslab.info/resources/rspec/1/ad.xsd'
    #http://www.geni.net/resources/rspec/3/ad.xsd'
    template = '<rspec type="advertisement" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://senslab.info/resources/rspec/1" xmlns:flack="http://senslab.info/resources/rspec/ext/flack/1" xmlns:planetlab="http://www.planet-lab.org/resources/sfa/ext/planetlab/1" xsi:schemaLocation="http://senslab.info/resources/rspec/1 http://senslab.info/resources/rspec/1/ad.xsd http://www.planet-lab.org/resources/sfa/ext/planetlab/1 http://www.planet-lab.org/resources/sfa/ext/planetlab/1/planetlab.xsd"/>'

class Iotlabv1Request(Iotlabv1):
    enabled = True
    content_type = 'request'
    schema = 'http://senslab.info/resources/rspec/1/request.xsd'
    #http://www.geni.net/resources/rspec/3/request.xsd
    template = '<rspec type="request" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://senslab.info/resources/rspec/1" xmlns:flack="http://senslab.info/resources/rspec/ext/flack/1" xmlns:planetlab="http://www.planet-lab.org/resources/sfa/ext/planetlab/1" xsi:schemaLocation="http://senslab.info/resources/rspec/1 http://senslab.info/resources/rspec/1/request.xsd http://www.planet-lab.org/resources/sfa/ext/planetlab/1 http://www.planet-lab.org/resources/sfa/ext/planetlab/1/planetlab.xsd"/>'

class Iotlabv1Manifest(Iotlabv1):
    enabled = True
    content_type = 'manifest'
    schema = 'http://senslab.info/resources/rspec/1/manifest.xsd'
    #http://www.geni.net/resources/rspec/3/manifest.xsd
    template = '<rspec type="manifest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://senslab.info/resources/rspec/1" xmlns:flack="http://senslab.info/resources/rspec/ext/flack/1" xmlns:planetlab="http://www.planet-lab.org/resources/sfa/ext/planetlab/1" xsi:schemaLocation="http://senslab.info/resources/rspec/1 http://senslab.info/resources/rspec/1/manifest.xsd http://www.planet-lab.org/resources/sfa/ext/planetlab/1 http://www.planet-lab.org/resources/sfa/ext/planetlab/1/planetlab.xsd"/>'


if __name__ == '__main__':
    from sfa.rspecs.rspec import RSpec
    from sfa.rspecs.rspec_elements import *
    r = RSpec('/tmp/iotlab.rspec')
    r.load_rspec_elements(Iotlabv1.elements)
    r.namespaces = Iotlabv1.namespaces
    print r.get(RSpecElements.NODE)
Пример #37
0
    def describe(self, urns, version=None, options={}):
        version_manager = VersionManager()
        version = version_manager.get_version(version)
        rspec_version = version_manager._get_version(version.type,
                                                     version.version,
                                                     'manifest')
        rspec = RSpec(version=rspec_version, user_options=options)

        # get slivers
        geni_slivers = []
        slivers = self.get_slivers(urns, options)
        if slivers:
            rspec_expires = datetime_to_string(utcparse(slivers[0]['expires']))
        else:
            rspec_expires = datetime_to_string(utcparse(time.time()))
        rspec.xml.set('expires', rspec_expires)

        # lookup the sliver allocations
        geni_urn = urns[0]
        sliver_ids = [sliver['sliver_id'] for sliver in slivers]
        constraint = SliverAllocation.sliver_id.in_(sliver_ids)
        sliver_allocations = self.driver.api.dbsession().query(
            SliverAllocation).filter(constraint)
        sliver_allocation_dict = {}
        for sliver_allocation in sliver_allocations:
            geni_urn = sliver_allocation.slice_urn
            sliver_allocation_dict[
                sliver_allocation.sliver_id] = sliver_allocation

        if not options.get(
                'list_leases') or options['list_leases'] != 'leases':
            # add slivers
            site_ids = []
            interface_ids = []
            tag_ids = []
            nodes_dict = {}
            for sliver in slivers:
                site_ids.append(sliver['site_id'])
                interface_ids.extend(sliver['interface_ids'])
                tag_ids.extend(sliver['node_tag_ids'])
                nodes_dict[sliver['node_id']] = sliver
            sites = self.get_sites({'site_id': site_ids})
            interfaces = self.get_interfaces({'interface_id': interface_ids})
            node_tags = self.get_node_tags({'node_tag_id': tag_ids})
            pl_initscripts = self.get_pl_initscripts()
            rspec_nodes = []
            for sliver in slivers:
                if sliver['slice_ids_whitelist'] and sliver[
                        'slice_id'] not in sliver['slice_ids_whitelist']:
                    continue
                rspec_node = self.sliver_to_rspec_node(sliver, sites,
                                                       interfaces, node_tags,
                                                       pl_initscripts,
                                                       sliver_allocation_dict)
                # manifest node element shouldn't contain available attribute
                rspec_node.pop('available')
                rspec_nodes.append(rspec_node)
                geni_sliver = self.rspec_node_to_geni_sliver(
                    rspec_node, sliver_allocation_dict)
                geni_slivers.append(geni_sliver)
            rspec.version.add_nodes(rspec_nodes)

            # add sliver defaults
            #default_sliver = slivers.get(None, [])
            #if default_sliver:
            #    default_sliver_attribs = default_sliver.get('tags', [])
            #    for attrib in default_sliver_attribs:
            #        rspec.version.add_default_sliver_attribute(attrib['tagname'], attrib['value'])

            # add links
            links = self.get_links(sites, nodes_dict, interfaces)
            rspec.version.add_links(links)

        if not options.get(
                'list_leases') or options['list_leases'] != 'resources':
            if slivers:
                leases = self.get_leases(slivers[0])
                rspec.version.add_leases(leases)

        return {
            'geni_urn': geni_urn,
            'geni_rspec': rspec.toxml(),
            'geni_slivers': geni_slivers
        }
Пример #38
0
         if caller_hrn == aggregate and aggregate != api.hrn:
             continue
 
         # get the rspec from the aggregate
         interface = api.aggregates[aggregate]
         server = api.server_proxy(interface, cred)
         multiclient.run(_ListResources, aggregate, server, [cred], options)
 
 
     results = multiclient.get_results()
     rspec_version = version_manager.get_version(options.get('geni_rspec_version'))
     if xrn:    
         result_version = version_manager._get_version(rspec_version.type, rspec_version.version, 'manifest')
     else: 
         result_version = version_manager._get_version(rspec_version.type, rspec_version.version, 'ad')
     rspec = RSpec(version=result_version)
     for result in results:
         self.add_slicemgr_stat(rspec, "ListResources", result["aggregate"], result["elapsed"], 
                                result["status"], result.get("exc_info",None))
         if result["status"]=="success":
             res = result['result']['value']
             try:
                 rspec.version.merge(ReturnValue.get_value(res))
             except:
                 api.logger.log_exc("SM.ListResources: Failed to merge aggregate rspec")
 
     # cache the result
     if self.cache and not xrn:
         api.logger.debug("SliceManager.ListResources caches advertisement")
         self.cache.add(version_string, rspec.toxml())
 
Пример #39
0
    def Allocate(self, api, xrn, creds, rspec_str, expiration, options):
        call_id = options.get('call_id')
        if Callids().already_handled(call_id): return ""
    
        version_manager = VersionManager()
        def _Allocate(aggregate, server, xrn, credential, rspec, options):
            tStart = time.time()
            try:
                # Need to call GetVersion at an aggregate to determine the supported
                # rspec type/format beofre calling CreateSliver at an Aggregate.
                #server_version = api.get_cached_server_version(server)
                #if 'sfa' not in server_version and 'geni_api' in server_version:
                    # sfa aggregtes support both sfa and pg rspecs, no need to convert
                    # if aggregate supports sfa rspecs. otherwise convert to pg rspec
                    #rspec = RSpec(RSpecConverter.to_pg_rspec(rspec, 'request'))
                    #filter = {'component_manager_id': server_version['urn']}
                    #rspec.filter(filter)
                    #rspec = rspec.toxml()
                result = server.Allocate(xrn, credential, rspec, options)
                return {"aggregate": aggregate, "result": result, "elapsed": time.time()-tStart, "status": "success"}
            except:
                logger.log_exc('Something wrong in _Allocate with URL %s'%server.url)
                return {"aggregate": aggregate, "elapsed": time.time()-tStart, "status": "exception", "exc_info": sys.exc_info()}

        # Validate the RSpec against PlanetLab's schema --disabled for now
        # The schema used here needs to aggregate the PL and VINI schemas
        # schema = "/var/www/html/schemas/pl.rng"
        rspec = RSpec(rspec_str)
    #    schema = None
    #    if schema:
    #        rspec.validate(schema)
    
        # if there is a <statistics> section, the aggregates don't care about it,
        # so delete it.
        self.drop_slicemgr_stats(rspec)
    
        # attempt to use delegated credential first
        cred = api.getDelegatedCredential(creds)
        if not cred:
            cred = api.getCredential()
    
        # get the callers hrn
        hrn, type = urn_to_hrn(xrn)
        valid_cred = api.auth.checkCredentials(creds, 'createsliver', hrn)[0]
        caller_hrn = Credential(cred=valid_cred).get_gid_caller().get_hrn()
        multiclient = MultiClient()
        for aggregate in api.aggregates:
            # prevent infinite loop. Dont send request back to caller
            # unless the caller is the aggregate's SM 
            if caller_hrn == aggregate and aggregate != api.hrn:
                continue
            interface = api.aggregates[aggregate]
            server = api.server_proxy(interface, cred)
            # Just send entire RSpec to each aggregate
            multiclient.run(_Allocate, aggregate, server, xrn, [cred], rspec.toxml(), options)
                
        results = multiclient.get_results()
        manifest_version = version_manager._get_version(rspec.version.type, rspec.version.version, 'manifest')
        result_rspec = RSpec(version=manifest_version)
        geni_urn = None
        geni_slivers = []

        for result in results:
            self.add_slicemgr_stat(result_rspec, "Allocate", result["aggregate"], result["elapsed"], 
                                   result["status"], result.get("exc_info",None))
            if result["status"]=="success":
                try:
                    res = result['result']['value']
                    geni_urn = res['geni_urn']
                    result_rspec.version.merge(ReturnValue.get_value(res['geni_rspec']))
                    geni_slivers.extend(res['geni_slivers'])
                except:
                    api.logger.log_exc("SM.Allocate: Failed to merge aggregate rspec")
        return {
            'geni_urn': geni_urn,
            'geni_rspec': result_rspec.toxml(),
            'geni_slivers': geni_slivers
        }
Пример #40
0
        networks = rspec.version.get_networks()
        for network in networks:
            current_network = network.get('name')
            if current_network and current_network not in current_networks:
                self.xml.append(network.element)
                current_networks.append(current_network)

    # Leases

    def get_leases(self, filter=None):
        return SFAv1Lease.get_leases(self.xml, filter)

    def add_leases(self, leases, network=None, no_dupes=False):
        SFAv1Lease.add_leases(self.xml, leases)

    # Spectrum

    def get_channels(self, filter=None):
        return []

    def add_channels(self, channels, network=None, no_dupes=False):
        pass


if __name__ == '__main__':
    from sfa.rspecs.rspec import RSpec
    from sfa.rspecs.rspec_elements import *
    r = RSpec('/tmp/resources.rspec')
    r.load_rspec_elements(SFAv1.elements)
    print r.get(RSpecElements.NODE)
Пример #41
0
        if self.type in ['request', 'manifest']:
            # remove 'available' element from remaining node elements
            self.xml.remove_element('//default:available | //available')

class OcfOfAd(OcfOf):
    enabled = True
    content_type = 'ad'
    schema ='https://github.com/fp7-ofelia/ocf/blob/ocf.rspecs/openflow/schemas/ad.xsd'
    template = '<rspec type="advertisement" xmlns="https://github.com/fp7-ofelia/ocf/tree/ocf.rspecs/openflow/schemas" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xmlns:openflow="https://github.com/fp7-ofelia/ocf/blob/ocf.rspecs/openflow/schemas" xs:schemaLocation="https://github.com/fp7-ofelia/ocf/blob/ocf.rspecs/openflow/schemas/ https://github.com/fp7-ofelia/ocf/blob/ocf.rspecs/openflow/schemas/ad.xsd  http://www.geni.net/resources/rspec/3/ad.xsd https://github.com/fp7-ofelia/ocf/blob/ocf.rspecs/openflow/schemas/ad.xsd http://www.geni.net/resources/rspec/ext/openflow/3/of-ad.xsd https://github.com/fp7-ofelia/ocf/blob/ocf.rspecs/openflow/schemas/network_schema.xsd" />'

class OcfOfRequest(OcfOf):
    enabled = True
    content_type = 'request'
    schema = 'http://www.geni.net/resources/rspec/3/request.xsd'
    template = '<rspec xmlns="http://www.geni.net/resources/rspec/3" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xmlns:openflow="http://www.geni.net/resources/rspec/ext/openflow/3" xs:schemaLocation="http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/request.xsd http://www.geni.net/resources/rspec/ext/openflow/3 http://www.geni.net/resources/rspec/ext/openflow/3/of-resv.xsd https://github.com/fp7-ofelia/ocf/blob/ocf.rspecs/openflow/schemas/network_schema.xsd" type="request" />'

class OcfOfManifest(OcfOf):
    enabled = True
    content_type = 'manifest'
    schema = 'https://github.com/fp7-ofelia/ocf/blob/ocf.rspecs/openflow/schemas/manifest.xsd'
    template = '<rspec type="manifest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.protogeni.net/resources/rspec/2 https://github.com/fp7-ofelia/ocf/blob/ocf.rspecs/openflow/schemas/manifest.xsd http://www.protogeni.net/resources/rspec/2/ad.xsd https://github.com/fp7-ofelia/ocf/blob/ocf.rspecs/openflow/schemas/network_schema.xsd"/>'
     


if __name__ == '__main__':
    from openflow.optin_manager.sfa.rspecs.rspec import RSpec
    from openflow.optin_manager.sfa.rspecs.rspec_elements import *
    r = RSpec('/tmp/ocf.rspec')
    r.load_rspec_elements(OcfOf.elements)
    print r.get(RSpecElements.NODE)
Пример #42
0
    def build_rspec(cls, slice_urn, resources, leases, flowspace, vms, rspec_version='GENI 3 request'):
        """
        Builds a RSpecs based on the specified resources and leases.

        Args:
            slice_urn (string) : the urn of the slice [UNUSED] [HRN in NITOS ?]

        Returns:
            string : the string version of the created RSpec.
        """
        rspec = RSpec(version=rspec_version)

        nodes = []
        channels = []
        links = []

        # XXX Here it is only about mappings and hooks between ontologies

        for urn in resources:
            # XXX TO BE CORRECTED, this handles None values
            if not urn:
                continue
            resource = dict()
            # TODO: take into account the case where we send a dict of URNs without keys
            #resource['component_id'] = resource.pop('urn')
            resource['component_id'] = urn
            resource_hrn, resource_type = urn_to_hrn(urn) # resource['component_id'])
            # build component_manager_id
            top_auth = resource_hrn.split('.')[0]
            cm = urn.split("+")
            resource['component_manager_id'] = "%s+%s+authority+cm" % (cm[0],top_auth)

            #print "resource_type", resource_type
            if resource_type == 'node':
                #print "NODE", resource, cls
                resource = cls.on_build_resource_hook(resource)
                nodes.append(resource)
            elif resource_type == 'link':
                links.append(resource)
            elif resource_type == 'channel':
                channels.append(resource)
            else:
                raise Exception, "Not supported type of resource" 

        #for node in nodes:
        #    print "NODE:", node

        rspec.version.add_nodes(nodes, rspec_content_type="request")

        #rspec.version.add_links(links)
        #rspec.version.add_channels(channels)

        sfa_leases = cls.manifold_to_sfa_leases(leases, slice_urn)
        #print "sfa_leases", sfa_leases
        if sfa_leases:
            # SFAWRAP BUG ???
            # rspec.version.add_leases bugs with an empty set of leases
            # slice_id = leases[0]['slice_id']
            # TypeError: list indices must be integers, not str
            rspec.version.add_leases(sfa_leases, []) # XXX Empty channels for now
   
        return rspec.toxml()
Пример #43
0
        def func(*args, **kwds):
            if name == "list_resources":
                (version, options) = args
                slice_urn = slice_hrn = None
                creds = []
                rspec = getattr(self.driver,
                                "list_resources")(slice_urn, slice_hrn, [],
                                                  options)
                result = rspec

            elif name == "describe":
                (urns, version, options) = args
                slice_urn = urns[0]
                slice_hrn, type = urn_to_hrn(slice_urn)
                creds = []
                rspec = getattr(self.driver,
                                "list_resources")(slice_urn, slice_hrn, creds,
                                                  options)

                # SliverAllocation
                if len(urns) == 1 and Xrn(xrn=urns[0]).type == 'slice':
                    constraint = SliverAllocation.slice_urn.in_(urns)
                else:
                    constraint = SliverAllocation.sliver_id.in_(urns)

                sliver_allocations = self.driver.api.dbsession().query(
                    SliverAllocation).filter(constraint)
                sliver_status = getattr(self.driver,
                                        "sliver_status")(slice_urn, slice_hrn)
                if 'geni_expires' in sliver_status.keys():
                    geni_expires = sliver_status['geni_expires']
                else:
                    geni_expires = ''

                geni_slivers = []
                for sliver_allocation in sliver_allocations:
                    geni_sliver = {}
                    geni_sliver['geni_expires'] = geni_expires
                    geni_sliver[
                        'geni_allocation'] = sliver_allocation.allocation_state
                    geni_sliver[
                        'geni_sliver_urn'] = sliver_allocation.sliver_id
                    geni_sliver['geni_error'] = ''
                    if geni_sliver['geni_allocation'] == 'geni_allocated':
                        geni_sliver[
                            'geni_operational_status'] = 'geni_pending_allocation'
                    else:
                        geni_sliver['geni_operational_status'] = 'geni_ready'
                    geni_slivers.append(geni_sliver)

                result = {
                    'geni_urn': slice_urn,
                    'geni_rspec': rspec,
                    'geni_slivers': geni_slivers
                }

            elif name == "allocate":
                (slice_urn, rspec_string, expiration, options) = args
                slice_hrn, type = urn_to_hrn(slice_urn)
                creds = []
                users = options.get('sfa_users', [])
                manifest_string = getattr(self.driver,
                                          "create_sliver")(slice_urn,
                                                           slice_hrn, creds,
                                                           rspec_string, users,
                                                           options)

                # slivers allocation
                rspec = RSpec(manifest_string)
                slivers = rspec.version.get_nodes_with_slivers()

                ##SliverAllocation
                for sliver in slivers:
                    client_id = sliver['client_id']
                    component_id = sliver['component_id']
                    component_name = sliver['component_name']
                    slice_name = slice_hrn.replace('.', '-')
                    component_short_name = component_name.split('.')[0]
                    # self.driver.hrn
                    sliver_hrn = '%s.%s-%s' % (self.driver.hrn, slice_name,
                                               component_short_name)
                    sliver_id = Xrn(sliver_hrn, type='sliver').urn
                    record = SliverAllocation(
                        sliver_id=sliver_id,
                        client_id=client_id,
                        component_id=component_id,
                        slice_urn=slice_urn,
                        allocation_state='geni_allocated')

                    record.sync()

                # return manifest
                rspec_version = RSpec(rspec_string).version
                rspec_version_str = "%s" % rspec_version
                options['geni_rspec_version'] = {
                    'version': rspec_version_str.split(' ')[1],
                    'type': rspec_version_str.lower().split(' ')[0]
                }
                result = self.describe([slice_urn], rspec_version, options)

            elif name == "provision":
                (urns, options) = args
                if len(urns) == 1 and Xrn(xrn=urns[0]).type == 'slice':
                    constraint = SliverAllocation.slice_urn.in_(urns)
                else:
                    constraint = SliverAllocation.sliver_id.in_(urns)

                dbsession = self.driver.api.dbsession()
                sliver_allocations = dbsession.query(SliverAllocation).filter(
                    constraint)
                for sliver_allocation in sliver_allocations:
                    sliver_allocation.allocation_state = 'geni_provisioned'

                dbsession.commit()
                result = self.describe(urns, '', options)

            elif name == "status":
                urns = args
                options = {}
                options['geni_rspec_version'] = {
                    'version': '3',
                    'type': 'GENI'
                }
                descr = self.describe(urns[0], '', options)
                result = {
                    'geni_urn': descr['geni_urn'],
                    'geni_slivers': descr['geni_slivers']
                }

            elif name == "delete":
                (urns, options) = args
                slice_urn = urns[0]
                slice_hrn, type = urn_to_hrn(slice_urn)
                creds = []
                options['geni_rspec_version'] = {
                    'version': '3',
                    'type': 'GENI'
                }
                descr = self.describe(urns, '', options)
                result = []
                for sliver_allocation in descr['geni_slivers']:
                    geni_sliver = {
                        'geni_sliver_urn':
                        sliver_allocation['geni_sliver_urn'],
                        'geni_allocation_status': 'geni_unallocated',
                        'geni_expires': sliver_allocation['geni_expires'],
                        'geni_error': sliver_allocation['geni_error']
                    }

                    result.append(geni_sliver)

                getattr(self.driver, "delete_sliver")(slice_urn, slice_hrn,
                                                      creds, options)

                #SliverAllocation
                constraints = SliverAllocation.slice_urn.in_(urns)
                dbsession = self.driver.api.dbsession()
                sliver_allocations = dbsession.query(SliverAllocation).filter(
                    constraints)
                sliver_ids = [
                    sliver_allocation.sliver_id
                    for sliver_allocation in sliver_allocations
                ]
                SliverAllocation.delete_allocations(sliver_ids, dbsession)

            elif name == "renew":
                (urns, expiration_time, options) = args
                slice_urn = urns[0]
                slice_hrn, type = urn_to_hrn(slice_urn)
                creds = []

                getattr(self.driver,
                        "renew_sliver")(slice_urn, slice_hrn, creds,
                                        expiration_time, options)

                options['geni_rspec_version'] = {
                    'version': '3',
                    'type': 'GENI'
                }
                descr = self.describe(urns, '', options)
                result = descr['geni_slivers']

            elif name == "perform_operational_action":
                (urns, action, options) = args
                options['geni_rspec_version'] = {
                    'version': '3',
                    'type': 'GENI'
                }
                result = self.describe(urns, '', options)['geni_slivers']

            else:
                # same as v2 ( registry methods)
                result = getattr(self.driver, name)(*args, **kwds)
            return result
Пример #44
0
        if rspec.version.type.lower() == 'protogeni':
            from sfa.rspecs.rspec_converter import RSpecConverter
            in_rspec = RSpecConverter.to_sfa_rspec(rspec.toxml())
            rspec = RSpec(in_rspec)

        # just copy over all networks
        current_networks = self.get_networks()
        networks = rspec.version.get_networks()
        for network in networks:
            current_network = network.get('name')
            if current_network and current_network not in current_networks:
                self.xml.append(network.element)
                current_networks.append(current_network)

if __name__ == '__main__':
    import sys
    import pprint
    from sfa.rspecs.rspec import RSpec
    from sfa.rspecs.rspec_elements import *
    print "main ofeliav1"
    if len(sys.argv) != 2:
        r = RSpec('/tmp/resources.rspec')
    else:
        r = RSpec(sys.argv[1], version='OFELIA 1')
    #print r.version.get_datapaths()
    resources = r.version.get_resources()
    pprint.pprint(resources)

    #r.load_rspec_elements(SFAv1.elements)
    #print r.get(RSpecElements.NODE)
Пример #45
0
import sys

from sfa.util.sfalogging import logger
from sfa.client.sfi_commands import Commands
from sfa.rspecs.rspec import RSpec

logger.enable_console()
command = Commands(usage="%prog [options] node1 node2...",
                   description="Delete slivers from the RSpec. " +
                   "This command reads in an RSpec and outputs a modified " +
                   "RSpec. Use this to remove nodes from your slice.")
command.add_nodefile_option()
command.prep()

if command.opts.infile:
    rspec = RSpec(command.opts.infile)
    nodes = []
    if command.opts.nodefile:
        f = open(command.opts.nodefile, "r")
        nodes = f.read().split()
        f.close()
       
    try:
        slivers = [{'hostname': node} for node in nodes]
        rspec.version.remove_slivers(slivers)
        print rspec.toxml()
    except:
        logger.log_exc("sfiDeleteSliver FAILED with nodes %s" % nodes)

    
Пример #46
0
                sliver = {}
            elif 'component_id' in sliver and sliver['component_id']:
                filter['component_id'] = '*%s*' % sliver['component_id']
            if not filter:
                continue
            nodes = PGv2Node.get_nodes(xml, filter)
            if not nodes:
                continue
            node = nodes[0]
            PGv2SliverType.add_slivers(node, sliver)

    @staticmethod
    def remove_slivers(xml, hostnames):
        for hostname in hostnames:
            nodes = PGv2Node.get_nodes(xml,
                                       {'component_id': '*%s*' % hostname})
            for node in nodes:
                slivers = PGv2SliverType.get_slivers(node.element)
                for sliver in slivers:
                    node.element.remove(sliver.element)


if __name__ == '__main__':
    from sfa.rspecs.rspec import RSpec
    import pdb
    r = RSpec('/tmp/emulab.rspec')
    r2 = RSpec(version='ProtoGENI')
    nodes = PGv2Node.get_nodes(r.xml)
    PGv2Node.add_nodes(r2.xml.root, nodes)
    #pdb.set_trace()