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 Parameter(str, "Request hash")
36 returns = Parameter(int, "1 if successful")
38 def call(self, cred, hrn, requested_rspec, request_hash, caller_cred=None):
42 # This cred will be an slice cred, not a user, so we cant use it to
43 # authenticate the caller's request_hash. Let just get the caller's gid
44 # from the cred and authenticate using that
45 client_gid = Credential(string=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 self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, Credential(string=caller_cred).get_gid_caller().get_hrn(), hrn, self.name))
53 sfa_aggregate_type = Config().get_aggregate_rspec_type()
54 rspec_manager = __import__("sfa.rspecs.aggregates.rspec_manager_"+sfa_aggregate_type, fromlist = ["sfa.rspecs.aggregates"])
55 #Filter the incoming rspec using sfatables
56 incoming_rules = SFATablesRules('OUTGOING')
58 #incoming_rules.set_slice(hrn) # This is a temporary kludge. Eventually, we'd like to fetch the context requested by the match/target
60 contexts = incoming_rules.contexts
61 request_context = rspec_manager.fetch_context(hrn, Credential(string=caller_cred).get_gid_caller().get_hrn(), contexts)
62 incoming_rules.set_context(request_context)
63 rspec = incoming_rules.apply(requested_rspec)
65 if (sfa_aggregate_type == 'pl'):
66 slices = Slices(self.api, caller_cred=caller_cred)
67 slices.create_slice(hrn, rspec)
69 # To clean up after July 21 - SB
70 rspec = rspec_manager.create_slice(self.api, hrn, rspec)