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
8 from PLC.Faults import *
9 from PLC.Parameter import Parameter
10 from PLC.Storage.AlchemyObject import AlchemyObj
12 class BootState(AlchemyObj):
14 Representation of a row in the boot_states table. To use,
15 instantiate with a dict of values.
18 tablename = 'boot_states'
20 'boot_state': Parameter(str, "Boot state", max = 20, primary_key=True),
23 def validate_boot_state(self, name):
24 # Make sure name is not blank
26 raise PLCInvalidArgument, "Boot state must be specified"
28 # Make sure boot state does not alredy exist
29 conflicts = BootStates(self.api, name)
31 raise PLCInvalidArgument, "Boot state name already in use"
35 def sync(self, commit=True, validate=True):
36 AlchemyObj.sync(self, commit, validate)
37 AlchemyObj.insert(self, dict(self))
39 def delete(self, commit=True):
40 assert 'boot_state' in self
41 AlchemyObj.delete(self, dict(self))
43 class BootStates(list):
45 Representation of the boot_states table in the database.
48 def __init__(self, api, filter = None):
50 boot_states = BootState().select()
51 elif isinstance(filter, StringTypes) or isinstance(filter, (list, tuple, set)):
52 boot_states = BootState().select(filter={'boot_state': filter})
54 raise PLCInvalidArgument, "Wrong boot state filter %r" % filter
56 for boot_state in boot_states:
57 self.append(boot_state)