adding new table definition
authorTony Mack <tmack@paris.CS.Princeton.EDU>
Sat, 9 Mar 2013 02:52:47 +0000 (21:52 -0500)
committerTony Mack <tmack@paris.CS.Princeton.EDU>
Sat, 9 Mar 2013 02:52:47 +0000 (21:52 -0500)
PLC/NodeNodeGroup.py [new file with mode: 0644]

diff --git a/PLC/NodeNodeGroup.py b/PLC/NodeNodeGroup.py
new file mode 100644 (file)
index 0000000..77fa639
--- /dev/null
@@ -0,0 +1,61 @@
+from types import StringTypes
+import time
+import re
+import datetime
+
+from PLC.Faults import *
+from PLC.Parameter import Parameter, Mixed
+from PLC.Filter import Filter
+from PLC.Debug import profile
+from PLC.Timestamp import Timestamp
+from PLC.Storage.AlchemyObject import AlchemyObj
+
+class NodeNodeGroup(AlchemyObj):
+    """
+    Representation of a row in the node_nodegroup table. To use, optionally
+    instantiate with a dict of values. Update as you would a
+    dict. Commit to the database with sync().To use, instantiate
+    with a dict of values.
+    """
+
+    tablename = 'node_nodegroup'
+    fields = {
+        'nodegroup_id': Parameter(int, "Nodegroup identifier", primary_key=True),
+        'node_id': Parameter(int, "Node identifier", indexed=True),
+        }
+
+    tags = {}
+
+    def sync(self, commit = True, validate=True):
+        """
+        Add the record
+        """
+        AlchemyObj.sync(self, commit, validate)
+        AlchemyObj.insert(self, dict(self))
+
+    def delete(self, commit = True):
+        """
+        Delete existing slice.
+        """
+        AlchemyObj.delete(self, dict(self))
+
+
+class NodeNodeGroups(list):
+    """
+    Representation of row(s) from the node_nodegroup table in the
+    database.
+    """
+
+    def __init__(self, api, filter = None, columns = None):
+         
+        # the view that we're selecting upon: start with view_slices
+        if not filter:
+            node_nodegroups = NodeNodeGroup().select()
+        elif isinstance(filter, dict):
+            node_nodegroups = NodeNodeGroup().select(filter=filter)
+        else:
+            raise PLCInvalidArgument, "Wrong node_nodegroup filter %r"%filter
+
+        for node_nodegroup in node_nodegroups:
+            self.append(node_nodegroup)