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