+# xxx Thierry : caching at the aggregate level sounds wrong...
+caching=True
+#caching=False
+def ListSlices(api, creds, call_id):
+ if Callids().already_handled(call_id): return []
+ # look in cache first
+ if caching and api.cache:
+ slices = api.cache.get('slices')
+ if slices:
+ return slices
+
+ # get data from db
+ slices = api.plshell.GetSlices(api.plauth, {'peer_id': None}, ['name'])
+ slice_hrns = [slicename_to_hrn(api.hrn, slice['name']) for slice in slices]
+ slice_urns = [hrn_to_urn(slice_hrn, 'slice') for slice_hrn in slice_hrns]
+
+ # cache the result
+ if caching and api.cache:
+ api.cache.add('slices', slice_urns)
+
+ return slice_urns
+
+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)
+
+ # get the rspec's return format from options
+ try:
+ format_raw = options.get('rspec_version', 'SFA 1')
+ format_split = format_raw.split(' ')
+ format, version = format_split[0].lower(), format_split[1]
+ except:
+ # invalid format. Just continue
+ format, version = 'sfa', '1'
+ format_template = "rsepc_%s_%s"
+
+ # look in cache first
+ if caching and api.cache and not xrn:
+ rspec = api.cache.get(format_template % (format, version))
+ if rspec:
+ api.logger.info("aggregate.ListResources: returning cached value for hrn %s"%hrn)
+ return rspec
+
+ aggregate = Aggregate(api)
+
+ if xrn:
+ # get this rspec for the specified slice
+ rspec = aggregate.get_rspec(slice_xrn=hrn, format=format)
+ else:
+ # generate rspec in both pg and sfa formats
+ rspec = aggregate.get_rspec(format=format)
+ # cache the result
+ if caching and api.cache:
+ api.cache.add(format_template % (format, version), rspec)
+
+ return rspec
+
+
+def get_ticket(api, xrn, creds, rspec, users):
+
+ reg_objects = __get_registry_objects(xrn, creds, users)