iteration 4 & last:
[plcapi.git] / PLC / Nodes.py
index ae2a5e7..bf460ca 100644 (file)
@@ -4,7 +4,7 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id: Nodes.py,v 1.19 2006/11/09 03:07:42 mlhuang Exp $
+# $Id: Nodes.py,v 1.20 2006/11/09 19:43:55 mlhuang Exp $
 #
 
 from types import StringTypes
@@ -43,6 +43,7 @@ class Node(Row):
         'node_id': Parameter(int, "Node identifier"),
         'hostname': Parameter(str, "Fully qualified hostname", max = 255),
         'site_id': Parameter(int, "Site at which this node is located"),
+        'peer_id': Parameter(int, "Peer at which this node is managed", nullok = True),
         'boot_state': Parameter(str, "Boot state", max = 20),
         'model': Parameter(str, "Make and model of the actual machine", max = 255, nullok = True),
         'boot_nonce': Parameter(str, "(Admin only) Random value generated by the node at last boot", max = 128),
@@ -61,6 +62,12 @@ class Node(Row):
         'ports': Parameter([int], "List of PCU ports that this node is connected to"),
         }
 
+    # foreign attributes management
+    # the key to track remote objects
+    foreign_key = 'hostname'
+    # the fields that get verbatim copied from foreign objects
+    foreign_fields = ['boot_state','model','version','date_created','last_updated']
+
     def validate_hostname(self, hostname):
         if not valid_hostname(hostname):
             raise PLCInvalidArgument, "Invalid hostname"
@@ -95,13 +102,14 @@ class Node(Row):
         self['deleted'] = True
         self.sync(commit)
 
+
 class Nodes(Table):
     """
     Representation of row(s) from the nodes table in the
     database.
     """
 
-    def __init__(self, api, node_filter = None, columns = None):
+    def __init__(self, api, node_filter = None, columns = None, scope = 'all'):
         Table.__init__(self, api, Node, columns)
 
         sql = "SELECT %s FROM view_nodes WHERE deleted IS False" % \
@@ -118,4 +126,10 @@ class Nodes(Table):
                 node_filter = Filter(Node.fields, node_filter)
                 sql += " AND (%s)" % node_filter.sql(api, "AND")
 
+        if scope == 'local':
+            sql += " AND (peer_id is NULL) "
+        elif scope == 'foreign':
+            sql += " AND (peer_id is NOT NULL) "
+
         self.selectall(sql)
+