sfadump more usable
[sfa.git] / sfa / methods / Remove.py
1 ### $Id: remove.py 16497 2010-01-07 03:33:24Z tmack $
2 ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/remove.py $
3
4 from sfa.util.faults import *
5 from sfa.util.namespace import urn_to_hrn
6 from sfa.util.method import Method
7 from sfa.util.parameter import Parameter, Mixed
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 xrn human readable name of record to remove (hrn or urn)
18
19     @return 1 if successful, faults otherwise 
20     """
21
22     interfaces = ['registry']
23     
24     accepts = [
25         Parameter(str, "Human readable name of slice to instantiate (hrn or urn)"),
26         Mixed(Parameter(str, "Credential string"),
27               Parameter(type([str]), "List of credentials")),
28         Mixed(Parameter(str, "Record type"),
29               Parameter(None, "Type not specified")),
30         ]
31
32     returns = Parameter(int, "1 if successful")
33     
34     def call(self, xrn, creds, type):
35         if not type:
36             hrn = urn_to_hrn(xrn)[0]
37         else: 
38             hrn, type = urn_to_hrn(xrn)
39         
40         # validate the cred
41         valid_creds = self.api.auth.checkCredentials(creds, "remove")
42         self.api.auth.verify_object_permission(hrn)
43
44         #log the call
45         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
46         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
47
48
49         manager = self.api.get_interface_manager()
50
51         return manager.remove(self.api, xrn, type)