1b1ae98940c880f02d7a85a3d9a1bf8d5ade0644
[sfa.git] / sfa / methods / remove.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.util.debug import log
8 from sfa.trust.credential import Credential
9
10 class remove(Method):
11     """
12     Remove an object from the registry. If the object represents a PLC object,
13     then the PLC records will also be removed.
14     
15     @param cred credential string
16     @param type record type
17     @param hrn human readable name of record to remove
18
19     @return 1 if successful, faults otherwise 
20     """
21
22     interfaces = ['registry']
23     
24     accepts = [
25         Parameter(str, "Credential string"),
26         Parameter(str, "Record type"),
27         Parameter(str, "Human readable name of slice to instantiate"),
28         Mixed(Parameter(str, "Human readable name of the original caller"),
29               Parameter(None, "Origin hrn not specified"))
30         ]
31
32     returns = Parameter(int, "1 if successful")
33     
34     def call(self, cred, type, hrn, origin_hrn=None):
35         user_cred = Credential(string=cred)
36
37         #log the call
38         if not origin_hrn:
39             origin_hrn = user_cred.get_gid_caller().get_hrn()
40         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
41
42         # validate the cred
43         self.api.auth.check(cred, "remove")
44         self.api.auth.verify_object_permission(hrn)
45        
46         # send the call to the right manager
47         manager_base = 'sfa.managers'
48         mgr_type = self.api.config.SFA_REGISTRY_TYPE
49         manager_module = manager_base + ".registry_manager_%s" % mgr_type
50         manager = __import__(manager_module, fromlist=[manager_base])
51         return manager.remove(self.api, hrn, type, origin_hrn)