2 # Functions for interacting with the boot_states table in the database
4 # Mark Huang <mlhuang@cs.princeton.edu>
5 # Copyright (C) 2006 The Trustees of Princeton University
7 # $Id: BootStates.py,v 1.5 2006/10/20 17:43:55 mlhuang Exp $
10 from PLC.Faults import *
11 from PLC.Parameter import Parameter
12 from PLC.Table import Row, Table
16 Representation of a row in the boot_states table. To use,
17 instantiate with a dict of values.
20 table_name = 'boot_states'
21 primary_key = 'boot_state'
22 join_tables = ['nodes']
24 'boot_state': Parameter(str, "Boot state", max = 20),
27 def validate_boot_state(self, name):
28 # Make sure name is not blank
30 raise PLCInvalidArgument, "Boot state must be specified"
32 # Make sure boot state does not alredy exist
33 conflicts = BootStates(self.api, [name])
35 raise PLCInvalidArgument, "Boot state name already in use"
39 class BootStates(Table):
41 Representation of the boot_states table in the database.
44 def __init__(self, api, names = None):
45 sql = "SELECT %s FROM boot_states" % \
46 ", ".join(BootState.fields)
49 # Separate the list into integers and strings
50 sql += " WHERE boot_state IN (%s)" % ", ".join(api.db.quote(names))
52 rows = api.db.selectall(sql)
55 self[row['boot_state']] = BootState(api, row)