+ self['deleted'] = True
+ self.sync(commit)
+
+ def add_site(self, site, peer_site_id, commit = True):
+ """
+ Associate a local site entry with this peer.
+ """
+
+ add = Row.add_object(Site, 'peer_site')
+ add(self, site,
+ {'peer_id': self['peer_id'],
+ 'site_id': site['site_id'],
+ 'peer_site_id': peer_site_id},
+ commit = commit)
+
+ def remove_site(self, site, commit = True):
+ """
+ Unassociate a site with this peer.
+ """
+
+ remove = Row.remove_object(Site, 'peer_site')
+ remove(self, site, commit)
+
+ def add_person(self, person, peer_person_id, commit = True):
+ """
+ Associate a local user entry with this peer.
+ """
+
+ add = Row.add_object(Person, 'peer_person')
+ add(self, person,
+ {'peer_id': self['peer_id'],
+ 'person_id': person['person_id'],
+ 'peer_person_id': peer_person_id},
+ commit = commit)
+
+ def remove_person(self, person, commit = True):
+ """
+ Unassociate a site with this peer.
+ """
+
+ remove = Row.remove_object(Person, 'peer_person')
+ remove(self, person, commit)
+
+ def add_key(self, key, peer_key_id, commit = True):
+ """
+ Associate a local key entry with this peer.
+ """
+
+ add = Row.add_object(Key, 'peer_key')
+ add(self, key,
+ {'peer_id': self['peer_id'],
+ 'key_id': key['key_id'],
+ 'peer_key_id': peer_key_id},
+ commit = commit)
+
+ def remove_key(self, key, commit = True):
+ """
+ Unassociate a key with this peer.
+ """
+
+ remove = Row.remove_object(Key, 'peer_key')
+ remove(self, key, commit)
+
+ def add_node(self, node, peer_node_id, commit = True):
+ """
+ Associate a local node entry with this peer.
+ """
+
+ add = Row.add_object(Node, 'peer_node')
+ add(self, node,
+ {'peer_id': self['peer_id'],
+ 'node_id': node['node_id'],
+ 'peer_node_id': peer_node_id},
+ commit = commit)
+
+ sites = Sites(self.api, node['site_id'], ['login_base'])
+ site = sites[0]
+ login_base = site['login_base']
+ try:
+ # attempt to manually update the 'hrn' tag with the remote prefix
+ hrn_root = self['hrn_root']
+ hrn = hostname_to_hrn(hrn_root, login_base, node['hostname'])
+ tags = {'hrn': hrn}
+ Node(self.api, node).update_tags(tags)
+ except:
+ logger.exception("Could not find out hrn on hostname=%s"%node['hostname'])
+
+ def remove_node(self, node, commit = True):
+ """
+ Unassociate a node with this peer.
+ """
+
+ remove = Row.remove_object(Node, 'peer_node')
+ remove(self, node, commit)
+ # attempt to manually update the 'hrn' tag now that the node is local
+ root_auth = self.api.config.PLC_HRN_ROOT
+ sites = Sites(self.api, node['site_id'], ['login_base'])
+ site = sites[0]
+ login_base = site['login_base']
+ hrn = hostname_to_hrn(root_auth, login_base, node['hostname'])
+ tags = {'hrn': hrn}
+ Node(self.api, node).update_tags(tags)
+
+ def add_slice(self, slice, peer_slice_id, commit = True):
+ """
+ Associate a local slice entry with this peer.
+ """
+
+ add = Row.add_object(Slice, 'peer_slice')
+ add(self, slice,
+ {'peer_id': self['peer_id'],
+ 'slice_id': slice['slice_id'],
+ 'peer_slice_id': peer_slice_id},
+ commit = commit)
+
+ def remove_slice(self, slice, commit = True):
+ """
+ Unassociate a slice with this peer.
+ """
+
+ remove = Row.remove_object(Slice, 'peer_slice')
+ remove(self, slice, commit)