Index: trunk/packages/sipb-xen-www/code/main.py
===================================================================
--- trunk/packages/sipb-xen-www/code/main.py	(revision 439)
+++ trunk/packages/sipb-xen-www/code/main.py	(revision 440)
@@ -37,5 +37,6 @@
 import templates
 from Cheetah.Template import Template
-from sipb_xen_database import Machine, CDROM, ctx, connect, MachineAccess
+import sipb_xen_database
+from sipb_xen_database import Machine, CDROM, ctx, connect, MachineAccess, Type
 import validation
 from webcommon import InvalidInput, CodeError, g
@@ -72,4 +73,5 @@
         return '<p>STDERR:</p><pre>' + str(addition) + '</pre>'
 
+Template.sipb_xen_database = sipb_xen_database
 Template.helppopup = staticmethod(helppopup)
 Template.err = None
@@ -98,6 +100,6 @@
     cdrom = ''
     name = ''
-    vmtype = 'hvm'
     def __init__(self, max_memory=None, max_disk=None, **kws):
+        self.type = Type.get('linux-hvm')
         if max_memory is not None:
             self.memory = min(self.memory, max_memory)
@@ -380,4 +382,8 @@
             machine.memory = memory
 
+        vm_type = validation.validVmType(fields.getfirst('vmtype'))
+        if vm_type is not None:
+            machine.type = vm_type
+
         disksize = validation.testDisk(user, fields.getfirst('disk'))
         if disksize is not None:
@@ -561,5 +567,5 @@
     max_disk = validation.maxDisk(user, machine)
     defaults = Defaults()
-    for name in 'machine_id name administrator owner memory contact'.split():
+    for name in 'machine_id name administrator owner memory contact type'.split():
         setattr(defaults, name, getattr(machine, name))
     defaults.disk = "%0.2f" % (machine.disks[0].size/1024.)
Index: trunk/packages/sipb-xen-www/code/templates/functions.tmpl
===================================================================
--- trunk/packages/sipb-xen-www/code/templates/functions.tmpl	(revision 439)
+++ trunk/packages/sipb-xen-www/code/templates/functions.tmpl	(revision 440)
@@ -12,4 +12,14 @@
   #end for
 </select>
+#end def
+
+#def vmTypeList($default=None)
+#for $vmtype in $sipb_xen_database.Type.select()
+<label>
+   <input #slurp
+#if $default == $vmtype then 'checked' else ''
+ type="radio" name="vmtype" value="${vmtype.type_id}">${vmtype.description}</input>
+</label>
+#end for
 #end def
 
Index: trunk/packages/sipb-xen-www/code/templates/info.tmpl
===================================================================
--- trunk/packages/sipb-xen-www/code/templates/info.tmpl	(revision 439)
+++ trunk/packages/sipb-xen-www/code/templates/info.tmpl	(revision 440)
@@ -59,5 +59,4 @@
 (To edit ram, disk size, or machine name, turn off the machine first.)
 #end if
-</p>
 <form action="modify" method="POST">
   <input type="hidden" name="machine_id" value="$defaults.machine_id"/>
@@ -72,4 +71,8 @@
     <tr><td>Machine Name:</td><td><input type="text" name="name" value="$defaults.name"/></td></tr>
 $errorRow('name', $err)
+    <tr>
+      <td>HVM/ParaVM$helppopup('hvm_paravm')</td>
+      <td>$vmTypeList($defaults.type)</td>
+    </tr>
     <tr><td>Ram:</td><td><input type="text" size=3 name="memory" value="$defaults.memory"/>MiB (max $max_mem)</td></tr>
 $errorRow('memory', $err)
Index: trunk/packages/sipb-xen-www/code/templates/list.tmpl
===================================================================
--- trunk/packages/sipb-xen-www/code/templates/list.tmpl	(revision 439)
+++ trunk/packages/sipb-xen-www/code/templates/list.tmpl	(revision 440)
@@ -36,14 +36,8 @@
 	</tr>
 $errorRow('disk', $err)
-	<tr>
-	  <td>HVM/ParaVM$helppopup('hvm_paravm')</td>
-	  <td>
-#for $value, $name in (('hvm', 'HVM'), ('paravm', 'ParaVM'))
-   <input #slurp
-#if $defaults.vmtype == $value then 'checked' else ''
- type="radio" name="vmtype" value="$value">$name</input>
-#end for
-	  </td>
-	</tr>
+        <tr>
+          <td>HVM/ParaVM$helppopup('hvm_paravm')</td>
+          <td>$vmTypeList($defaults.type)</td>
+        </tr>
 $errorRow('vmtype', $err)
 	<tr>
Index: trunk/packages/sipb-xen-www/code/validation.py
===================================================================
--- trunk/packages/sipb-xen-www/code/validation.py	(revision 439)
+++ trunk/packages/sipb-xen-www/code/validation.py	(revision 440)
@@ -19,5 +19,5 @@
 def getMachinesByOwner(user, machine=None):
     """Return the machines owned by the same as a machine.
-    
+
     If the machine is None, return the machines owned by the same
     user.
@@ -32,5 +32,5 @@
     """Return the maximum memory for a machine or a user.
 
-    If machine is None, return the memory available for a new 
+    If machine is None, return the memory available for a new
     machine.  Else, return the maximum that machine can have.
 
@@ -50,4 +50,9 @@
 
 def maxDisk(user, machine=None):
+    """Return the maximum disk that a machine can reach.
+
+    If machine is None, the maximum disk for a new machine. Otherwise,
+    return the maximum that a given machine can be changed to.
+    """
     machines = getMachinesByOwner(user, machine)
     disk_usage = sum([sum([y.size for y in x.disks])
@@ -102,5 +107,5 @@
             raise ValueError
     except ValueError:
-        raise InvalidInput('memory', memory, 
+        raise InvalidInput('memory', memory,
                            "Minimum %s MiB" % MIN_MEMORY_SINGLE)
     if memory > maxMemory(user, machine, on):
@@ -126,10 +131,10 @@
 
 def validVmType(vm_type):
-    if vm_type == 'hvm':
-        return Type.get('linux-hvm')
-    elif vm_type == 'paravm':
-        return Type.get('linux')
-    else:
+    if vm_type is None:
+        return None
+    t = Type.get(vm_type)
+    if t is None:
         raise CodeError("Invalid vm type '%s'"  % vm_type)
+    return t
 
 def testMachineId(user, machine_id, exists=True):
@@ -139,5 +144,5 @@
     """
     if machine_id is None:
-        raise InvalidInput('machine_id', machine_id, 
+        raise InvalidInput('machine_id', machine_id,
                            "Must specify a machine ID.")
     try:
@@ -177,5 +182,5 @@
     #XXX Should we require that user is in the admin group?
     return admin
-    
+
 def testOwner(user, owner, machine=None):
     """Determine whether a user can set the owner of a machine to this value.
