- aggs = Aggregates(api)
- cred = api.getCredential()
- for agg in aggs:
- if agg not in [api.auth.client_cred.get_gid_caller().get_hrn()]:
- try:
- # get the rspec from the aggregate
- agg_rspec = aggs[agg].get_resources(cred, xrn, origin_hrn)
- except:
- # XX print out to some error log
- print >> log, "Error getting resources at aggregate %s" % agg
- traceback.print_exc(log)
- print >> log, "%s" % (traceback.format_exc())
-
-
- try:
- tree = etree.parse(StringIO(agg_rspec))
- except etree.XMLSyntaxError:
- message = agg + ": " + str(sys.exc_info()[1])
- raise InvalidRSpec(message)
-
- root = tree.getroot()
- if root.get("type") in ["Planetlab", "VINI"]:
- if rspec == None:
- rspec = root
- else:
- for network in root.iterfind("./network"):
- rspec.append(deepcopy(network))
-
- return etree.tostring(rspec, xml_declaration=True, pretty_print=True)
-
-"""
-Returns the request context required by sfatables. At some point, this
-mechanism should be changed to refer to "contexts", which is the
-information that sfatables is requesting. But for now, we just return
-the basic information needed in a dict.
-"""
-def fetch_context(slice_hrn, user_hrn, contexts):
- #slice_hrn = urn_to_hrn(slice_xrn)[0]
- #user_hrn = urn_to_hrn(user_xrn)[0]
- base_context = {'sfa':{'user':{'hrn':user_hrn}, 'slice':{'hrn':slice_hrn}}}
- return base_context
+ # 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()
+ 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]
+ my_opts = copy(options)
+ my_opts['geni_compressed'] = False
+ threads.run(server.ListResources, credential, my_opts)
+ #threads.run(server.get_resources, cred, xrn, origin_hrn)
+
+ results = threads.get_results()
+ # combine the rspecs into a single rspec
+ for agg_rspec in results:
+ try:
+ tree = etree.parse(StringIO(agg_rspec))
+ except etree.XMLSyntaxError:
+ message = str(agg_rspec) + ": " + str(sys.exc_info()[1])
+ raise InvalidRSpec(message)
+
+ root = tree.getroot()
+ if root.get("type") in ["SFA"]:
+ if rspec == None:
+ rspec = root
+ else:
+ for network in root.iterfind("./network"):
+ rspec.append(deepcopy(network))
+ for request in root.iterfind("./request"):
+ rspec.append(deepcopy(request))
+
+ sfa_logger().debug('get_rspec: rspec=%r'%rspec)
+ rspec = etree.tostring(rspec, xml_declaration=True, pretty_print=True)
+ # cache the result
+ if api.cache and not xrn:
+ api.cache.add('nodes', rspec)
+
+ return rspec