group db-related stuff in sfa/storage
[sfa.git] / sfa / methods / Remove.py
1 from sfa.util.xrn import Xrn
2 from sfa.util.method import Method
3
4 from sfa.trust.credential import Credential
5
6 from sfa.storage.parameter import Parameter, Mixed
7
8 class Remove(Method):
9     """
10     Remove an object from the registry. If the object represents a PLC object,
11     then the PLC records will also be removed.
12     
13     @param cred credential string
14     @param type record type
15     @param xrn human readable name of record to remove (hrn or urn)
16
17     @return 1 if successful, faults otherwise 
18     """
19
20     interfaces = ['registry']
21     
22     accepts = [
23         Parameter(str, "Human readable name of slice to instantiate (hrn or urn)"),
24         Mixed(Parameter(str, "Credential string"),
25               Parameter(type([str]), "List of credentials")),
26         Mixed(Parameter(str, "Record type"),
27               Parameter(None, "Type not specified")),
28         ]
29
30     returns = Parameter(int, "1 if successful")
31     
32     def call(self, xrn, creds, type):
33         xrn=Xrn(xrn,type=type)
34         
35         # validate the cred
36         valid_creds = self.api.auth.checkCredentials(creds, "remove")
37         self.api.auth.verify_object_permission(xrn.get_hrn())
38
39         #log the call
40         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
41         self.api.logger.info("interface: %s\tmethod-name: %s\tcaller-hrn: %s\ttarget-urn: %s"%(
42                 self.api.interface, self.name, origin_hrn, xrn.get_urn()))
43
44         return self.api.manager.Remove(self.api, xrn)