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


Python version_manager.VersionManager类代码示例

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


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

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

示例2: ListResources

def ListResources(api, creds, options, call_id):
    if Callids().already_handled(call_id): return ""
    # get slice's hrn from options
    xrn = options.get('geni_slice_urn', None)
    (hrn, type) = urn_to_hrn(xrn)

    version_manager = VersionManager()
    # get the rspec's return format from options
    rspec_version = version_manager.get_version(options.get('rspec_version'))
    version_string = "rspec_%s" % (rspec_version.to_string())

    #panos adding the info option to the caching key (can be improved)
    if options.get('info'):
        version_string = version_string + "_"+options.get('info', 'default')

    # look in cache first
    if caching and api.cache and not xrn:
        rspec = api.cache.get(version_string)
        if rspec:
            api.logger.info("aggregate.ListResources: returning cached value for hrn %s"%hrn)
            return rspec 

    #panos: passing user-defined options
    #print "manager options = ",options
    aggregate = Aggregate(api, options)
    rspec =  aggregate.get_rspec(slice_xrn=xrn, version=rspec_version)

    # cache the result
    if caching and api.cache and not xrn:
        api.cache.add(version_string, rspec)

    return rspec
开发者ID:planetlab,项目名称:sfa,代码行数:32,代码来源:aggregate_manager_pl.py

示例3: Describe

    def Describe(self, api, creds, urns, options):
        call_id = options.get('call_id')
        if Callids().already_handled(call_id): return ""

        version_manager = VersionManager()
        rspec_version = version_manager.get_version(options.get('geni_rspec_version'))
        return api.driver.describe(urns, rspec_version, options)
开发者ID:BeomJun92,项目名称:sfawrap,代码行数:7,代码来源:aggregate_manager.py

示例4: provision

    def provision(self, urns, options=None):
        if options is None: options={}
        # update users
        slices = PlSlices(self)
        aggregate = PlAggregate(self)
        slivers = aggregate.get_slivers(urns)
        if not slivers:
            sliver_id_parts = Xrn(urns[0]).get_sliver_id_parts()
            filter = {}
            try:
                filter['slice_id'] = int(sliver_id_parts[0])
            except ValueError:
                filter['name'] = sliver_id_parts[0]
            slices = self.shell.GetSlices(filter,['hrn'])
            if not slices:
                raise Forbidden("Unable to locate slice record for sliver:  %s" % xrn)
            slice = slices[0]
            slice_urn = hrn_to_urn(slice['hrn'], type='slice')
            urns = [slice_urn]          
        else:    
            slice_id = slivers[0]['slice_id']
            slice_hrn = self.shell.GetSliceHrn(slice_id)
            slice = self.shell.GetSlices({'slice_id': slice_id})[0]
            slice['hrn'] = slice_hrn
            sfa_peer = slices.get_sfa_peer(slice['hrn'])
            users = options.get('geni_users', [])
            persons = slices.verify_persons(slice['hrn'], slice, users, sfa_peer, options=options)
            # update sliver allocation states and set them to geni_provisioned
            sliver_ids = [sliver['sliver_id'] for sliver in slivers]
            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:nfvproject,项目名称:SFA,代码行数:35,代码来源:pldriver.py

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

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

示例7: ListResources

def ListResources(api, creds, options,call_id):
    if Callids().already_handled(call_id): return ""
    # get slice's hrn from options
    xrn = options.get('geni_slice_urn', '')
    hrn, type = urn_to_hrn(xrn)

    version_manager = VersionManager()
    # get the rspec's return format from options
    rspec_version = version_manager.get_version(options.get('rspec_version'))
    version_string = "rspec_%s" % (rspec_version.to_string())
    
    # look in cache first
    if api.cache and not xrn:
        rspec = api.cache.get(version_string)
        if rspec:
            api.logger.info("aggregate.ListResources: returning cached value for hrn %s"%hrn)
            return rspec

    aggregate = ViniAggregate(api, options) 
    rspec =  aggregate.get_rspec(slice_xrn=xrn, version=rspec_version)
           
    # cache the result
    if api.cache and not xrn:
        api.cache.add('nodes', rspec)

    return rspec
开发者ID:planetlab,项目名称:sfa,代码行数:26,代码来源:aggregate_manager_vini.py

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

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

示例10: list_resources

 def list_resources (self, slice_urn, slice_hrn, creds, options):
     cached_requested = options.get('cached', True) 
 
     version_manager = VersionManager()
     # get the rspec's return format from options
     rspec_version = version_manager.get_version(options.get('geni_rspec_version'))
     version_string = "rspec_%s" % (rspec_version)
 
     #panos adding the info option to the caching key (can be improved)
     if options.get('info'):
         version_string = version_string + "_"+options.get('info', 'default')
 
     # look in cache first
     if cached_requested and self.cache and not slice_hrn:
         rspec = self.cache.get(version_string)
         if rspec:
             logger.debug("OpenStackDriver.ListResources: returning cached advertisement")
             return rspec 
 
     #panos: passing user-defined options
     #print "manager options = ",options
     aggregate = OSAggregate(self)
     rspec =  aggregate.get_rspec(slice_xrn=slice_urn, version=rspec_version, 
                                  options=options)
 
     # cache the result
     if self.cache and not slice_hrn:
         logger.debug("OpenStackDriver.ListResources: stores advertisement in cache")
         self.cache.add(version_string, rspec)
 
     return rspec
开发者ID:tubav,项目名称:sfa,代码行数:31,代码来源:nova_driver.py

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

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

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

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

示例15: list_resources

    def list_resources(self, slice_urn, slice_hrn, creds, options):

        version_manager = VersionManager()
        # get the rspec's return format from options
        rspec_version = version_manager.get_version(options.get("geni_rspec_version"))
        version_string = "rspec_%s" % (rspec_version)

        aggregate = DummyAggregate(self)
        rspec = aggregate.get_rspec(slice_xrn=slice_urn, version=rspec_version, options=options)

        return rspec
开发者ID:tubav,项目名称:sfa,代码行数:11,代码来源:dummydriver.py


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