4 from sfa.util.faults import *
5 from sfa.util.method import Method
6 from sfa.util.parameter import Parameter, Mixed
7 from sfa.trust.auth import Auth
8 from sfa.util.record import GeniRecord
9 from sfa.util.genitable import GeniTable
10 from sfa.util.debug import log
11 from sfa.trust.credential import Credential
12 from sfa.server.registry import Registries
16 Remove an object from the registry. If the object represents a PLC object,
17 then the PLC records will also be removed.
19 @param cred credential string
20 @param type record type
21 @param hrn human readable name of record to remove
23 @return 1 if successful, faults otherwise
26 interfaces = ['registry']
29 Parameter(str, "Credential string"),
30 Parameter(str, "Record type"),
31 Parameter(str, "Human readable name (hrn) of record to be removed")
34 returns = Parameter(int, "1 if successful")
36 def call(self, cred, type, hrn, caller_cred=None):
37 self.api.auth.check(cred, "remove")
42 self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, Credential(string=caller_cred).get_gid_caller().get_hrn(), hrn, self.name))
43 self.api.auth.verify_object_permission(hrn)
46 if type not in ['all', '*']:
48 records = table.find(filter)
50 raise RecordNotFound(hrn)
54 credential = self.api.getCredential()
55 registries = Registries(self.api)
56 # Try to remove the object from the PLCDB of federated agg.
57 # This is attempted before removing the object from the local agg's PLCDB and sfa table
58 if hrn.startswith(self.api.hrn) and type in ['user', 'slice', 'authority']:
59 for registry in registries:
60 if registry not in [self.api.hrn]:
61 result=registries[registry].remove_remote_object(credential, hrn, record)
63 persons = self.api.plshell.GetPersons(self.api.plauth, record['pointer'])
64 # only delete this person if he has site ids. if he doesnt, it probably means
65 # he was just removed from a site, not actually deleted
66 if persons and persons[0]['site_ids']:
67 self.api.plshell.DeletePerson(self.api.plauth, record['pointer'])
69 if self.api.plshell.GetSlices(self.api.plauth, record['pointer']):
70 self.api.plshell.DeleteSlice(self.api.plauth, record['pointer'])
72 if self.api.plshell.GetNodes(self.api.plauth, record['pointer']):
73 self.api.plshell.DeleteNode(self.api.plauth, record['pointer'])
74 elif type == "authority":
75 if self.api.plshell.GetSites(self.api.plauth, record['pointer']):
76 self.api.plshell.DeleteSite(self.api.plauth, record['pointer'])
78 raise UnknownGeniType(type)
82 # forward the call after replacing the root hrn