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 $
4 from sfa.util.faults import *
5 from sfa.util.xrn import urn_to_hrn
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
11 class reset_slice(Method):
13 Reset the specified slice
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
20 interfaces = ['aggregate', 'slicemgr', 'component']
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"))
29 returns = Parameter(int, "1 if successful")
31 def call(self, cred, xrn, origin_hrn=None):
32 hrn, type = urn_to_hrn(xrn)
33 self.api.auth.check(cred, 'resetslice', hrn)
34 # send the call to the right manager
35 manager_base = 'sfa.managers'
36 if self.api.interface in ['component']:
37 mgr_type = self.api.config.SFA_CM_TYPE
38 manager_module = manager_base + ".component_manager_%s" % mgr_type
39 manager = __import__(manager_module, fromlist=[manager_base])
40 manager.reset_slice(self.api, xrn)
41 elif self.api.interface in ['aggregate']:
42 mgr_type = self.api.config.SFA_AGGREGATE_TYPE
43 manager_module = manager_base + ".aggregate_manager_%s" % mgr_type
44 manager = __import__(manager_module, fromlist=[manager_base])
45 manager.reset_slice(self.api, xrn)
46 elif self.api.interface in ['slicemgr']:
47 mgr_type = self.api.config.SFA_SM_TYPE
48 manager_module = manager_base + ".slice_manager_%s" % mgr_type
49 manager = __import__(manager_module, fromlist=[manager_base])
50 manager.reset_slice(self.api, xrn)