+def ListResources(api, creds, options, call_id):
+ def _ListResources(server, credential, my_opts, call_id):
+ args = [credential, my_opts]
+ if _call_id_supported(api, server):
+ args.append(call_id)
+ try:
+ return server.ListResources(*args)
+ except Exception, e:
+ api.logger.warn("ListResources failed at %s: %s" %(server.url, str(e)))
+
+ 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)
+ my_opts = copy(options)
+ my_opts['geni_compressed'] = False
+ if 'rspec_version' in my_opts:
+ del my_opts['rspec_version']
+
+ # get the rspec's return format from options
+ rspec_version = RSpecVersion(options.get('rspec_version'))
+ version_string = "rspec_%s" % (rspec_version.get_version_name())
+
+ # look in cache first
+ if caching and api.cache and not xrn:
+ rspec = api.cache.get(version_string)
+ if rspec:
+ return rspec
+
+ # get the callers hrn
+ valid_cred = api.auth.checkCredentials(creds, 'listnodes', hrn)[0]
+ caller_hrn = Credential(string=valid_cred).get_gid_caller().get_hrn()
+
+ # attempt to use delegated credential first
+ credential = api.getDelegatedCredential(creds)
+ if not credential:
+ credential = api.getCredential()
+ credentials = [credential]
+ 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
+ # get the rspec from the aggregate
+ server = api.aggregates[aggregate]
+ #threads.run(server.ListResources, credentials, my_opts, call_id)
+ threads.run(_ListResources, server, credentials, my_opts, call_id)
+
+ results = threads.get_results()
+ rspec_version = RSpecVersion(my_opts.get('rspec_version'))
+ if rspec_version['type'] == pg_rspec_ad_version['type']:
+ rspec = PGRSpec()
+ else:
+ rspec = SfaRSpec()
+ for result in results:
+ try:
+ rspec.merge(result)
+ except:
+ api.logger.info("SM.ListResources: Failed to merge aggregate rspec")
+
+ # cache the result
+ if caching and api.cache and not xrn:
+ api.cache.add(version_string, rspec.toxml())
+
+ return rspec.toxml()
+
+
+def CreateSliver(api, xrn, creds, rspec_str, users, call_id):
+
+ def _CreateSliver(server, xrn, credential, rspec, users, call_id):
+ # Need to call GetVersion at an aggregate to determine the supported
+ # rspec type/format beofre calling CreateSliver at an Aggregate.
+ server_version = _get_server_version(api, server)
+ if 'sfa' not in aggregate_version and 'geni_api' in aggregate_version:
+ # sfa aggregtes support both sfa and pg rspecs, no need to convert
+ # if aggregate supports sfa rspecs. othewise convert to pg rspec
+ rspec = RSpecConverter.to_pg_rspec(rspec)
+ args = [xrn, credential, rspec, users]
+ if _call_id_supported(api, server):
+ args.append(call_id)
+ try:
+ return server.CreateSliver(*args)
+ except Exception, e:
+ api.logger.warn("CreateSliver failed at %s: %s" %(server.url, str(e)))
+
+ if Callids().already_handled(call_id): return ""