3 from sfa.util.xrn import urn_to_hrn
4 from sfa.util.method import Method
5 from sfa.util.sfatablesRuntime import run_sfatables
6 from sfa.util.sfalogging import logger
8 from sfa.util.faults import SfaInvalidArgument
9 from sfa.trust.credential import Credential
11 from sfa.storage.parameter import Parameter, Mixed
14 class ListResources(Method):
16 Returns information about available resources
17 @param credential list
18 @param options dictionary
21 interfaces = ['aggregate']
23 Mixed(Parameter(str, "Credential string"),
24 Parameter(type([str]), "List of credentials")),
25 Parameter(dict, "Options")
27 returns = Parameter(str, "List of resources")
29 def call(self, creds, options):
30 logger.info("interface: %s\tmethod-name: %s" %
31 (self.api.interface, self.name))
33 # client must specify a version
34 if not options.get('geni_rspec_version'):
35 if options.get('rspec_version'):
36 options['geni_rspec_version'] = options['rspec_version']
38 raise SfaInvalidArgument(
39 'Must specify an rspec version option. geni_rspec_version cannot be null')
41 # Find the valid credentials
42 valid_creds = self.api.auth.checkCredentialsSpeaksFor(
43 creds, 'listnodes', options=options)
45 # get hrn of the original caller
46 origin_hrn = options.get('origin_hrn', None)
48 origin_hrn = Credential(
49 cred=valid_creds[0]).get_gid_caller().get_hrn()
50 rspec = self.api.manager.ListResources(self.api, creds, options)
52 # filter rspec through sfatables
53 if self.api.interface in ['aggregate']:
54 chain_name = 'OUTGOING'
56 "ListResources: sfatables on chain %s" % chain_name)
57 filtered_rspec = run_sfatables(chain_name, '', origin_hrn, rspec)
59 if 'geni_compressed' in options and options['geni_compressed'] == True:
60 filtered_rspec = zlib.compress(filtered_rspec).encode('base64')