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


Python RSpec.filter方法代码示例

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


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

示例1: create

# 需要导入模块: from sfa.rspecs.rspec import RSpec [as 别名]
# 或者: from sfa.rspecs.rspec.RSpec import filter [as 别名]
    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,代码行数:48,代码来源:sfi.py

示例2: _CreateSliver

# 需要导入模块: from sfa.rspecs.rspec import RSpec [as 别名]
# 或者: from sfa.rspecs.rspec.RSpec import filter [as 别名]
 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,代码行数:22,代码来源:slice_manager.py

示例3: add_resource

# 需要导入模块: from sfa.rspecs.rspec import RSpec [as 别名]
# 或者: from sfa.rspecs.rspec.RSpec import filter [as 别名]
    def add_resource(self, parent_id, name, typename, config, owner = None):
        if not parent_id:
            raise ValueError("Need a parent")
        
        #Creating a new SFI client object
#        sfi = Sfi()
#        sfi.read_config()
#        sfi.bootstrap()
#        credentials = [ sfi.my_credential_string ]
#        bootstrap = sfi.bootstrap.server_proxy(sfi.sm_url)
        
        #Create new options
        version_dict = {'type':'SFA', 'version':'1','schema':None,'namespace':None,'extensions':[]}
        options = {}
        options[ 'geni_rspec_version' ]  = version_dict
           
        #Getting the configuration paramter of the parent resource, in this case an RSpec
        parent = self.__manager.get_resource(parent_id)
        pconfig = parent.get_configuration()
        rspec = pconfig['xmlRspec']
        logger.debug('RSpec of the parent %s'%rspec)

        #Saving the hostname of the parent in order to retrieve the slice later
        hostname = self.fetch_tag(rspec,'hostname')
        logger.debug('Saved the hostname %s'%hostname)        

        #Getting the vctname and creating the slice_hrn        
        slice_hrn = 'raven.fts.%s' %config['vctname']
        slice_urn = hrn_to_urn(slice_hrn, 'slice')
        logger.info('Creating or updating a slice with the name %s'%slice_hrn)

        #Preparing the server_proxy object and getting the server version
        result = self.__bootstrap.GetVersion()
        server_version= ReturnValue.get_value(result)
        logger.debug('Received server version %s'%server_version)	


        #Creating the slice record dict or string
        #recorddict = dict({'hrn': slice_hrn,
        #'url': 'http://planet-lab.org',
        #'type': 'slice',
        #'researcher': ['teagle.teagle.teagle'],
        #'description': 'Teagle slice'})
        slice_str = '<record description="Teagle Slice4" hrn="%s" type="slice" url="http://planet-lab.org"><researcher>teagle.teagle.teagle</researcher></record>' %slice_hrn
        slicerecord = SfaRecord(string = slice_str).as_dict()
        logger.debug('Prepared a slice record to add to the registry %s'%slice_str)
 
        
        #Retrieving the credential of the authority
        auth_cred = self.__sfi.bootstrap.authority_credential_string (self.__sfi.authority)
        #auth_cred = sfi.bootstrap.authority_credential_string (sfi.authority)
        logger.debug('Authority %s credentials %s'%(self.__sfi.authority, auth_cred,))
        #logger.debug('Authority %s credentials %s'%(sfi.authority, auth_cred,))

        #Trying to create the slice
        try:
            records = self.registry().Register(slicerecord, auth_cred)
            #records = self.registry(sfi).Register(slicerecord, auth_cred)
        except ServerException:
            logger.debug("Slice already existing")
            pass
        
        #Saving the slice credential
        creds = [self.__sfi.slice_credential_string(slice_hrn)]
        #creds = [sfi.slice_credential_string(slice_hrn)]
        logger.debug('The slice credential: %s'%creds)
        
        
        # users
        # 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, [self.__sfi.my_credential_string])
        #slice_records = self.registry(sfi).Resolve(slice_urn, [sfi.my_credential_string])
        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, [self.__sfi.my_credential_string])
            #user_records = self.registry(sfi).Resolve(user_urns, [sfi.my_credential_string])

            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')
            else:
                users = sfa_users_arg(user_records, slice_record)


        logger.debug('Creating the sliver using the RSpec %s'%rspec)
        time.sleep(5)

        #Creating the sliver
        logger.debug("###################slice_urn: %s"%(slice_urn,))
        logger.debug("###################creds: %s"%(creds,))
        logger.debug("###################rspec: %s"%(rspec,))
#.........这里部分代码省略.........
开发者ID:tubav,项目名称:teagle,代码行数:103,代码来源:SFAVNode.py


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