Avoid a second remctl to determine whether ice3 is up
authorEric Price <ecprice@mit.edu>
Mon, 2 Jun 2008 05:48:27 +0000 (01:48 -0400)
committerEric Price <ecprice@mit.edu>
Mon, 2 Jun 2008 05:48:27 +0000 (01:48 -0400)
svn path=/trunk/packages/sipb-xen-www/; revision=554

code/controls.py
code/main.py
code/webcommon.py

index 79aa311..e389823 100644 (file)
@@ -137,13 +137,11 @@ def createVm(owner, contact, name, memory, disk_size, machine_type, cdrom, clone
     bootMachine(machine, cdrom)
     return machine
 
-def getList(machines):
-    """Return a dictionary mapping machine  to dicts."""
+def getList():
+    """Return a dictionary mapping machine names to dicts."""
     value_string = remctl('web', 'listvms')
     value_dict = yaml.safe_load(value_string)
-
-    d = dict((m, value_dict[m.name]) for m in machines if m.name in value_dict)
-    return d
+    return value_dict
 
 def parseStatus(s):
     """Parse a status string into nested tuples of strings.
index 60c2818..c7dff0e 100755 (executable)
@@ -203,7 +203,7 @@ def getListDict(user):
     has_vnc = {}
     xmlist = g.xmlist
     checkpoint.checkpoint('Got uptimes')
-    can_clone = (controls.getList([Machine.get_by(name='ice3')])) == {}
+    can_clone = 'ice3' in g.xmlist_raw
     for m in machines:
         if m not in xmlist:
             has_vnc[m] = 'Off'
index ee9bb73..58d9333 100644 (file)
@@ -43,8 +43,11 @@ class Global(object):
 
     machines = cachedproperty(lambda self:
                                   Machine.query().join('acl').select_by(user=self.user))
+    xmlist_raw = cachedproperty(lambda self: controls.getList())
     xmlist = cachedproperty(lambda self:
-                                controls.getList(self.machines))
+                                dict((m, self.xmlist_raw[m.name])
+                                     for m in self.machines
+                                     if m.name in self.xmlist_raw))
 
     def clear(self):
         """Clear the state so future accesses reload it."""