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