X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FBootStates.py;h=2bbcf0de3f8e125edb2f9e7b01eeecada6b97467;hb=9aecb8c6fde06136bef94e2fd6fce832dc3c0c10;hp=fc9a578ff3fc3d225e637022234f6700c4482662;hpb=0bb08c2256514d0091d05a5e2a5e19e963a59358;p=plcapi.git diff --git a/PLC/BootStates.py b/PLC/BootStates.py index fc9a578..2bbcf0d 100644 --- a/PLC/BootStates.py +++ b/PLC/BootStates.py @@ -4,8 +4,6 @@ # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id: BootStates.py,v 1.1 2006/10/10 20:24:06 mlhuang Exp $ -# from PLC.Faults import * from PLC.Parameter import Parameter @@ -19,55 +17,35 @@ class BootState(Row): table_name = 'boot_states' primary_key = 'boot_state' + join_tables = ['nodes'] fields = { 'boot_state': Parameter(str, "Boot state", max = 20), } - def __init__(self, api, fields = {}): - Row.__init__(self, fields) - self.api = api - def validate_boot_state(self, name): - # Remove leading and trailing spaces - name = name.strip() - - # Make sure name is not blank after we removed the spaces - if not 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]) + + # Make sure boot state does not already exist + conflicts = BootStates(self.api, [name]) if conflicts: raise PLCInvalidArgument, "Boot state name already in use" - return name + return name - def delete(self, commit = True): - assert 'boot_state' in self - - # Clean up miscellaneous join tables - for table in ['nodes', 'boot_states']: - self.api.db.do("DELETE FROM " + table + \ - " WHERE boot_state = %(boot_state)s", - self) - - if commit: - self.api.db.commit() - class BootStates(Table): """ Representation of the boot_states table in the database. """ - def __init__(self, api, names = None): + def __init__(self, api, boot_states = None): + Table.__init__(self, api, BootState) + sql = "SELECT %s FROM boot_states" % \ ", ".join(BootState.fields) - - if names: - # Separate the list into integers and strings - sql += " WHERE boot_state IN (%s)" % ", ".join(api.db.quote(names)) - rows = api.db.selectall(sql) + if boot_states: + sql += " WHERE boot_state IN (%s)" % ", ".join( [ api.db.quote (s) for s in boot_states ] ) - for row in rows: - self[row['boot_state']] = BootState(api, row) + self.selectall(sql)