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