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