X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FSliceInstantiations.py;h=843b3270ab8f2a82141e83bbc99c57d9534738d1;hb=d016b01f1145899e697f1f49233710bb464d438c;hp=7b4b2a438a1d16f2ccb574398cef91f12e7437c0;hpb=71b475e73b5130b95d636148a8c92c95268d79e1;p=plcapi.git diff --git a/PLC/SliceInstantiations.py b/PLC/SliceInstantiations.py index 7b4b2a4..843b327 100644 --- a/PLC/SliceInstantiations.py +++ b/PLC/SliceInstantiations.py @@ -4,16 +4,50 @@ # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id: SliceInstantiations.py,v 1.1 2006/09/06 15:36:07 mlhuang Exp $ +# $Id: SliceInstantiations.py,v 1.2 2006/10/03 19:27:28 mlhuang Exp $ # -class SliceInstantiations(list): +from PLC.Faults import * +from PLC.Parameter import Parameter +from PLC.Table import Row, Table + +class SliceInstantiation(Row): + """ + Representation of a row in the slice_instantiations table. To use, + instantiate with a dict of values. + """ + + table_name = 'slice_instantiations' + primary_key = 'instantiation' + join_tables = ['slices'] + fields = { + 'instantiation': Parameter(str, "Slice instantiation state", max = 100), + } + + def validate_instantiation(self, instantiation): + # Make sure name is not blank + if not len(instantiation): + raise PLCInvalidArgument, "Slice instantiation state name must be specified" + + # Make sure slice instantiation does not alredy exist + conflicts = SliceInstantiations(self.api, [instantiation]) + if conflicts: + raise PLCInvalidArgument, "Slice instantiation state name already in use" + + return instantiation + +class SliceInstantiations(Table): """ Representation of the slice_instantiations table in the database. """ - def __init__(self, api): - sql = "SELECT * FROM slice_instantiations" + def __init__(self, api, instantiations = None): + Table.__init__(self, api, SliceInstantiation) + + sql = "SELECT %s FROM slice_instantiations" % \ + ", ".join(SliceInstantiation.fields) + + if instantiations: + sql += " WHERE instantiation IN (%s)" % ", ".join(map(api.db.quote, instantiations)) - for row in api.db.selectall(sql): - self.append[row['instantiation']] + self.selectall(sql)