db0fe08eecaa928b1034dbef25e053b80d1b843a
[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 # this does not sound quite right, but the best I could come up with is:
35 # if type is not specified then we expect a URN
36     def call(self, xrn, creds, type):
37         if type: hrn=xrn
38         else:    (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\tmethod-name: %s\tcaller-hrn: %s\ttarget-hrn: %s\ttype: %s"%(
47                 self.api.interface, self.name, origin_hrn, hrn, type))
48
49         manager = self.api.get_interface_manager()
50
51         return manager.remove(self.api, hrn, type)