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