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