Changeset 144 for trunk/web/templates
- Timestamp:
- Oct 8, 2007, 4:44:14 AM (17 years ago)
- Location:
- trunk/web/templates
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web/templates/command.tmpl
r134 r144 8 8 9 9 #def body 10 <h1>Command succes ful</h1>10 <h1>Command successful</h1> 11 11 <p>$command ${machine.name} was successful.</p> 12 #if $command == "Delete VM" 12 #if $command == "Delete VM" or True 13 13 <p><a href="list">Return</a></p> 14 14 #else -
trunk/web/templates/info.tmpl
r135 r144 69 69 #end if 70 70 #if not $on 71 <tr><td>Ram:</td><td><input type="text" size=3 value="$machine.memory"/>MB (max $max mem)</td></tr>72 <tr><td>Disk:</td><td><input type="text" size=3 value="${machine.disks[0].size/1024.}"/>GB (max $max disk)</td></tr>71 <tr><td>Ram:</td><td><input type="text" size=3 value="$machine.memory"/>MB (max $max_mem)</td></tr> 72 <tr><td>Disk:</td><td><input type="text" size=3 value="${machine.disks[0].size/1024.}"/>GB (max $max_disk)</td></tr> 73 73 #end if 74 74 <tr><td><input type="submit" class="button" name="action" value="Change"/></td></tr> -
trunk/web/templates/list.tmpl
r139 r144 21 21 <td>Uptime</td> 22 22 <td>VNC</td> 23 <td> Restart?</td>23 <td></td> 24 24 #for $machine in $machines: 25 25 <tr> … … 38 38 #end if 39 39 <td>#slurp 40 #if $uptimes .get($machine.name)41 $uptimes[$machine .name]#slurp40 #if $uptimes[$machine] 41 $uptimes[$machine]#slurp 42 42 #else 43 43 Off#slurp … … 45 45 </td> 46 46 <td>#slurp 47 #if $has_vnc .get($machine.name)== True47 #if $has_vnc[$machine] == True 48 48 <a href="vnc?machine_id=$machine.machine_id">Console</a>#slurp 49 49 #else 50 $has_vnc .get($machine.name)50 $has_vnc[$machine] 51 51 #end if 52 52 </td> … … 55 55 <input type="hidden" name="machine_id" 56 56 value="$machine.machine_id"/> 57 <input type="submit" class="button" 58 value="Reboot"/> 57 #if $uptimes[$machine] 58 <input type="submit" class="button" name="action" value="Shutdown"/> 59 #else 60 <input type="submit" class="button" name="action" value="Power on"/> 61 #end if 59 62 </form> 60 63 </td> … … 63 66 </table> 64 67 #end if 65 68 #if $can_add_vm 66 69 <p>Create a new VM:</p> 67 70 <form action="create" method="POST"> … … 73 76 <tr> 74 77 <td>Memory</td> 75 <td><input type="text" name="memory" value="$ maxmem" size=3/> megabytes ($maxmem max)</td>78 <td><input type="text" name="memory" value="$default_mem" size=3/> megabytes ($max_mem max)</td> 76 79 </tr> 77 80 <tr> 78 81 <td>Disk</td> 79 <td><input type="text" name="disk" value="$ maxdisk" size=3/> gigabytes ($maxdiskmax)</td>82 <td><input type="text" name="disk" value="$default_disk" size=3/> gigabytes (${"%0.1f" % ($max_disk-0.05)} max)</td> 80 83 </tr> 81 84 <tr> … … 102 105 <input type="submit" class="button" value="Create it!"/> 103 106 </form> 104 107 #else 108 <p>You are at the maximum number of VMs.</p> 109 #end if 105 110 #end def -
trunk/web/templates/main.py
r140 r144 42 42 "%02x" * 6]) % tuple(u) 43 43 44 def maxMemory(user, machine=None): 45 return 256 44 MAX_MEMORY_TOTAL = 512 45 MAX_MEMORY_SINGLE = 256 46 MIN_MEMORY_SINGLE = 16 47 MAX_DISK_TOTAL = 50 48 MAX_DISK_SINGLE = 50 49 MIN_DISK_SINGLE = 0.1 50 MAX_VMS_TOTAL = 10 51 MAX_VMS_ACTIVE = 4 52 53 def getMachinesOwner(owner): 54 return Machine.select_by(owner=owner) 55 56 def maxMemory(user, machine=None, on=None): 57 machines = getMachinesOwner(user.username) 58 if on is None: 59 on = getUptimes(machines) 60 active_machines = [x for x in machines if on[x]] 61 mem_usage = sum([x.memory for x in active_machines if x != machine]) 62 return min(MAX_MEMORY_SINGLE, MAX_MEMORY_TOTAL-mem_usage) 46 63 47 64 def maxDisk(user, machine=None): 48 return 10.0 65 machines = getMachinesOwner(user.username) 66 disk_usage = sum([sum([y.size for y in x.disks]) 67 for x in machines if x != machine]) 68 return min(MAX_DISK_SINGLE, MAX_DISK_TOTAL-disk_usage/1024.) 69 70 def canAddVm(user, on=None): 71 machines = getMachinesOwner(user.username) 72 if on is None: 73 on = getUptimes(machines) 74 active_machines = [x for x in machines if on[x]] 75 return (len(machines) < MAX_VMS_TOTAL and 76 len(active_machines) < MAX_VMS_ACTIVE) 49 77 50 78 def haveAccess(user, machine): … … 95 123 stderr=subprocess.PIPE) 96 124 if kws.get('err'): 125 p.wait() 97 126 return p.stdout.read(), p.stderr.read() 98 127 if p.wait(): 99 print >> sys.stderr, 'ERROR on remctl ', args100 print >> sys.stderr, p.stderr.read()128 raise MyException('ERROR on remctl %s: %s' % 129 (args, p.stderr.read())) 101 130 return p.stdout.read() 102 131 … … 159 188 uptime = ' '.join(lst[2:]) 160 189 d[name] = uptime 161 return d 190 ans = {} 191 for m in machines: 192 ans[m] = d.get(m.name) 193 return ans 162 194 163 195 def statusInfo(machine): … … 191 223 transaction = ctx.current.create_transaction() 192 224 try: 225 if memory > maxMemory(user): 226 raise MyException("Too much memory requested") 227 if disk > maxDisk(user) * 1024: 228 raise MyException("Too much disk requested") 229 if not canAddVm(user): 230 raise MyException("Too many VMs requested") 193 231 res = meta.engine.execute('select nextval(\'"machines_machine_id_seq"\')') 194 232 id = res.fetchone()[0] … … 218 256 transaction.rollback() 219 257 raise 258 registerMachine(machine) 220 259 makeDisks() 221 registerMachine(machine)222 260 # tell it to boot with cdrom 223 261 bootMachine(machine, cdrom) … … 228 266 try: 229 267 memory = int(memory) 230 if memory < = 0:268 if memory < MIN_MEMORY_SINGLE: 231 269 raise ValueError 232 270 except ValueError: 233 raise MyException("Invalid memory amount") 271 raise MyException("Invalid memory amount; must be at least %s MB" % 272 MIN_MEMORY_SINGLE) 234 273 if memory > maxMemory(user, machine): 235 274 raise MyException("Too much memory requested") … … 242 281 raise MyException("Too much disk requested") 243 282 disk = int(disk * 1024) 244 if disk < = 0:283 if disk < MIN_DISK_SINGLE * 1024: 245 284 raise ValueError 246 285 except ValueError: 247 raise MyException("Invalid disk amount") 286 raise MyException("Invalid disk amount; minimum is %s GB" % 287 MIN_DISK_SINGLE) 248 288 return disk 249 289 … … 287 327 on = uptimes 288 328 for m in machines: 289 if not on .get(m.name):290 has_vnc[m .name] = 'Off'329 if not on[m]: 330 has_vnc[m] = 'Off' 291 331 elif m.type.hvm: 292 has_vnc[m .name] = True332 has_vnc[m] = True 293 333 else: 294 has_vnc[m .name] = "ParaVM"+helppopup("paravm_console")334 has_vnc[m] = "ParaVM"+helppopup("paravm_console") 295 335 # for m in machines: 296 336 # status = statusInfo(m) 297 337 # on[m.name] = status is not None 298 338 # has_vnc[m.name] = hasVnc(status) 339 max_mem=maxMemory(user, on=on) 340 max_disk=maxDisk(user) 299 341 d = dict(user=user, 300 maxmem=maxMemory(user), 301 maxdisk=maxDisk(user), 342 can_add_vm=canAddVm(user, on=on), 343 max_mem=max_mem, 344 max_disk=max_disk, 345 default_mem=max_mem, 346 default_disk=min(4.0, max_disk), 302 347 machines=machines, 303 348 has_vnc=has_vnc, … … 418 463 remctl('reboot', machine.name) 419 464 elif action == 'Power on': 465 if maxMemory(user) < machine.memory: 466 raise MyException("You don't have enough free RAM quota") 420 467 bootMachine(machine, cdrom) 421 468 elif action == 'Power off': … … 515 562 pass 516 563 #fields.append((disp, None)) 517 564 max_mem = maxMemory(user, machine) 565 max_disk = maxDisk(user, machine) 518 566 d = dict(user=user, 519 567 cdroms=CDROM.select(), … … 523 571 uptime=str(uptime), 524 572 ram=machine.memory, 525 max mem=maxMemory(user, machine),526 max disk=maxDisk(user, machine),573 max_mem=max_mem, 574 max_disk=max_disk, 527 575 fields = fields) 528 576 print Template(file='info.tmpl', … … 549 597 u.email = os.environ[ 'SSL_CLIENT_S_DN_Email'] 550 598 else: 551 u.username = ' nobody'552 u.email = None599 u.username = 'moo' 600 u.email = 'nobody' 553 601 connect('postgres://sipb-xen@sipb-xen-dev/sipb_xen') 554 602 operation = os.environ.get('PATH_INFO', '')
Note: See TracChangeset
for help on using the changeset viewer.