4 from sfa.util.faults import *
5 from sfa.util.xrn import urn_to_hrn
6 from sfa.util.method import Method
7 from sfa.util.parameter import Parameter, Mixed
8 from sfa.trust.credential import Credential
9 from sfa.util.sfatablesRuntime import run_sfatables
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 # get manager for this interface
41 manager = self.api.get_interface_manager()
42 rspec = manager.get_rspec(self.api, creds, options)
44 # filter rspec through sfatables
45 if self.api.interface in ['aggregate']:
46 chain_name = 'OUTGOING'
47 elif self.api.interface in ['slicemgr']:
48 chain_name = 'FORWARD-OUTGOING'
49 self.api.logger.debug("ListResources: sfatables on chain %s"%chain_name)
50 filtered_rspec = run_sfatables(chain_name, hrn, origin_hrn, rspec)
52 if options.has_key('geni_compressed') and options['geni_compressed'] == True:
53 filtered_rspec = zlib.compress(filtered_rspec).encode('base64')