5d1a09c2313ae782277e09c67df42752f5c1fc21
[sfa.git] / sfa / methods / create_slice.py
1 ### $Id$
2 ### $URL$
3
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
15
16
17 class create_slice(Method):
18     """
19     Instantiate the specified slice according to whats defined in the specified rspec      
20
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  
25     """
26
27     interfaces = ['aggregate', 'slicemgr']
28     
29     accepts = [
30         Parameter(str, "Credential string"),
31         Parameter(str, "Human readable name of slice to instantiate"),
32         Parameter(str, "Resource specification"),
33         ]
34
35     returns = Parameter(int, "1 if successful")
36     
37     def call(self, cred, hrn, requested_rspec, caller_cred=None):
38         if caller_cred==None:
39            caller_cred=cred
40         #log the call
41         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))
42
43         # Filter the incoming rspec using sfatables
44         incoming_rules = SFATablesRules('OUTGOING')
45             
46         incoming_rules.set_user_(caller_cred.callerGID.hrn) # This is a temporary kludge. Eventually, we'd like to fetch the context requested by the match/target
47
48         rspec = incoming_rules.apply(requested_rspec)
49
50
51         sfa_aggregate_type = Config().get_aggregate_rspec_type()
52         self.api.auth.check(cred, 'createslice')
53         if (sfa_aggregate_type == 'pl'):
54             slices = Slices(self.api, caller_cred=caller_cred)
55             slices.create_slice(hrn, rspec)    
56         else:
57             # To clean up after July 21 - SB    
58             rspec_manager = __import__("sfa.rspecs.aggregates.rspec_manager_"+sfa_aggregate_type, fromlist = ["sfa.rspecs.aggregates"])
59             rspec = rspec_manager.create_slice(self.api, hrn, rspec)
60
61             
62         
63         return 1