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.faults import SfaInvalidArgument
7 from sfa.trust.credential import Credential
9 from sfa.storage.parameter import Parameter, Mixed
12 class ListResources(Method):
14 Returns information about available resources
15 @param credential list
16 @param options dictionary
19 interfaces = ['aggregate', 'slicemgr']
21 Mixed(Parameter(str, "Credential string"),
22 Parameter(type([str]), "List of credentials")),
23 Parameter(dict, "Options")
25 returns = Parameter(str, "List of resources")
27 def call(self, creds, options):
28 self.api.logger.info("interface: %s\tmethod-name: %s" %
29 (self.api.interface, self.name))
31 # client must specify a version
32 if not options.get('geni_rspec_version'):
33 if options.get('rspec_version'):
34 options['geni_rspec_version'] = options['rspec_version']
36 raise SfaInvalidArgument(
37 'Must specify an rspec version option. geni_rspec_version cannot be null')
39 # Find the valid credentials
40 valid_creds = self.api.auth.checkCredentialsSpeaksFor(
41 creds, 'listnodes', options=options)
43 # get hrn of the original caller
44 origin_hrn = options.get('origin_hrn', None)
46 origin_hrn = Credential(
47 cred=valid_creds[0]).get_gid_caller().get_hrn()
48 rspec = self.api.manager.ListResources(self.api, creds, options)
50 # filter rspec through sfatables
51 if self.api.interface in ['aggregate']:
52 chain_name = 'OUTGOING'
53 elif self.api.interface in ['slicemgr']:
54 chain_name = 'FORWARD-OUTGOING'
55 self.api.logger.debug(
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')