4 from sfa.util.faults import *
5 from sfa.util.misc import *
6 from sfa.util.method import Method
7 from sfa.util.parameter import Parameter, Mixed
8 from sfa.trust.auth import Auth
9 from sfa.plc.slices import Slices
10 from sfa.util.config import Config
11 # RSpecManager_pl is not used. It's used to make sure the module is in place.
12 import sfa.rspecs.aggregates.rspec_manager_pl
13 from sfa.trust.credential import Credential
14 from sfatables.runtime import SFATablesRules
17 class create_slice(Method):
19 Instantiate the specified slice according to whats defined in the specified rspec
21 @param cred credential string specifying the rights of the caller
22 @param hrn human readable name of slice to instantiate
23 @param rspec resource specification
24 @return 1 is successful, faults otherwise
27 interfaces = ['aggregate', 'slicemgr']
30 Parameter(str, "Credential string"),
31 Parameter(str, "Human readable name of slice to instantiate"),
32 Parameter(str, "Resource specification"),
33 Mixed(Parameter(str, "Request hash"),
34 Parameter(None, "Request hash not specified"))
37 returns = Parameter(int, "1 if successful")
39 def call(self, cred, hrn, requested_rspec, request_hash=None):
41 # This cred will be an slice cred, not a user, so we cant use it to
42 # authenticate the caller's request_hash. Let just get the caller's gid
43 # from the cred and authenticate using that
44 user_cred = Credential(string=cred)
45 client_gid = user_cred.get_gid_caller()
46 client_gid_str = client_gid.save_to_string(save_parents=True)
47 self.api.auth.authenticateGid(client_gid_str, [cred, hrn, requested_rspec], request_hash)
48 self.api.auth.check(cred, 'createslice')
51 gid_origin_caller = user_cred.get_gid_origin_caller()
52 origin_hrn = gid_origin_caller.get_hrn()
53 self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
55 sfa_aggregate_type = Config().get_aggregate_rspec_type()
56 rspec_manager = __import__("sfa.rspecs.aggregates.rspec_manager_"+sfa_aggregate_type, fromlist = ["sfa.rspecs.aggregates"])
57 #Filter the incoming rspec using sfatables
58 if self.api.interface in ['slicemgr']:
59 incoming_rules = SFATablesRules('FORWARD-INCOMING')
60 elif self.api.interface in ['aggregate']:
61 incoming_rules = SFATablesRules('INCOMING')
63 if incoming_rules.sorted_rule_list:
64 #incoming_rules.set_slice(hrn) # This is a temporary kludge. Eventually, we'd like to fetch the context requested by the match/target
66 contexts = incoming_rules.contexts
67 request_context = rspec_manager.fetch_context(hrn, origin_hrn, contexts)
68 incoming_rules.set_context(request_context)
69 rspec = incoming_rules.apply(requested_rspec)
71 rspec = requested_rspec
73 # send the call to the right manager
74 if sfa_aggregate_type not in ['pl']:
75 # To clean up after July 21 - SB
76 rspec = rspec_manager.create_slice(self.api, hrn, rspec)
79 manager_base = 'sfa.managers'
80 if self.api.interface in ['aggregate']:
81 mgr_type = self.api.config.SFA_AGGREGATE_TYPE
82 manager_module = manager_base + ".aggregate_manager_%s" % mgr_type
83 manager = __import__(manager_module, fromlist=[manager_base])
84 manager.create_slice(self.api, hrn, rspec)
85 elif self.api.interface in ['slicemgr']:
86 mgr_type = self.api.config.SFA_SM_TYPE
87 manager_module = manager_base + ".slice_manager_%s" % mgr_type
88 manager = __import__(manager_module, fromlist=[manager_base])
89 manager.create_slice(self.api, hrn, rspec, gid_origin_caller)