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