- def __init__(self, api):
- sql = "SELECT * FROM node_bootstates"
-
- for row in api.db.selectall(sql):
- self.append(row['boot_state'])
+ 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)
+
+ if boot_states:
+ sql += " WHERE boot_state IN (%s)" % ", ".join( [ api.db.quote (s) for s in boot_states ] )
+
+ self.selectall(sql)