- Timestamp:
- Apr 21, 2008, 9:13:53 PM (17 years ago)
- Location:
- trunk/packages/sipb-xen-www/code
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/sipb-xen-www/code/main.py
r438 r440 37 37 import templates 38 38 from Cheetah.Template import Template 39 from sipb_xen_database import Machine, CDROM, ctx, connect, MachineAccess 39 import sipb_xen_database 40 from sipb_xen_database import Machine, CDROM, ctx, connect, MachineAccess, Type 40 41 import validation 41 42 from webcommon import InvalidInput, CodeError, g … … 72 73 return '<p>STDERR:</p><pre>' + str(addition) + '</pre>' 73 74 75 Template.sipb_xen_database = sipb_xen_database 74 76 Template.helppopup = staticmethod(helppopup) 75 77 Template.err = None … … 98 100 cdrom = '' 99 101 name = '' 100 vmtype = 'hvm'101 102 def __init__(self, max_memory=None, max_disk=None, **kws): 103 self.type = Type.get('linux-hvm') 102 104 if max_memory is not None: 103 105 self.memory = min(self.memory, max_memory) … … 380 382 machine.memory = memory 381 383 384 vm_type = validation.validVmType(fields.getfirst('vmtype')) 385 if vm_type is not None: 386 machine.type = vm_type 387 382 388 disksize = validation.testDisk(user, fields.getfirst('disk')) 383 389 if disksize is not None: … … 561 567 max_disk = validation.maxDisk(user, machine) 562 568 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(): 564 570 setattr(defaults, name, getattr(machine, name)) 565 571 defaults.disk = "%0.2f" % (machine.disks[0].size/1024.) -
trunk/packages/sipb-xen-www/code/templates/functions.tmpl
r406 r440 12 12 #end for 13 13 </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 14 24 #end def 15 25 -
trunk/packages/sipb-xen-www/code/templates/info.tmpl
r436 r440 59 59 (To edit ram, disk size, or machine name, turn off the machine first.) 60 60 #end if 61 </p>62 61 <form action="modify" method="POST"> 63 62 <input type="hidden" name="machine_id" value="$defaults.machine_id"/> … … 72 71 <tr><td>Machine Name:</td><td><input type="text" name="name" value="$defaults.name"/></td></tr> 73 72 $errorRow('name', $err) 73 <tr> 74 <td>HVM/ParaVM$helppopup('hvm_paravm')</td> 75 <td>$vmTypeList($defaults.type)</td> 76 </tr> 74 77 <tr><td>Ram:</td><td><input type="text" size=3 name="memory" value="$defaults.memory"/>MiB (max $max_mem)</td></tr> 75 78 $errorRow('memory', $err) -
trunk/packages/sipb-xen-www/code/templates/list.tmpl
r426 r440 36 36 </tr> 37 37 $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> 48 42 $errorRow('vmtype', $err) 49 43 <tr> -
trunk/packages/sipb-xen-www/code/validation.py
r437 r440 19 19 def getMachinesByOwner(user, machine=None): 20 20 """Return the machines owned by the same as a machine. 21 21 22 22 If the machine is None, return the machines owned by the same 23 23 user. … … 32 32 """Return the maximum memory for a machine or a user. 33 33 34 If machine is None, return the memory available for a new 34 If machine is None, return the memory available for a new 35 35 machine. Else, return the maximum that machine can have. 36 36 … … 50 50 51 51 def 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 """ 52 57 machines = getMachinesByOwner(user, machine) 53 58 disk_usage = sum([sum([y.size for y in x.disks]) … … 102 107 raise ValueError 103 108 except ValueError: 104 raise InvalidInput('memory', memory, 109 raise InvalidInput('memory', memory, 105 110 "Minimum %s MiB" % MIN_MEMORY_SINGLE) 106 111 if memory > maxMemory(user, machine, on): … … 126 131 127 132 def 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: 133 137 raise CodeError("Invalid vm type '%s'" % vm_type) 138 return t 134 139 135 140 def testMachineId(user, machine_id, exists=True): … … 139 144 """ 140 145 if machine_id is None: 141 raise InvalidInput('machine_id', machine_id, 146 raise InvalidInput('machine_id', machine_id, 142 147 "Must specify a machine ID.") 143 148 try: … … 177 182 #XXX Should we require that user is in the admin group? 178 183 return admin 179 184 180 185 def testOwner(user, owner, machine=None): 181 186 """Determine whether a user can set the owner of a machine to this value.
Note: See TracChangeset
for help on using the changeset viewer.