Merge remote-tracking branch 'origin/pycurl' into planetlab-4_0-branch
[plcapi.git] / PLC / BootStates.py
index 6757ca1..014b61a 100644 (file)
@@ -4,7 +4,7 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id: BootStates.py,v 1.4 2006/10/10 21:54:20 mlhuang Exp $
+# $Id: BootStates.py 5574 2007-10-25 20:33:17Z thierry $
 #
 
 from PLC.Faults import *
@@ -25,11 +25,8 @@ class BootState(Row):
         }
 
     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
@@ -44,15 +41,13 @@ 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(map(api.db.quote, boot_states))
 
-        for row in rows:
-            self[row['boot_state']] = BootState(api, row)
+        self.selectall(sql)