fix spelling error
[sfa.git] / sfa / methods / reset_slice.py
1 ### $Id: reset_slices.py 15428 2009-10-23 15:28:03Z tmack $
2 ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/reset_slices.py $
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
11 class reset_slice(Method):
12     """
13     Reset 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
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"),
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, hrn, origin_hrn=None):
32         self.api.auth.check(cred, 'resetslice')
33         # send the call to the right manager
34         manager_base = 'sfa.managers'
35         if self.api.interface in ['component']:
36             mgr_type = self.api.config.SFA_CM_TYPE
37             manager_module = manager_base + ".component_manager_%s" % mgr_type
38             manager = __import__(manager_module, fromlist=[manager_base])
39             manager.reset_slice(self.api, hrn)
40         elif self.api.interface in ['aggregate']:
41             mgr_type = self.api.config.SFA_AGGREGATE_TYPE
42             manager_module = manager_base + ".aggregate_manager_%s" % mgr_type
43             manager = __import__(manager_module, fromlist=[manager_base])
44             manager.reset_slice(self.api, hrn)
45         elif self.api.interface in ['slicemgr']:
46             mgr_type = self.api.config.SFA_SM_TYPE
47             manager_module = manager_base + ".slice_manager_%s" % mgr_type
48             manager = __import__(manager_module, fromlist=[manager_base])
49             manager.reset_slice(self.api, hrn) 
50
51         return 1