logging and call tracing features
[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. This is just to resolve issues with the dynamic __import__ that comes later.
12 import sfa.rspecs.aggregates.rspec_manager_pl
13 from sfa.trust.credential import Credential
14
15
16 class create_slice(Method):
17     """
18     Instantiate the specified slice according to whats defined in the specified rspec      
19
20     @param cred credential string specifying the rights of the caller
21     @param hrn human readable name of slice to instantiate
22     @param rspec resource specification
23     @return 1 is successful, faults otherwise  
24     """
25
26     interfaces = ['aggregate', 'slicemgr']
27     
28     accepts = [
29         Parameter(str, "Credential string"),
30         Parameter(str, "Human readable name of slice to instantiate"),
31         Parameter(str, "Resource specification"),
32         ]
33
34     returns = Parameter(int, "1 if successful")
35     
36     def call(self, cred, hrn, rspec, caller_cred=None):
37         if caller_cred==None:
38            caller_cred=cred
39         #log the call
40         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))
41
42         sfa_aggregate_type = Config().get_aggregate_rspec_type()
43         self.api.auth.check(cred, 'createslice')
44         if (sfa_aggregate_type == 'pl'):
45             slices = Slices(self.api, caller_cred=caller_cred)
46             slices.create_slice(hrn, rspec)    
47         else:
48             # To clean up after July 21 - SB    
49             rspec_manager = __import__("sfa.rspecs.aggregates.rspec_manager_"+sfa_aggregate_type, fromlist = ["sfa.rspecs.aggregates"])
50             rspec = rspec_manager.create_slice(self.api, hrn, rspec)
51         
52         return 1