added support for urn name format. urn is the default name format used over the wire
[sfa.git] / sfa / methods / start_slice.py
1 ### $Id$
2 ### $URL$
3
4 from sfa.util.faults import *
5 from sfa.util.namespace 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.trust.credential import Credential
10
11 class start_slice(Method):
12     """
13     Start the specified slice      
14
15     @param cred credential string specifying the rights of the caller
16     @param hrn human readable name of slice to instantiate (urn or hrn)
17     @return 1 is successful, faults otherwise  
18     """
19
20     interfaces = ['aggregate', 'slicemgr', 'component']
21     
22     accepts = [
23         Parameter(str, "Credential string"),
24         Parameter(str, "Human readable name of slice to instantiate (urn or hrn)"),
25         Mixed(Parameter(str, "Human readable name of the original caller"),
26               Parameter(None, "Origin hrn not specified"))
27         ]
28
29     returns = [Parameter(int, "1 if successful")]
30     
31     def call(self, cred, xrn, origin_hrn=None):
32         user_cred = Credential(string=cred)
33
34         #log the call
35         if not origin_hrn:
36             origin_hrn = user_cred.get_gid_caller().get_hrn()
37         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
38
39         # validate the cred
40         self.api.auth.check(cred, 'startslice')
41        
42         # send the call to the right manager
43         manager_base = 'sfa.managers'
44         if self.api.interface in ['component']:
45             mgr_type = self.api.config.SFA_CM_TYPE
46             manager_module = manager_base + ".component_manager_%s" % mgr_type
47             manager = __import__(manager_module, fromlist=[manager_base])
48             manager.start_slice(self.api, xrn)
49         elif self.api.interface in ['aggregate']:
50             mgr_type = self.api.config.SFA_AGGREGATE_TYPE
51             manager_module = manager_base + ".aggregate_manager_%s" % mgr_type
52             manager = __import__(manager_module, fromlist=[manager_base])
53             manager.start_slice(self.api, xrn)
54         elif self.api.interface in ['slicemgr']:
55             mgr_type = self.api.config.SFA_SM_TYPE
56             manager_module = manager_base + ".slice_manager_%s" % mgr_type
57             manager = __import__(manager_module, fromlist=[manager_base])
58             manager.start_slice(self.api, xrn)
59  
60         return 1