2 # Functions for interacting with the slice_instantiations table in the database
4 # Mark Huang <mlhuang@cs.princeton.edu>
5 # Copyright (C) 2006 The Trustees of Princeton University
10 from PLC.Faults import *
11 from PLC.Parameter import Parameter
12 from PLC.Table import Row, Table
14 class SliceInstantiation(Row):
16 Representation of a row in the slice_instantiations table. To use,
17 instantiate with a dict of values.
20 table_name = 'slice_instantiations'
21 primary_key = 'instantiation'
22 join_tables = ['slices']
24 'instantiation': Parameter(str, "Slice instantiation state", max = 100),
27 def validate_instantiation(self, instantiation):
28 # Make sure name is not blank
29 if not len(instantiation):
30 raise PLCInvalidArgument, "Slice instantiation state name must be specified"
32 # Make sure slice instantiation does not alredy exist
33 conflicts = SliceInstantiations(self.api, [instantiation])
35 raise PLCInvalidArgument, "Slice instantiation state name already in use"
39 class SliceInstantiations(Table):
41 Representation of the slice_instantiations table in the database.
44 def __init__(self, api, instantiations = None):
45 Table.__init__(self, api, SliceInstantiation)
47 sql = "SELECT %s FROM slice_instantiations" % \
48 ", ".join(SliceInstantiation.fields)
51 sql += " WHERE instantiation IN (%s)" % ", ".join(map(api.db.quote, instantiations))