3 from sfa.util.xrn import urn_to_hrn
4 from sfa.util.method import Method
5 from sfa.util.sfatablesRuntime import run_sfatables
7 from sfa.trust.credential import Credential
9 from sfa.storage.parameter import Parameter, Mixed
11 class ListResources(Method):
13 Returns information about available resources or resources allocated to this slice
14 @param credential list
15 @param options dictionary
18 interfaces = ['aggregate', 'slicemgr']
20 Mixed(Parameter(str, "Credential string"),
21 Parameter(type([str]), "List of credentials")),
22 Parameter(dict, "Options")
24 returns = Parameter(str, "List of resources")
26 def call(self, creds, options={}):
27 self.api.logger.info("interface: %s\tmethod-name: %s" % (self.api.interface, self.name))
29 # get slice's hrn from options
30 xrn = options.get('geni_slice_urn', '')
31 (hrn, _) = urn_to_hrn(xrn)
33 # Find the valid credentials
34 valid_creds = self.api.auth.checkCredentials(creds, 'listnodes', hrn)
36 # get hrn of the original caller
37 origin_hrn = options.get('origin_hrn', None)
39 origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
40 rspec = self.api.manager.ListResources(self.api, creds, options)
42 # filter rspec through sfatables
43 if self.api.interface in ['aggregate']:
44 chain_name = 'OUTGOING'
45 elif self.api.interface in ['slicemgr']:
46 chain_name = 'FORWARD-OUTGOING'
47 self.api.logger.debug("ListResources: sfatables on chain %s"%chain_name)
48 filtered_rspec = run_sfatables(chain_name, hrn, origin_hrn, rspec)
50 if options.has_key('geni_compressed') and options['geni_compressed'] == True:
51 filtered_rspec = zlib.compress(filtered_rspec).encode('base64')