+# $Id$
+# $URL$
#
# Thierry Parmentelat - INRIA
#
from PLC.Filter import Filter
from PLC.Table import Row, Table
import PLC.Auth
-
+from PLC.Shell import *
from PLC.Sites import Site, Sites
from PLC.Persons import Person, Persons
from PLC.Keys import Key, Keys
from PLC.Nodes import Node, Nodes
-from PLC.SliceAttributeTypes import SliceAttributeType, SliceAttributeTypes
-from PLC.SliceAttributes import SliceAttribute, SliceAttributes
+from PLC.TagTypes import TagType, TagTypes
+from PLC.SliceTags import SliceTag, SliceTags
from PLC.Slices import Slice, Slices
class Peer(Row):
table_name = 'peers'
primary_key = 'peer_id'
- join_tables = ['peer_site', 'peer_person', 'peer_key', 'peer_node',
- 'peer_slice_attribute_type', 'peer_slice_attribute', 'peer_slice']
+ join_tables = ['peer_site', 'peer_person', 'peer_key', 'peer_node', 'peer_slice']
fields = {
- 'peer_id': Parameter (int, "Peer identifier"),
- 'peername': Parameter (str, "Peer name"),
- 'peer_url': Parameter (str, "Peer API URL"),
- 'key': Parameter(str, "Peer GPG public key"),
- 'cacert': Parameter(str, "Peer SSL public certificate"),
+ 'peer_id': Parameter (int, "Peer identifier"),
+ 'peername': Parameter (str, "Peer name"),
+ 'peer_url': Parameter (str, "Peer API URL"),
+ 'key': Parameter(str, "Peer GPG public key"),
+ 'cacert': Parameter(str, "Peer SSL public certificate"),
+ 'shortname' : Parameter(str, "Peer short name"),
+ 'hrn_root' : Parameter(str, "Root of this peer in a hierarchical naming space"),
### cross refs
'site_ids': Parameter([int], "List of sites for which this peer is authoritative"),
'person_ids': Parameter([int], "List of users for which this peer is authoritative"),
return peername
def validate_peer_url(self, url):
- """
- Validate URL. Must be HTTPS.
- """
+ """
+ Validate URL. Must be HTTPS.
+ """
(scheme, netloc, path, params, query, fragment) = urlparse(url)
if scheme != "https":
raise PLCInvalidArgument, "Peer URL scheme must be https"
-
+ if path[-1] != '/':
+ raise PLCInvalidArgument, "Peer URL should end with /"
+
return url
def delete(self, commit = True):
- """
- Deletes this peer and all related entities.
- """
+ """
+ Deletes this peer and all related entities.
+ """
- assert 'peer_id' in self
+ assert 'peer_id' in self
# Remove all related entities
for obj in \
- Slices(self.api, self['slice_ids'], peer_id = self['peer_id']) + \
- Keys(self.api, self['key_ids'], peer_id = self['peer_id']) + \
- Persons(self.api, self['person_ids'], peer_id = self['peer_id']) + \
- Nodes(self.api, self['node_ids'], peer_id = self['peer_id']) + \
- Sites(self.api, self['site_ids'], peer_id = self['peer_id']):
+ Slices(self.api, self['slice_ids']) + \
+ Keys(self.api, self['key_ids']) + \
+ Persons(self.api, self['person_ids']) + \
+ Nodes(self.api, self['node_ids']) + \
+ Sites(self.api, self['site_ids']):
assert obj['peer_id'] == self['peer_id']
obj.delete(commit = False)
# Mark as deleted
- self['deleted'] = True
- self.sync(commit)
+ self['deleted'] = True
+ self.sync(commit)
def add_site(self, site, peer_site_id, commit = True):
"""
'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.
'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):
"""
'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.
'peer_node_id': peer_node_id},
commit = commit)
- def add_slice_attribute_type(self, slice_attribute_type, peer_attribute_type_id, commit = True):
- """
- Associate a local slice attribute type entry with this peer.
- """
-
- add = Row.add_object(SliceAttributeType, 'peer_slice_attribute_type')
- add(self, slice_attribute_type,
- {'peer_id': self['peer_id'],
- 'attribute_type_id': slice_attribute_type['attribute_type_id'],
- 'peer_attribute_type_id': peer_attribute_type_id},
- commit = commit)
+ # calling UpdateNode with the node's hostname
+ # will force the 'hrn' tag to be updated with the
+ # correct root auth
+ shell = Shell()
+ UpdateNode = self.api.callable('UpdateNode')
+ UpdateNode(shell.auth, node['node_id'], {'hostname': node['hostname']})
- def add_slice_attribute(self, slice_attribute, peer_slice_attribute_id, commit = True):
+ def remove_node(self, node, commit = True):
"""
- Associate a local slice_attribute entry with this peer.
+ Unassociate a node with this peer.
"""
+
+ remove = Row.remove_object(Node, 'peer_node')
+ remove(self, node, commit)
- add = Row.add_object(SliceAttribute, 'peer_slice_attribute')
- add(self, slice_attribute,
- {'peer_id': self['peer_id'],
- 'slice_attribute_id': slice_attribute['slice_attribute_id'],
- 'peer_slice_attribute_id': peer_slice_attribute_id},
- commit = commit)
+ # calling UpdateNode with the node's hostname
+ # will force the 'hrn' tag to be updated with the
+ # correct root auth
+ shell = Shell()
+ UpdateNode = self.api.callable('UpdateNode')
+ UpdateNode(shell.auth, node['node_id'], {'hostname': node['hostname']})
def add_slice(self, slice, peer_slice_id, commit = True):
"""
'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)
+
def connect(self, **kwds):
"""
Connect to this peer via XML-RPC.
def wrapper(*args, **kwds):
from PLC.GPG import gpg_sign
- signature = gpg_sign(methodname, args,
+ signature = gpg_sign(args,
self.api.config.PLC_ROOT_GPG_KEY,
- self.api.config.PLC_ROOT_GPG_KEY_PUB)
+ self.api.config.PLC_ROOT_GPG_KEY_PUB,
+ methodname)
auth = {'AuthMethod': "gpg",
'name': self.api.config.PLC_NAME,
ints = filter(lambda x: isinstance(x, (int, long)), peer_filter)
strs = filter(lambda x: isinstance(x, StringTypes), peer_filter)
peer_filter = Filter(Peer.fields, {'peer_id': ints, 'peername': strs})
- sql += " AND (%s)" % peer_filter.sql(api, "OR")
+ sql += " AND (%s) %s" % peer_filter.sql(api, "OR")
elif isinstance(peer_filter, dict):
peer_filter = Filter(Peer.fields, peer_filter)
- sql += " AND (%s)" % peer_filter.sql(api, "AND")
+ sql += " AND (%s) %s" % peer_filter.sql(api, "AND")
self.selectall(sql)