本文整理汇总了Python中sfa.rspecs.rspec.RSpec.validate方法的典型用法代码示例。如果您正苦于以下问题:Python RSpec.validate方法的具体用法?Python RSpec.validate怎么用?Python RSpec.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfa.rspecs.rspec.RSpec
的用法示例。
在下文中一共展示了RSpec.validate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CreateSliver
# 需要导入模块: from sfa.rspecs.rspec import RSpec [as 别名]
# 或者: from sfa.rspecs.rspec.RSpec import validate [as 别名]
def CreateSliver(api, xrn, creds, rspec_str, users, call_id):
version_manager = VersionManager()
def _CreateSliver(aggregate, server, xrn, credential, rspec, users, call_id):
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)
args = [xrn, credential, rspec, requested_users]
if _call_id_supported(api, server):
args.append(call_id)
rspec = server.CreateSliver(*args)
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"}
if Callids().already_handled(call_id): return ""
# Validate the RSpec against PlanetLab's schema --disabled for now
# The schema used here needs to aggregate the PL and VINI schemas
# schema = "/var/www/html/schemas/pl.rng"
rspec = RSpec(rspec_str)
schema = None
if schema:
rspec.validate(schema)
# if there is a <statistics> section, the aggregates don't care about it,
# so delete it.
drop_slicemgr_stats(rspec)
# attempt to use delegated credential first
cred = api.getDelegatedCredential(creds)
if not cred:
cred = api.getCredential()
# get the callers hrn
hrn, type = urn_to_hrn(xrn)
valid_cred = api.auth.checkCredentials(creds, 'createsliver', hrn)[0]
caller_hrn = Credential(string=valid_cred).get_gid_caller().get_hrn()
threads = ThreadManager()
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.get_server(interface, cred)
# Just send entire RSpec to each aggregate
threads.run(_CreateSliver, aggregate, server, xrn, [cred], rspec.toxml(), users, call_id)
results = threads.get_results()
manifest_version = version_manager._get_version(rspec.version.type, rspec.version.version, 'manifest')
result_rspec = RSpec(version=manifest_version)
for result in results:
add_slicemgr_stat(result_rspec, "CreateSliver", result["aggregate"], result["elapsed"], result["status"])
if result["status"]=="success":
try:
result_rspec.version.merge(result["rspec"])
except:
api.logger.log_exc("SM.CreateSliver: Failed to merge aggregate rspec")
return result_rspec.toxml()