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
8 from PLC.Faults import *
9 from PLC.Parameter import Parameter
10 from PLC.Table import Row, Table
12 class SliceInstantiation(Row):
14 Representation of a row in the slice_instantiations table. To use,
15 instantiate with a dict of values.
18 table_name = 'slice_instantiations'
19 primary_key = 'instantiation'
20 join_tables = ['slices']
22 'instantiation': Parameter(str, "Slice instantiation state", max = 100),
25 def validate_instantiation(self, instantiation):
26 # Make sure name is not blank
27 if not len(instantiation):
28 raise PLCInvalidArgument, "Slice instantiation state name must be specified"
30 # Make sure slice instantiation does not alredy exist
31 conflicts = SliceInstantiations(self.api, [instantiation])
33 raise PLCInvalidArgument, "Slice instantiation state name already in use"
37 class SliceInstantiations(Table):
39 Representation of the slice_instantiations table in the database.
42 def __init__(self, api, instantiations = None):
43 Table.__init__(self, api, SliceInstantiation)
45 sql = "SELECT %s FROM slice_instantiations" % \
46 ", ".join(SliceInstantiation.fields)
49 sql += " WHERE instantiation IN (%s)" % ", ".join( [ api.db.quote (i) for i in instantiations ] )