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 # Validate that at least one of the credentials is good enough
31 self.api.auth.check(cred, 'listnodes')
33 user_cred = Credential(string=cred)
36 error = sys.exc_info()[:2]
40 raise InsufficientRights('ListResources: Access denied: %s -- %s' % (error[0],error[1]))
42 origin_hrn = user_cred.get_gid_caller().get_hrn()
44 manager_base = 'sfa.managers'
46 if self.api.interface in ['geni_am']:
47 mgr_type = self.api.config.SFA_GENI_AGGREGATE_TYPE
48 manager_module = manager_base + ".geni_am_%s" % mgr_type
49 manager = __import__(manager_module, fromlist=[manager_base])
50 rspec = manager.ListResources(self.api, creds, options)
51 outgoing_rules = SFATablesRules('OUTGOING')
54 filtered_rspec = rspec
55 if outgoing_rules.sorted_rule_list:
56 context = {'sfa':{'user':{'hrn':origin_hrn}, 'slice':{'hrn':None}}}
57 outgoing_rules.set_context(context)
58 filtered_rspec = outgoing_rules.apply(rspec)