Ignore:
Timestamp:
Apr 21, 2008, 9:13:53 PM (17 years ago)
Author:
ecprice
Message:

Support setting paravm/hvm for off, but already created, VMs.

Location:
trunk/packages/sipb-xen-www/code
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/sipb-xen-www/code/main.py

    r438 r440  
    3737import templates
    3838from Cheetah.Template import Template
    39 from sipb_xen_database import Machine, CDROM, ctx, connect, MachineAccess
     39import sipb_xen_database
     40from sipb_xen_database import Machine, CDROM, ctx, connect, MachineAccess, Type
    4041import validation
    4142from webcommon import InvalidInput, CodeError, g
     
    7273        return '<p>STDERR:</p><pre>' + str(addition) + '</pre>'
    7374
     75Template.sipb_xen_database = sipb_xen_database
    7476Template.helppopup = staticmethod(helppopup)
    7577Template.err = None
     
    98100    cdrom = ''
    99101    name = ''
    100     vmtype = 'hvm'
    101102    def __init__(self, max_memory=None, max_disk=None, **kws):
     103        self.type = Type.get('linux-hvm')
    102104        if max_memory is not None:
    103105            self.memory = min(self.memory, max_memory)
     
    380382            machine.memory = memory
    381383
     384        vm_type = validation.validVmType(fields.getfirst('vmtype'))
     385        if vm_type is not None:
     386            machine.type = vm_type
     387
    382388        disksize = validation.testDisk(user, fields.getfirst('disk'))
    383389        if disksize is not None:
     
    561567    max_disk = validation.maxDisk(user, machine)
    562568    defaults = Defaults()
    563     for name in 'machine_id name administrator owner memory contact'.split():
     569    for name in 'machine_id name administrator owner memory contact type'.split():
    564570        setattr(defaults, name, getattr(machine, name))
    565571    defaults.disk = "%0.2f" % (machine.disks[0].size/1024.)
  • trunk/packages/sipb-xen-www/code/templates/functions.tmpl

    r406 r440  
    1212  #end for
    1313</select>
     14#end def
     15
     16#def vmTypeList($default=None)
     17#for $vmtype in $sipb_xen_database.Type.select()
     18<label>
     19   <input #slurp
     20#if $default == $vmtype then 'checked' else ''
     21 type="radio" name="vmtype" value="${vmtype.type_id}">${vmtype.description}</input>
     22</label>
     23#end for
    1424#end def
    1525
  • trunk/packages/sipb-xen-www/code/templates/info.tmpl

    r436 r440  
    5959(To edit ram, disk size, or machine name, turn off the machine first.)
    6060#end if
    61 </p>
    6261<form action="modify" method="POST">
    6362  <input type="hidden" name="machine_id" value="$defaults.machine_id"/>
     
    7271    <tr><td>Machine Name:</td><td><input type="text" name="name" value="$defaults.name"/></td></tr>
    7372$errorRow('name', $err)
     73    <tr>
     74      <td>HVM/ParaVM$helppopup('hvm_paravm')</td>
     75      <td>$vmTypeList($defaults.type)</td>
     76    </tr>
    7477    <tr><td>Ram:</td><td><input type="text" size=3 name="memory" value="$defaults.memory"/>MiB (max $max_mem)</td></tr>
    7578$errorRow('memory', $err)
  • trunk/packages/sipb-xen-www/code/templates/list.tmpl

    r426 r440  
    3636        </tr>
    3737$errorRow('disk', $err)
    38         <tr>
    39           <td>HVM/ParaVM$helppopup('hvm_paravm')</td>
    40           <td>
    41 #for $value, $name in (('hvm', 'HVM'), ('paravm', 'ParaVM'))
    42    <input #slurp
    43 #if $defaults.vmtype == $value then 'checked' else ''
    44  type="radio" name="vmtype" value="$value">$name</input>
    45 #end for
    46           </td>
    47         </tr>
     38        <tr>
     39          <td>HVM/ParaVM$helppopup('hvm_paravm')</td>
     40          <td>$vmTypeList($defaults.type)</td>
     41        </tr>
    4842$errorRow('vmtype', $err)
    4943        <tr>
  • trunk/packages/sipb-xen-www/code/validation.py

    r437 r440  
    1919def getMachinesByOwner(user, machine=None):
    2020    """Return the machines owned by the same as a machine.
    21    
     21
    2222    If the machine is None, return the machines owned by the same
    2323    user.
     
    3232    """Return the maximum memory for a machine or a user.
    3333
    34     If machine is None, return the memory available for a new 
     34    If machine is None, return the memory available for a new
    3535    machine.  Else, return the maximum that machine can have.
    3636
     
    5050
    5151def maxDisk(user, machine=None):
     52    """Return the maximum disk that a machine can reach.
     53
     54    If machine is None, the maximum disk for a new machine. Otherwise,
     55    return the maximum that a given machine can be changed to.
     56    """
    5257    machines = getMachinesByOwner(user, machine)
    5358    disk_usage = sum([sum([y.size for y in x.disks])
     
    102107            raise ValueError
    103108    except ValueError:
    104         raise InvalidInput('memory', memory, 
     109        raise InvalidInput('memory', memory,
    105110                           "Minimum %s MiB" % MIN_MEMORY_SINGLE)
    106111    if memory > maxMemory(user, machine, on):
     
    126131
    127132def validVmType(vm_type):
    128     if vm_type == 'hvm':
    129         return Type.get('linux-hvm')
    130     elif vm_type == 'paravm':
    131         return Type.get('linux')
    132     else:
     133    if vm_type is None:
     134        return None
     135    t = Type.get(vm_type)
     136    if t is None:
    133137        raise CodeError("Invalid vm type '%s'"  % vm_type)
     138    return t
    134139
    135140def testMachineId(user, machine_id, exists=True):
     
    139144    """
    140145    if machine_id is None:
    141         raise InvalidInput('machine_id', machine_id, 
     146        raise InvalidInput('machine_id', machine_id,
    142147                           "Must specify a machine ID.")
    143148    try:
     
    177182    #XXX Should we require that user is in the admin group?
    178183    return admin
    179    
     184
    180185def testOwner(user, owner, machine=None):
    181186    """Determine whether a user can set the owner of a machine to this value.
Note: See TracChangeset for help on using the changeset viewer.