revert accidental (too early) checkin
[plcapi.git] / PLC / Peers.py
index ed62c99..866b41b 100644 (file)
@@ -28,8 +28,6 @@ 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']
     fields = {
        'peer_id': Parameter (int, "Peer identifier"),
        'peername': Parameter (str, "Peer name"),
@@ -37,24 +35,15 @@ class Peer(Row):
        'key': Parameter(str, "Peer GPG public key"),
        'cacert': Parameter(str, "Peer SSL public certificate"),
         ### 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"),
+        'site_ids': Parameter([int], "List of sites for this peer is authoritative"),
+        'person_ids': Parameter([int], "List of users for this peer is authoritative"),
         'key_ids': Parameter([int], "List of keys for which this peer is authoritative"),
         'node_ids': Parameter([int], "List of nodes for which this peer is authoritative"),
+        'attribute_type_ids': Parameter([int], "List of slice attribute types for which this peer is authoritative"),
+        'slice_attribute_ids': Parameter([int], "List of slice attributes for which this peer is authoritative"),
         'slice_ids': Parameter([int], "List of slices for which this peer is authoritative"),
        }
 
-    def validate_peername(self, peername):
-        if not len(peername):
-            raise PLCInvalidArgument, "Peer name must be specified"
-
-        conflicts = Peers(self.api, [peername])
-        for peer in conflicts:
-            if 'peer_id' not in self or self['peer_id'] != peer['peer_id']:
-                raise PLCInvalidArgument, "Peer name already in use"
-
-        return peername
-
     def validate_peer_url(self, url):
        """
        Validate URL. Must be HTTPS.
@@ -75,11 +64,13 @@ class Peer(Row):
 
         # 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']):
+                Sites(self.api, self['site_ids']) + \
+                Persons(self.api, self['person_ids']) + \
+                Keys(self.api, self['key_ids']) + \
+                Nodes(self.api, self['node_ids']) + \
+                SliceAttributeTypes(self.api, self['attribute_type_ids']) + \
+                SliceAttributes(self.api, self['slice_attribute_ids']) + \
+                Slices(self.api, self['slice_ids']):
             assert obj['peer_id'] == self['peer_id']
             obj.delete(commit = False)
 
@@ -87,90 +78,6 @@ class Peer(Row):
        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 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 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 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)
-
-    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)
-
-    def add_slice_attribute(self, slice_attribute, peer_slice_attribute_id, commit = True):
-        """
-        Associate a local slice_attribute entry with this peer.
-        """
-
-        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)
-
-    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 connect(self, **kwds):
         """
         Connect to this peer via XML-RPC.
@@ -205,33 +112,27 @@ class Peer(Row):
 
         return wrapper
 
-    def __getattr__(self, attr):
+    def __getattr__(self, methodname):
         """
-        Returns a callable API function if attr is the name of a
-        PLCAPI function; otherwise, returns the specified attribute.
+        Fetch a callable for the specified method.
         """
 
+        function = getattr(self.server, methodname)
+
         try:
-            # Figure out if the specified attribute is the name of a
-            # PLCAPI function. If so and the function requires an
-            # authentication structure as its first argument, return a
-            # callable that automagically adds an auth struct to the
-            # call.
-            methodname = attr
+            # Figure out if the function is a PLCAPI function and
+            # requires an authentication structure as its first
+            # argument.
             api_function = self.api.callable(methodname)
             if api_function.accepts and \
                (isinstance(api_function.accepts[0], PLC.Auth.Auth) or \
                 (isinstance(api_function.accepts[0], Mixed) and \
-                 filter(lambda param: isinstance(param, Auth), api_function.accepts[0]))):
-                function = getattr(self.server, methodname)
-                return self.add_auth(function, methodname)
+                 filter(lambda param: isinstance(param, Auth), func.accepts[0]))):
+                function = self.add_auth(function, methodname)
         except Exception, err:
             pass
 
-        if hasattr(self, attr):
-            return getattr(self, attr)
-        else:
-            raise AttributeError, "type object 'Peer' has no attribute '%s'" % attr
+        return function
 
 class Peers (Table):
     """