added support for urn name format. urn is the default name format used over the wire
[sfa.git] / sfa / methods / stop_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 stop_slice(Method):
12     """
13     Stop the specified slice      
14
15     @param cred credential string specifying the rights of the caller
16     @param xrn human readable name of slice to instantiate (hrn or urn)
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 (hrn or urn)"),
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         hrn, type = urn_to_hrn(xrn)
33         user_cred = Credential(string=cred)
34
35         #log the call
36         if not origin_hrn:
37             origin_hrn = user_cred.get_gid_caller().get_hrn()
38         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
39
40         # validate the cred
41         self.api.auth.check(cred, 'stopslice')
42        
43         # send the call to the right manager
44         manager_base = 'sfa.managers'
45         if self.api.interface in ['component']:
46             mgr_type = self.api.config.SFA_CM_TYPE
47             manager_module = manager_base + ".component_manager_%s" % mgr_type
48             manager = __import__(manager_module, fromlist=[manager_base])
49             manager.stop_slice(self.api, xrn)
50         elif self.api.interface in ['aggregate']:
51             mgr_type = self.api.config.SFA_AGGREGATE_TYPE
52             manager_module = manager_base + ".aggregate_manager_%s" % mgr_type
53             manager = __import__(manager_module, fromlist=[manager_base])
54             manager.stop_slice(self.api, xrn)
55         elif self.api.interface in ['slicemgr']:
56             mgr_type = self.api.config.SFA_SM_TYPE
57             manager_module = manager_base + ".slice_manager_%s" % mgr_type
58             manager = __import__(manager_module, fromlist=[manager_base])
59             manager.stop_slice(self.api, xrn)
60  
61         return 1