X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FBootStates.py;h=42a5214d97a24f57c95907c206d55a47fa0229b1;hb=d8fca496b2ad500c6778c60164bb2e1478ae8dcd;hp=cabf4fca2693d1005402ff3ac84ba835516bab6c;hpb=369bddedd50b4f9a3e779e09d67fdfb9a2fbd086;p=plcapi.git diff --git a/PLC/BootStates.py b/PLC/BootStates.py index cabf4fc..42a5214 100644 --- a/PLC/BootStates.py +++ b/PLC/BootStates.py @@ -1,19 +1,53 @@ # -# Functions for interacting with the node_bootstates table in the database +# Functions for interacting with the boot_states table in the database # # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id: BootStates.py,v 1.2 2006/09/25 14:48:07 mlhuang Exp $ +# $Id: BootStates.py,v 1.6 2006/10/24 20:02:22 mlhuang Exp $ # -class BootStates(list): +from PLC.Faults import * +from PLC.Parameter import Parameter +from PLC.Table import Row, Table + +class BootState(Row): """ - Representation of the node_bootstates table in the database. + Representation of a row in the boot_states table. To use, + instantiate with a dict of values. """ - def __init__(self, api): - sql = "SELECT * FROM boot_states" + table_name = 'boot_states' + primary_key = 'boot_state' + join_tables = ['nodes'] + fields = { + 'boot_state': Parameter(str, "Boot state", max = 20), + } + + def validate_boot_state(self, name): + # Make sure name is not blank + if not len(name): + raise PLCInvalidArgument, "Boot state must be specified" + + # Make sure boot state does not alredy exist + conflicts = BootStates(self.api, [name]) + if conflicts: + raise PLCInvalidArgument, "Boot state name already in use" + + return name + +class BootStates(Table): + """ + Representation of the boot_states table in the database. + """ + + def __init__(self, api, boot_states = None): + Table.__init__(self, api, BootState) + + sql = "SELECT %s FROM boot_states" % \ + ", ".join(BootState.fields) - for row in api.db.selectall(sql): - self.append(row['boot_state']) + if boot_states: + sql += " WHERE boot_state IN (%s)" % ", ".join(map(api.db.quote, boot_states)) + + self.selectall(sql)