- Timestamp:
- Oct 9, 2007, 7:28:19 AM (17 years ago)
- Location:
- trunk/web/templates
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web/templates/main.py
r147 r152 38 38 pass 39 39 40 40 class Global(object): 41 def __init__(self, user): 42 self.user = user 43 44 def __get_uptimes(self): 45 if not hasattr(self, '_uptimes'): 46 self._uptimes = getUptimes(self.machines) 47 return self._uptimes 48 uptimes = property(__get_uptimes) 49 50 g = None 41 51 42 52 def helppopup(subj): … … 73 83 return Machine.select_by(owner=owner) 74 84 75 def maxMemory(user, machine=None , on=None):85 def maxMemory(user, machine=None): 76 86 """Return the maximum memory for a machine or a user. 77 87 … … 84 94 85 95 machines = getMachinesByOwner(user.username) 86 if on is None: 87 on = getUptimes(machines) 88 active_machines = [x for x in machines if on[x]] 96 active_machines = [x for x in machines if g.uptimes[x]] 89 97 mem_usage = sum([x.memory for x in active_machines if x != machine]) 90 98 return min(MAX_MEMORY_SINGLE, MAX_MEMORY_TOTAL-mem_usage) … … 96 104 return min(MAX_DISK_SINGLE, MAX_DISK_TOTAL-disk_usage/1024.) 97 105 98 def canAddVm(user , on=None):106 def canAddVm(user): 99 107 machines = getMachinesByOwner(user.username) 100 if on is None: 101 on = getUptimes(machines) 102 active_machines = [x for x in machines if on[x]] 108 active_machines = [x for x in machines if g.uptimes[x]] 103 109 return (len(machines) < MAX_VMS_TOTAL and 104 110 len(active_machines) < MAX_VMS_ACTIVE) … … 160 166 return p.stdout.read() 161 167 162 def makeDisks(): 163 """Update the lvm partitions to include all disks in the database.""" 164 remctl('web', 'lvcreate') 168 def lvcreate(machine, disk): 169 """Create a single disk for a machine""" 170 remctl('web', 'lvcreate', machine.name, 171 disk.guest_device_name, str(disk.size)) 172 173 def makeDisks(machine): 174 """Update the lvm partitions to add a disk.""" 175 for disk in machine.disks: 176 lvcreate(machine, disk) 165 177 166 178 def bootMachine(machine, cdtype): … … 287 299 raise 288 300 registerMachine(machine) 289 makeDisks( )301 makeDisks(machine) 290 302 # tell it to boot with cdrom 291 303 bootMachine(machine, cdrom) … … 356 368 on = {} 357 369 has_vnc = {} 358 uptimes = getUptimes(machines) 359 on = uptimes 370 on = g.uptimes 360 371 for m in machines: 361 372 if not on[m]: … … 369 380 # on[m.name] = status is not None 370 381 # has_vnc[m.name] = hasVnc(status) 371 max_mem=maxMemory(user , on=on)382 max_mem=maxMemory(user) 372 383 max_disk=maxDisk(user) 373 384 d = dict(user=user, 374 can_add_vm=canAddVm(user , on=on),385 can_add_vm=canAddVm(user), 375 386 max_mem=max_mem, 376 387 max_disk=max_disk, … … 433 444 token = base64.urlsafe_b64encode(token) 434 445 446 status = statusInfo(machine) 447 has_vnc = hasVnc(status) 448 435 449 d = dict(user=user, 450 on=status, 451 has_vnc=has_vnc, 436 452 machine=machine, 437 453 hostname=os.environ.get('SERVER_NAME', 'localhost'), … … 647 663 email = 'moo@cow.com' 648 664 u = User() 665 g = Global(u) 649 666 if 'SSL_CLIENT_S_DN_Email' in os.environ: 650 667 username = os.environ[ 'SSL_CLIENT_S_DN_Email'].split("@")[0] -
trunk/web/templates/vnc.tmpl
r133 r152 8 8 #def body 9 9 <h1>Console</h1> 10 #if not $on 11 <p> Your machine appears to be off.</p> 12 #else if not $has_vnc 13 <p> Your machine appears to not be accepting VNC connections. Perhaps you have a ParaVM machine?</p> 14 #end if 10 15 <p>Here is a console to ${machine.name}.</p> 11 16 <APPLET CODE="VncViewer.class" ARCHIVE="../VncViewer.jar"
Note: See TracChangeset
for help on using the changeset viewer.