• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python xrn.Xrn类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: GetVersion

def GetVersion(api):
    # peers explicitly in aggregates.xml
    peers =dict ([ (peername,get_serverproxy_url(v)) for (peername,v) in api.aggregates.iteritems()
                   if peername != api.hrn])
    version_manager = VersionManager()
    ad_rspec_versions = []
    request_rspec_versions = []
    for rspec_version in version_manager.versions:
        if rspec_version.content_type in ['*', 'ad']:
            ad_rspec_versions.append(rspec_version.to_dict())
        if rspec_version.content_type in ['*', 'request']:
            request_rspec_versions.append(rspec_version.to_dict())
    default_rspec_version = version_manager.get_version("sfa 1").to_dict()
    xrn=Xrn(api.hrn, 'authority+sa')
    version_more = {'interface':'slicemgr',
                    'hrn' : xrn.get_hrn(),
                    'urn' : xrn.get_urn(),
                    'peers': peers,
                    'request_rspec_versions': request_rspec_versions,
                    'ad_rspec_versions': ad_rspec_versions,
                    'default_ad_rspec': default_rspec_version
                    }
    sm_version=version_core(version_more)
    # local aggregate if present needs to have localhost resolved
    if api.hrn in api.aggregates:
        local_am_url=get_serverproxy_url(api.aggregates[api.hrn])
        sm_version['peers'][api.hrn]=local_am_url.replace('localhost',sm_version['hostname'])
    return sm_version
开发者ID:planetlab,项目名称:sfa,代码行数:28,代码来源:slice_manager_pl.py


示例2: get_slice_and_slivers

    def get_slice_and_slivers(self, slice_xrn, login=None):
        """
        Returns a dict of slivers keyed on the sliver's node_id
        """
        slivers = {}
        sfa_slice = None
        if not slice_xrn:
            return (sfa_slice, slivers)
        slice_urn = hrn_to_urn(slice_xrn, 'slice')
        slice_hrn, _ = urn_to_hrn(slice_xrn)
        slice_name = slice_hrn

        slices = self.driver.GetSlices(slice_filter= str(slice_name), \
                                                slice_filter_type = 'slice_hrn', login=login)
        
        logger.debug("Slabaggregate api \tget_slice_and_slivers \
                        sfa_slice %s \r\n slices %s self.driver.hrn %s" \
                        %(sfa_slice, slices, self.driver.hrn))
        if not slices:
            return (sfa_slice, slivers)
        #if isinstance(sfa_slice, list):
            #sfa_slice = slices[0]
        #else:
            #sfa_slice = slices

        # sort slivers by node id , if there is a job
        #and therfore, node allocated to this slice
        for sfa_slice in slices:
            try:
                node_ids_list =  sfa_slice['node_ids']  
            except KeyError:
                logger.log_exc("SLABAGGREGATE \t \
                                        get_slice_and_slivers KeyError ")
                continue
                                        
            for node in node_ids_list:
                sliver_xrn = Xrn(slice_urn, type='sliver', id=node)
                sliver_xrn.set_authority(self.driver.hrn)
                #node_id = self.driver.root_auth + '.' + node_id
                sliver = Sliver({'sliver_id':sliver_xrn.urn, 
                                'name': sfa_slice['hrn'],
                                'type': 'slab-node', 
                                'tags': []})
                
                slivers[node] = sliver
          
        
        #Add default sliver attribute :
        #connection information for senslab
        if get_authority (sfa_slice['hrn']) == self.driver.root_auth: 
            tmp = sfa_slice['hrn'].split('.')
            ldap_username = tmp[1].split('_')[0]
            vmaddr = 'ssh ' + ldap_username + '@grenoble.senslab.info'
            slivers['default_sliver'] =  {'vm': vmaddr , 'login': ldap_username}
            
        #TODO get_slice_and_slivers Find the login of the external user

        logger.debug("SLABAGGREGATE api get_slice_and_slivers  slivers %s "\
                                                             %(slivers))
        return (slices, slivers)
开发者ID:tubav,项目名称:sfa,代码行数:60,代码来源:slabaggregate.py


示例3: GetVersion

 def GetVersion(self, api, options):
     # peers explicitly in aggregates.xml
     peers =dict ([ (peername,interface.get_url()) for (peername,interface) in api.aggregates.iteritems()
                    if peername != api.hrn])
     version_manager = VersionManager()
     ad_rspec_versions = []
     request_rspec_versions = []
     for rspec_version in version_manager.versions:
         if rspec_version.content_type in ['*', 'ad']:
             ad_rspec_versions.append(rspec_version.to_dict())
         if rspec_version.content_type in ['*', 'request']:
             request_rspec_versions.append(rspec_version.to_dict())
     xrn=Xrn(api.hrn, 'authority+sa')
     version_more = {
         'interface':'slicemgr',
         'sfa': 2,
         'geni_api': 2,
         'geni_api_versions': {'2': 'http://%s:%s' % (api.config.SFA_SM_HOST, api.config.SFA_SM_PORT)},
         'hrn' : xrn.get_hrn(),
         'urn' : xrn.get_urn(),
         'peers': peers,
         'geni_request_rspec_versions': request_rspec_versions,
         'geni_ad_rspec_versions': ad_rspec_versions,
         }
     sm_version=version_core(version_more)
     # local aggregate if present needs to have localhost resolved
     if api.hrn in api.aggregates:
         local_am_url=api.aggregates[api.hrn].get_url()
         sm_version['peers'][api.hrn]=local_am_url.replace('localhost',sm_version['hostname'])
     return sm_version
开发者ID:tubav,项目名称:sfa,代码行数:30,代码来源:slice_manager.py


示例4: call

    def call(self, xrn, creds, rspec, options):
        xrn = Xrn(xrn, type='slice')
        self.api.logger.info("interface: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, xrn.get_hrn(), self.name))
        (speaking_for, _) = urn_to_hrn(options.get('geni_speaking_for'))

        # Find the valid credentials
        valid_creds = self.api.auth.checkCredentials(creds, 'createsliver', xrn.get_hrn(), speaking_for_hrn=speaking_for)
        # use the expiration from the first valid credential to determine when 
        # the slivers should expire.
        expiration = datetime_to_string(Credential(cred=valid_creds[0]).expiration)
        
        # make sure request is not empty
        slivers = RSpec(rspec).version.get_nodes_with_slivers()
        if not slivers:
            raise InvalidRSpec("Missing <sliver_type> or <sliver> element. Request rspec must explicitly allocate slivers")    

        # flter rspec through sfatables
        if self.api.interface in ['aggregate']:
            chain_name = 'INCOMING'
        elif self.api.interface in ['slicemgr']:
            chain_name = 'FORWARD-INCOMING'
        self.api.logger.debug("Allocate: sfatables on chain %s"%chain_name)
        origin_hrn = Credential(cred=valid_creds[0]).get_gid_caller().get_hrn()
        self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, xrn, self.name)) 
        rspec = run_sfatables(chain_name, xrn.get_hrn(), origin_hrn, rspec)
        slivers = RSpec(rspec).version.get_nodes_with_slivers()
        if not slivers:
            raise SfatablesRejected(slice_xrn)

        result = self.api.manager.Allocate(self.api, xrn.get_urn(), creds, rspec, expiration, options)
        return result
开发者ID:aquila,项目名称:sfa,代码行数:31,代码来源:Allocate.py


示例5: provision

 def provision(self, xrn):
     """Provision slivers"""
     xrn = Xrn(xrn, 'slice')
     slice_urn=xrn.get_urn()
     options = {'geni_rspec_version': 'KOREN'}
     manifest = self.api.manager.Provision(self.api, [slice_urn], [], options)
     print manifest
开发者ID:kongseokhwan,项目名称:sfa,代码行数:7,代码来源:sfaadmin.py


示例6: __init__

    def __init__ (self, auth=None, hostname=None, slicename=None, slivername=None, username=None, **kwargs):
        
        if hostname is not None:
            self.type = 'node'
            self.hrn = '.'.join( [auth, Xrn.escape(hostname)] )
            self.hrn_to_urn()

        elif slicename is not None:
            self.type = 'slice'
            self.hrn = '.'.join([auth, slicename])
            self.hrn_to_urn()
        
        elif slivername is not None:
            self.type = 'sliver'
            # Reformat sliver name
            xrn_slivername = clab_slivername_to_xrn_slivername(slivername)
            self.hrn = '.'.join([auth, xrn_slivername])
            self.hrn_to_urn()
            
        elif username is not None:
            self.type = 'user'
            self.hrn = '.'.join([auth, username])
            self.hrn_to_urn()

        else:
            Xrn.__init__ (self, **kwargs)
开发者ID:gnogueras,项目名称:clab_sfawrap,代码行数:26,代码来源:clab_xrn.py


示例7: GetVersion

 def GetVersion(self, api, options):
     # peers explicitly in aggregates.xml
     peers =dict ([ (peername,interface.get_url()) for (peername,interface) in api.aggregates.iteritems()
                    if peername != api.hrn])
     version_manager = VersionManager()
     ad_rspec_versions = []
     request_rspec_versions = []
     cred_types = [{'geni_type': 'geni_sfa', 'geni_version': str(i)} for i in range(4)[-2:]]
     for rspec_version in version_manager.versions:
         if rspec_version.content_type in ['*', 'ad']:
             ad_rspec_versions.append(rspec_version.to_dict())
         if rspec_version.content_type in ['*', 'request']:
             request_rspec_versions.append(rspec_version.to_dict())
     xrn=Xrn(api.hrn, 'authority+sm')
     version_more = {
         'interface':'slicemgr',
         'sfa': 2,
         'geni_api': 3,
         'geni_api_versions': {'3': 'http://%s:%s' % (api.config.SFA_SM_HOST, api.config.SFA_SM_PORT)},
         'hrn' : xrn.get_hrn(),
         'urn' : xrn.get_urn(),
         'peers': peers,
         'geni_single_allocation': 0, # Accept operations that act on as subset of slivers in a given state.
         'geni_allocate': 'geni_many',# Multiple slivers can exist and be incrementally added, including those which connect or overlap in some way.
         'geni_credential_types': cred_types,
         }
     sm_version=version_core(version_more)
     # local aggregate if present needs to have localhost resolved
     if api.hrn in api.aggregates:
         local_am_url=api.aggregates[api.hrn].get_url()
         sm_version['peers'][api.hrn]=local_am_url.replace('localhost',sm_version['hostname'])
     return sm_version
开发者ID:aquila,项目名称:sfa,代码行数:32,代码来源:slice_manager.py


示例8: 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


示例9: _record_dict

 def _record_dict(self, xrn, type, email, key, 
                  slices, researchers, pis, 
                  url, description, extras):
     record_dict = {}
     if xrn:
         if type:
             xrn = Xrn(xrn, type)
         else:
             xrn = Xrn(xrn)
         record_dict['urn'] = xrn.get_urn()
         record_dict['hrn'] = xrn.get_hrn()
         record_dict['type'] = xrn.get_type()
     if url:
         record_dict['url'] = url
     if description:
         record_dict['description'] = description
     if key:
         try:
             pubkey = open(key, 'r').read()
         except IOError:
             pubkey = key
         record_dict['reg-keys'] = [pubkey]
     if slices:
         record_dict['slices'] = slices
     if researchers:
         record_dict['reg-researchers'] = researchers
     if email:
         record_dict['email'] = email
     if pis:
         record_dict['reg-pis'] = pis
     if extras:
         record_dict.update(extras)
     return record_dict
开发者ID:kongseokhwan,项目名称:sfa,代码行数:33,代码来源:sfaadmin.py


示例10: allocate

    def allocate (self, urn, rspec_string, expiration, options=None):
        if options is None: options={}
        xrn = Xrn(urn) 
        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(xrn.get_hrn(), users[0])

        # collect public keys
        users = options.get('geni_users', [])
        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()
        slivers = aggregate.run_instances(instance_name, tenant_name, \
                                          rspec_string, key_name, pubkeys)
        
        # update all sliver allocation states setting then to geni_allocated    
        sliver_ids = [sliver.id for sliver in slivers]
        dbsession=self.api.dbsession()
        SliverAllocation.set_allocations(sliver_ids, 'geni_provisioned',dbsession)
   
        return aggregate.describe(urns=[urn], version=rspec.version)
开发者ID:BeomJun92,项目名称:sfawrap,代码行数:30,代码来源:nova_driver.py


示例11: __init__

 def __init__ (self, auth=None, hostname=None, slicename=None, email=None, interface=None, **kwargs):
     #def hostname_to_hrn(auth_hrn, login_base, hostname):
     if hostname is not None:
         self.type='node'
         # keep only the first part of the DNS name
         #self.hrn='.'.join( [auth,hostname.split(".")[0] ] )
         # escape the '.' in the hostname
         self.hrn='.'.join( [auth,Xrn.escape(hostname)] )
         self.hrn_to_urn()
     #def slicename_to_hrn(auth_hrn, slicename):
     elif slicename is not None:
         self.type='slice'
         # split at the first _
         parts = slicename.split("_",1)
         self.hrn = ".".join([auth] + parts )
         self.hrn_to_urn()
     #def email_to_hrn(auth_hrn, email):
     elif email is not None:
         self.type='person'
         # keep only the part before '@' and replace special chars into _
         self.hrn='.'.join([auth,email.split('@')[0].replace(".", "_").replace("+", "_")])
         self.hrn_to_urn()
     elif interface is not None:
         self.type = 'interface'
         self.hrn = auth + '.' + interface
         self.hrn_to_urn()
     else:
         Xrn.__init__ (self,**kwargs)
开发者ID:aquila,项目名称:sfa,代码行数:28,代码来源:plxrn.py


示例12: _record_dict

 def _record_dict(self, xrn=None, type=None, 
                  url=None, description=None, email='', 
                  key=None, 
                  slices=[], researchers=[], pis=[]):
     record_dict = {}
     if xrn:
         if type:
             xrn = Xrn(xrn, type)
         else:
             xrn = Xrn(xrn)
         record_dict['urn'] = xrn.get_urn()
         record_dict['hrn'] = xrn.get_hrn()
         record_dict['type'] = xrn.get_type()
     if url:
         record_dict['url'] = url
     if description:
         record_dict['description'] = description
     if key:
         try:
             pubkey = open(key, 'r').read()
         except IOError:
             pubkey = key
         record_dict['keys'] = [pubkey]
     if slices:
         record_dict['slices'] = slices
     if researchers:
         record_dict['researcher'] = researchers
     if email:
         record_dict['email'] = email
     if pis:
         record_dict['pi'] = pis
     return record_dict
开发者ID:tubav,项目名称:sfa,代码行数:32,代码来源:sfaadmin.py


示例13: delete_instance

    def delete_instance(self, instance):
    
        def _delete_security_group(inst):
            security_group = inst.metadata.get('security_groups', '')
            if security_group:
                manager = SecurityGroup(self.driver)
                timeout = 10.0 # wait a maximum of 10 seconds before forcing the security group delete
                start_time = time.time()
                instance_deleted = False
                while instance_deleted == False and (time.time() - start_time) < timeout:
                    tmp_inst = self.driver.shell.compute_manager.servers.findall(id=inst.id)
                    if not tmp_inst:
                        instance_deleted = True
                    time.sleep(.5)
                manager.delete_security_group(security_group)

        multiclient = MultiClient()
        tenant = self.driver.shell.auth_manager.tenants.find(id=instance.tenant_id)
        
        # Update connection for the current client
        xrn = Xrn(tenant.name)
        user_name = xrn.get_authority_hrn() + '.' + xrn.leaf.split('-')[0]
        self.driver.shell.compute_manager.connect(username=user_name, tenant=tenant.name, password=user_name)

        args = { 'name': instance.name,
                 'id': instance.id }
        instances = self.driver.shell.compute_manager.servers.findall(**args)
        security_group_manager = SecurityGroup(self.driver)
        for instance in instances:
            # destroy instance
            self.driver.shell.compute_manager.servers.delete(instance)
            # deleate this instance's security groups
            multiclient.run(_delete_security_group, instance)
        return 1
开发者ID:kongseokhwan,项目名称:sfa,代码行数:34,代码来源:osaggregate.py


示例14: provision

    def provision(self, urns, options=None):
        if options is None: options={}
        # update sliver allocation states and set them to geni_provisioned
        aggregate = OSAggregate(self)

        # Update connection for the current client
        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.shell.compute_manager.connect(username=user_name, tenant=tenant_name, password=user_name)
        
        instances = aggregate.get_instances(xrn)
        # Allocate new floating IP per the instance
        servers = aggregate.check_floatingip(instances, True)
        aggregate.create_floatingip(tenant_name, servers)

        sliver_ids=[]
        for instance in instances:
            sliver_id = OSXrn(name=('koren'+'.'+ instance.name), id=instance.id, type='node+openstack').get_urn()
            sliver_ids.append(sliver_id)
        dbsession=self.api.dbsession()
        SliverAllocation.set_allocations(sliver_ids, 'geni_provisioned', dbsession)
        version_manager = VersionManager()
        rspec_version = version_manager.get_version(options['geni_rspec_version'])
        return self.describe(urns, rspec_version, options=options)
开发者ID:kongseokhwan,项目名称:sfa,代码行数:25,代码来源:osdriver.py


示例15: provision

 def provision(self, xrn):
     """Provision slivers"""
     xrn = Xrn(xrn, 'slice')
     slice_urn=xrn.get_urn()
     options={}
     manifest = self.api.manager.provision(self.api, [slice_urn], [], options)
     print manifest
开发者ID:nfvproject,项目名称:SFA,代码行数:7,代码来源:sfaadmin.py


示例16: RenewSliver

 def RenewSliver(self, api, xrn, creds, expiration_time, options):
     call_id = options.get('call_id')
     if Callids().already_handled(call_id): return True
     
     xrn = Xrn(xrn, 'slice')
     slice_urn=xrn.get_urn()
     slice_hrn=xrn.get_hrn()
     return self.driver.renew_sliver (slice_urn, slice_hrn, creds, expiration_time, options)
开发者ID:tubav,项目名称:sfa,代码行数:8,代码来源:aggregate_manager.py


示例17: SliverStatus

 def SliverStatus (self, api, xrn, creds, options):
     call_id = options.get('call_id')
     if Callids().already_handled(call_id): return {}
 
     xrn = Xrn(xrn,'slice')
     slice_urn=xrn.get_urn()
     slice_hrn=xrn.get_hrn()
     return self.driver.sliver_status (slice_urn, slice_hrn)
开发者ID:tubav,项目名称:sfa,代码行数:8,代码来源:aggregate_manager.py


示例18: allocate

 def allocate(self, xrn, rspec):
     """Allocate slivers"""
     xrn = Xrn(xrn, 'slice')
     slice_urn=xrn.get_urn()
     rspec_string = open(rspec).read()
     options={}
     manifest = self.api.manager.Allocate(self.api, slice_urn, [], rspec_string, options)
     print manifest
开发者ID:nfvproject,项目名称:SFA,代码行数:8,代码来源:sfaadmin.py


示例19: DeleteSliver

    def DeleteSliver(self, api, xrn, creds, options):
        call_id = options.get('call_id')
        if Callids().already_handled(call_id): return True

        xrn = Xrn(xrn, 'slice')
        slice_urn=xrn.get_urn()
        slice_hrn=xrn.get_hrn()
        return self.driver.delete_sliver (slice_urn, slice_hrn, creds, options)
开发者ID:tubav,项目名称:sfa,代码行数:8,代码来源:aggregate_manager.py


示例20: list

 def list(self, xrn, type=None, recursive=False):
     """List names registered at a given authority - possibly filtered by type"""
     xrn = Xrn(xrn, type) 
     options = {'recursive': recursive}    
     records = self.api.manager.List(self.api, xrn.get_hrn(), options=options)
     for record in records:
         if not type or record['type'] == type:
             print "%s (%s)" % (record['hrn'], record['type'])
开发者ID:tubav,项目名称:sfa,代码行数:8,代码来源:sfaadmin.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sfdb.SpiderFootDb类代码示例发布时间:2022-05-27
下一篇:
Python xrn.urn_to_hrn函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap