1 from sfa.util.faults import *
2 from sfa.util.method import Method
3 from sfa.util.parameter import Parameter, Mixed
4 from sfa.trust.auth import Auth
5 from sfa.util.record import GeniRecord
6 from sfa.util.genitable import GeniTable
7 from sfa.util.debug import log
8 from sfa.trust.credential import Credential
9 from sfa.util.misc import *
10 from types import StringTypes
12 class remove_remote_object(Method):
14 Remove an object from the PLC records of a federated aggregate.
15 This method will be called by registry.remove() while removing
16 a record from the local aggreage's PLCDB and sfa table. This
17 method need not be directly called by end-user.
19 @param cred credential string
20 @param hrn human readbale name of record to be removed
21 @param record record as stored in the authoritative registry
23 @return 1 if successful, faults otherwise
26 interfaces = ['registry']
29 Parameter(str, "Credential string"),
30 Parameter(str, "Human readable name (hrn) of record to be removed"),
31 Parameter(dict, "Record dictionary as stored in the authoritative registry")
34 returns = Parameter(int, "1 if successful")
36 def call(self, cred, hrn, record, 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)
45 peer=self.get_peer(hrn)
48 peer_records = self.api.plshell.GetPersons(self.api.plauth, {'peer_person_id' : record['pointer']})
51 peer_record=peer_records[0]
52 self.api.plshell.UnBindObjectFromPeer(self.api.plauth, 'person', peer_record['person_id'], peer)
53 self.api.plshell.DeletePerson(self.api.plauth, peer_record['person_id'])
55 peer_records=self.api.plshell.GetSlices(self.api.plauth, {'peer_slice_id' : record['pointer']})
58 peer_record=peer_records[0]
59 self.api.plshell.UnBindObjectFromPeer(self.api.plauth, 'slice', peer_record['slice_id'], peer)
60 self.api.plshell.DeleteSlice(self.api.plauth, peer_record['slice_id'])
61 elif type == "authority":
62 peer_records=self.api.plshell.GetSites(self.api.plauth, {'peer_site_id' : record['pointer']})
65 peer_record=peer_records[0]
66 self.api.plshell.UnBindObjectFromPeer(self.api.plauth, 'site', peer_record['site_id'], peer)
67 self.api.plshell.DeleteSite(self.api.plauth, peer_record['site_id'])
69 raise UnknownGeniType(type)
74 # Remove objects from remote agg. where no RefreshPeer Federation exists
75 # yet to figure out the mechanism to identify the correct object in the PLCDB
76 # on the remote aggregate
79 def get_peer(self, hrn):
80 # Becaues of myplc federation, we first need to determine if this
81 # slice belongs to out local plc or a myplc peer. We will assume it
82 # is a local site, unless we find out otherwise
84 # get this slice's authority (site)
85 slice_authority = get_authority(hrn)
87 # get this site's authority (sfa root authority or sub authority)
88 site_authority = get_authority(slice_authority).lower()
89 if not site_authority:
90 site_authority = slice_authority
92 # check if we are already peered with this site_authority, if so
93 peers = self.api.plshell.GetPeers(self.api.plauth, {}, ['peer_id', 'peername', 'shortname', 'hrn_root'])
94 for peer_record in peers:
95 names = [name.lower() for name in peer_record.values() if isinstance(name, StringTypes)]
96 if site_authority in names:
97 peer = peer_record['shortname']