当前位置: 首页>>代码示例>>Python>>正文


Python rspec.RSpec类代码示例

本文整理汇总了Python中sfa.rspecs.rspec.RSpec的典型用法代码示例。如果您正苦于以下问题:Python RSpec类的具体用法?Python RSpec怎么用?Python RSpec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了RSpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_rspec

    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()
开发者ID:tubav,项目名称:sfa,代码行数:25,代码来源:dummyaggregate.py

示例2: merge

    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)
开发者ID:aquila,项目名称:sfa,代码行数:26,代码来源:ofeliav1.py

示例3: create_sliver

    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()
开发者ID:tubav,项目名称:sfa,代码行数:29,代码来源:nova_driver.py

示例4: describe

    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
开发者ID:aquila,项目名称:sfa,代码行数:30,代码来源:osaggregate.py

示例5: describe

    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
开发者ID:kongseokhwan,项目名称:sfa,代码行数:32,代码来源:osaggregate.py

示例6: list_resources

    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 ]
开发者ID:tubav,项目名称:teagle,代码行数:28,代码来源:SFAPNode.py

示例7: Provision

    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
        }            
开发者ID:BeomJun92,项目名称:sfawrap,代码行数:59,代码来源:slice_manager.py

示例8: list_resources

 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()
开发者ID:aquila,项目名称:sfa,代码行数:8,代码来源:osaggregate.py

示例9: list_resources

    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()
开发者ID:nfvproject,项目名称:SFA,代码行数:54,代码来源:iotlabaggregate.py

示例10: get_rspec

 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()
开发者ID:tubav,项目名称:sfa,代码行数:12,代码来源:osaggregate.py

示例11: to_sfa_rspec

    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()
开发者ID:aquila,项目名称:sfa,代码行数:53,代码来源:pg_rspec_converter.py

示例12: create

    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
开发者ID:planetlab,项目名称:sfa,代码行数:46,代码来源:sfi.py

示例13: _CreateSliver

 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()}
开发者ID:tubav,项目名称:sfa,代码行数:20,代码来源:slice_manager.py

示例14: Describe

    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
        }  
开发者ID:aquila,项目名称:sfa,代码行数:41,代码来源:slice_manager.py

示例15: to_sfa_rspec

    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()
开发者ID:planetlab,项目名称:sfa,代码行数:41,代码来源:pg_rspec_converter.py


注:本文中的sfa.rspecs.rspec.RSpec类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。