1 from sfa.util.faults import *
2 from sfa.util.namespace import *
3 from sfa.util.method import Method
4 from sfa.util.parameter import Parameter, Mixed
5 from sfa.trust.credential import Credential
6 from sfatables.runtime import SFATablesRules
10 class ListResources(Method):
12 Returns information about available resources or resources allocated to this slice
13 @param credential list
14 @param options dictionary
17 interfaces = ['geni_am']
19 Parameter(type([str]), "List of credentials"),
20 Parameter(dict, "Options")
22 returns = Parameter(str, "List of resources")
24 def call(self, creds, options):
25 self.api.logger.info("interface: %s\tmethod-name: %s" % (self.api.interface, self.name))
27 # Find the valid credentials
29 if options.has_key('geni_slice_urn'):
30 xrn = options['geni_slice_urn']
31 hrn, _ = urn_to_hrn(xrn)
33 ValidCreds = self.api.auth.checkCredentials(creds, '', hrn)
34 origin_hrn = Credential(string=ValidCreds[0]).get_gid_caller().get_hrn()
37 manager_base = 'sfa.managers'
39 if self.api.interface in ['geni_am']:
40 mgr_type = self.api.config.SFA_GENI_AGGREGATE_TYPE
41 manager_module = manager_base + ".geni_am_%s" % mgr_type
42 manager = __import__(manager_module, fromlist=[manager_base])
43 rspec = manager.ListResources(self.api, ValidCreds, options)
44 outgoing_rules = SFATablesRules('OUTGOING')
47 filtered_rspec = rspec
48 if outgoing_rules.sorted_rule_list:
49 context = {'sfa':{'user':{'hrn':origin_hrn}, 'slice':{'hrn':None}}}
50 outgoing_rules.set_context(context)
51 filtered_rspec = outgoing_rules.apply(rspec)
53 if options.has_key('geni_compressed') and options['geni_compressed'] == True:
54 filtered_rspec = zlib.compress(rspec).encode('base64')