本文整理汇总了Python中sfa.rspecs.version_manager.VersionManager._get_version方法的典型用法代码示例。如果您正苦于以下问题:Python VersionManager._get_version方法的具体用法?Python VersionManager._get_version怎么用?Python VersionManager._get_version使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfa.rspecs.version_manager.VersionManager
的用法示例。
在下文中一共展示了VersionManager._get_version方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_rspec
# 需要导入模块: from sfa.rspecs.version_manager import VersionManager [as 别名]
# 或者: from sfa.rspecs.version_manager.VersionManager import _get_version [as 别名]
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()
示例2: to_sfa_rspec
# 需要导入模块: from sfa.rspecs.version_manager import VersionManager [as 别名]
# 或者: from sfa.rspecs.version_manager.VersionManager import _get_version [as 别名]
def to_sfa_rspec(in_rspec, content_type=None):
rspec = RSpec(in_rspec)
version_manager = VersionManager()
sfa_version = version_manager._get_version("sfa", "1")
pg_version = version_manager._get_version("protogeni", "2")
if rspec.version.type.lower() == sfa_version.type.lower():
return in_rspec
elif rspec.version.type.lower() == pg_version.type.lower():
return PGRSpecConverter.to_sfa_rspec(in_rspec, content_type)
else:
return in_rspec
示例3: get_rspec
# 需要导入模块: from sfa.rspecs.version_manager import VersionManager [as 别名]
# 或者: from sfa.rspecs.version_manager.VersionManager import _get_version [as 别名]
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()
示例4: describe
# 需要导入模块: from sfa.rspecs.version_manager import VersionManager [as 别名]
# 或者: from sfa.rspecs.version_manager.VersionManager import _get_version [as 别名]
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: describe
# 需要导入模块: from sfa.rspecs.version_manager import VersionManager [as 别名]
# 或者: from sfa.rspecs.version_manager.VersionManager import _get_version [as 别名]
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
示例6: create_sliver
# 需要导入模块: from sfa.rspecs.version_manager import VersionManager [as 别名]
# 或者: from sfa.rspecs.version_manager.VersionManager import _get_version [as 别名]
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()
示例7: Provision
# 需要导入模块: from sfa.rspecs.version_manager import VersionManager [as 别名]
# 或者: from sfa.rspecs.version_manager.VersionManager import _get_version [as 别名]
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: list_resources
# 需要导入模块: from sfa.rspecs.version_manager import VersionManager [as 别名]
# 或者: from sfa.rspecs.version_manager.VersionManager import _get_version [as 别名]
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: list_resources
# 需要导入模块: from sfa.rspecs.version_manager import VersionManager [as 别名]
# 或者: from sfa.rspecs.version_manager.VersionManager import _get_version [as 别名]
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: to_sfa_rspec
# 需要导入模块: from sfa.rspecs.version_manager import VersionManager [as 别名]
# 或者: from sfa.rspecs.version_manager.VersionManager import _get_version [as 别名]
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()
示例11: get_rspec
# 需要导入模块: from sfa.rspecs.version_manager import VersionManager [as 别名]
# 或者: from sfa.rspecs.version_manager.VersionManager import _get_version [as 别名]
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()
示例12: Describe
# 需要导入模块: from sfa.rspecs.version_manager import VersionManager [as 别名]
# 或者: from sfa.rspecs.version_manager.VersionManager import _get_version [as 别名]
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
}
示例13: describe
# 需要导入模块: from sfa.rspecs.version_manager import VersionManager [as 别名]
# 或者: from sfa.rspecs.version_manager.VersionManager import _get_version [as 别名]
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}
示例14: to_sfa_rspec
# 需要导入模块: from sfa.rspecs.version_manager import VersionManager [as 别名]
# 或者: from sfa.rspecs.version_manager.VersionManager import _get_version [as 别名]
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()
示例15: list_resources
# 需要导入模块: from sfa.rspecs.version_manager import VersionManager [as 别名]
# 或者: from sfa.rspecs.version_manager.VersionManager import _get_version [as 别名]
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()