Initial checkin
authorTony Mack <tmack@paris.CS.Princeton.EDU>
Tue, 12 Mar 2013 23:07:12 +0000 (19:07 -0400)
committerTony Mack <tmack@paris.CS.Princeton.EDU>
Tue, 12 Mar 2013 23:07:12 +0000 (19:07 -0400)
PLC/SliceInstances.py [new file with mode: 0644]

diff --git a/PLC/SliceInstances.py b/PLC/SliceInstances.py
new file mode 100644 (file)
index 0000000..b21dcc9
--- /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 SliceInstance(AlchemyObj):
+    """
+    Representation of a row in the slice_node 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 = 'slice_instance'
+    fields = {
+        'slice_id': Parameter(int, "Slice identifier", primary_key=True),
+        'instance_id': Parameter(str, "Instance 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 SliceInstances(list):
+    """
+    Representation of row(s) from the slices 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:
+            slice_instances = SliceInstance().select()
+        elif isinstance(filter, dict):
+            slices_instances = SliceInstance().select(filter=filter)
+        else:
+            raise PLCInvalidArgument, "Wrong slice_instance filter %r"%filter
+
+        for slice_instance in slice_instances:
+            self.append(slice_instance)