a little nicer wrt pep8
[sfa.git] / sfa / methods / Remove.py
1 from sfa.util.xrn import Xrn
2 from sfa.util.method import Method
3 from sfa.util.sfalogging import logger
4
5 from sfa.trust.credential import Credential
6
7 from sfa.storage.parameter import Parameter, Mixed
8
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         xrn = Xrn(xrn, type=type)
36
37         # validate the cred
38         valid_creds = self.api.auth.checkCredentials(creds, "remove")
39         self.api.auth.verify_object_permission(xrn.get_hrn())
40
41         # log the call
42         origin_hrn = Credential(
43             string=valid_creds[0]).get_gid_caller().get_hrn()
44         logger.info("interface: %s\tmethod-name: %s\tcaller-hrn: %s\ttarget-urn: %s" % (
45                     self.api.interface, self.name, origin_hrn, xrn.get_urn()))
46
47         return self.api.manager.Remove(self.api, xrn)