4 from sfa.util.faults import *
5 from sfa.util.method import Method
6 from sfa.util.parameter import Parameter, Mixed
7 from sfa.trust.auth import Auth
8 from sfa.util.config import Config
9 from sfa.plc.nodes import Nodes
10 # RSpecManager_pl is not used. This line is a check that ensures that everything is in place for the import to work.
11 import sfa.rspecs.aggregates.rspec_manager_pl
12 from sfa.trust.credential import Credential
13 from sfatables.runtime import SFATablesRules
15 class get_resources(Method):
17 Get an resource specification (rspec). The rspec may describe the resources
18 available at an authority or the resources being used by a slice.
20 @param cred credential string specifying the rights of the caller
21 @param hrn human readable name of the slice we are interesed in or None
25 interfaces = ['aggregate', 'slicemgr']
28 Parameter(str, "Credential string"),
29 Mixed(Parameter(str, "Human readable name (hrn)"),
30 Parameter(None, "hrn not specified")),
31 Mixed(Parameter(str, "Human readable name of the original caller"),
32 Parameter(None, "Origin hrn not specified"))
35 returns = Parameter(str, "String representatin of an rspec")
37 def call(self, cred, hrn=None, origin_hrn=None):
38 user_cred = Credential(string=cred)
42 origin_hrn = user_cred.get_gid_caller().get_hrn()
43 self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
46 self.api.auth.check(cred, 'listnodes')
48 # send the call to the right manager
49 manager_base = 'sfa.managers'
50 if self.api.interface in ['aggregate']:
51 mgr_type = self.api.config.SFA_AGGREGATE_TYPE
52 manager_module = manager_base + ".aggregate_manager_%s" % mgr_type
53 manager = __import__(manager_module, fromlist=[manager_base])
54 rspec = manager.get_rspec(self.api, hrn, origin_hrn)
55 outgoing_rules = SFATablesRules('OUTGOING')
56 elif self.api.interface in ['slicemgr']:
57 mgr_type = self.api.config.SFA_SM_TYPE
58 manager_module = manager_base + ".slice_manager_%s" % mgr_type
59 manager = __import__(manager_module, fromlist=[manager_base])
60 rspec = manager.get_rspec(self.api, hrn, origin_hrn)
61 outgoing_rules = SFATablesRules('FORWARD-OUTGOING')
63 filtered_rspec = rspec
64 if outgoing_rules.sorted_rule_list:
65 request_context = manager.fetch_context(hrn, origin_hrn, outgoing_rules.contexts)
66 outgoing_rules.set_context(request_context)
67 filtered_rspec = outgoing_rules.apply(rspec)