- Timestamp:
- May 15, 2008, 9:55:17 PM (17 years ago)
- Location:
- trunk/packages/sipb-xen-www/code
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/sipb-xen-www/code/controls.py
r522 r535 12 12 import re 13 13 import cache_acls 14 import cPickle 14 15 15 16 # ... and stolen from xend/uuid.py … … 114 115 machine.type_id = machine_type.type_id 115 116 ctx.current.save(machine) 116 disk = Disk(machine_id=machine.machine_id, 117 disk = Disk(machine_id=machine.machine_id, 117 118 guest_device_name='hda', size=disk_size) 118 119 open_nics = NIC.select_by(machine_id=None) … … 123 124 nic.machine_id = machine.machine_id 124 125 nic.hostname = name 125 ctx.current.save(nic) 126 ctx.current.save(nic) 126 127 ctx.current.save(disk) 127 128 cache_acls.refreshMachine(machine) … … 137 138 return machine 138 139 139 def getUptimes(machines=None): 140 """Return a dictionary mapping machine names to uptime strings""" 141 value_string = remctl('web', 'listvms') 142 lines = value_string.splitlines() 143 d = {} 144 for line in lines: 145 lst = line.split() 146 name, id = lst[:2] 147 uptime = ' '.join(lst[2:]) 148 d[name] = uptime 149 ans = {} 150 for m in machines: 151 ans[m] = d.get(m.name) 152 return ans 140 def getList(machines): 141 """Return a dictionary mapping machine to dicts.""" 142 value_string = remctl('web', 'listvms', '--pickle') 143 value_dict = cPickle.loads(value_string) 144 145 d = dict((m, value_dict[m.name]) for m in machines if m.name in value_dict) 146 return d 153 147 154 148 def parseStatus(s): -
trunk/packages/sipb-xen-www/code/main.py
r516 r535 197 197 def getListDict(user): 198 198 """Gets the list of local variables used by list.tmpl.""" 199 checkpoint.checkpoint('Starting') 199 200 machines = g.machines 200 201 checkpoint.checkpoint('Got my machines') 201 202 on = {} 202 203 has_vnc = {} 203 on = g.uptimes204 xmlist = g.xmlist 204 205 checkpoint.checkpoint('Got uptimes') 205 206 for m in machines: 206 m.uptime = g.uptimes.get(m) 207 if not on[m]: 207 if m not in xmlist: 208 208 has_vnc[m] = 'Off' 209 elif m.type.hvm: 210 has_vnc[m] = True 209 m.uptime = None 211 210 else: 212 has_vnc[m] = "ParaVM"+helppopup("paravm_console") 211 m.uptime = xmlist[m]['uptime'] 212 if xmlist[m]['console']: 213 has_vnc[m] = True 214 elif m.type.hvm: 215 has_vnc[m] = "WTF?" 216 else: 217 has_vnc[m] = "ParaVM"+helppopup("paravm_console") 213 218 max_memory = validation.maxMemory(user) 214 219 max_disk = validation.maxDisk(user) … … 228 233 defaults=defaults, 229 234 machines=machines, 230 has_vnc=has_vnc, 231 uptimes=g.uptimes) 235 has_vnc=has_vnc) 232 236 return d 233 237 … … 652 656 checkpoint.checkpoint('output as a string') 653 657 print output_string 654 print '<!-- <pre>%s</pre> -->' % checkpoint 658 if fields.has_key('timedebug'): 659 print '<pre>%s</pre>' % checkpoint 655 660 except Exception, err: 656 661 if not fields.has_key('js'): … … 676 681 if __name__ == '__main__': 677 682 fields = cgi.FieldStorage() 683 684 if fields.has_key('sqldebug'): 685 import logging 686 logging.basicConfig() 687 logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO) 688 logging.getLogger('sqlalchemy.orm.unitofwork').setLevel(logging.INFO) 689 678 690 u = getUser() 679 691 g.user = u -
trunk/packages/sipb-xen-www/code/templates/list.tmpl
r448 r535 1 1 #from skeleton import skeleton 2 2 #extends skeleton 3 #import datetime 3 4 4 5 … … 119 120 <td>#slurp 120 121 #if $machine.uptime 121 $ machine.uptime#slurp122 ${datetime.timedelta(seconds=int(machine.uptime))}#slurp 122 123 #end if 123 124 </td> -
trunk/packages/sipb-xen-www/code/validation.py
r440 r535 5 5 import re 6 6 import string 7 from sipb_xen_database import Machine, NIC, Type 7 from sipb_xen_database import Machine, NIC, Type, Disk 8 8 from webcommon import InvalidInput, g 9 9 … … 45 45 return MAX_MEMORY_SINGLE 46 46 machines = getMachinesByOwner(user, machine) 47 active_machines = [x for x in machines if g. uptimes.get(x)]47 active_machines = [x for x in machines if g.xmlist.get(x)] 48 48 mem_usage = sum([x.memory for x in active_machines if x != machine]) 49 49 return min(MAX_MEMORY_SINGLE, MAX_MEMORY_TOTAL-mem_usage) … … 55 55 return the maximum that a given machine can be changed to. 56 56 """ 57 machines = getMachinesByOwner(user, machine) 58 disk_usage = sum([sum([y.size for y in x.disks]) 59 for x in machines if x != machine]) 57 if machine is not None: 58 machine_id = machine.machine_id 59 else: 60 machine_id = None 61 disk_usage = Disk.query().filter_by(Disk.c.machine_id != machine_id, 62 owner=user).sum(Disk.c.size) 60 63 return min(MAX_DISK_SINGLE, MAX_DISK_TOTAL-disk_usage/1024.) 61 64 62 65 def cantAddVm(user): 63 66 machines = getMachinesByOwner(user) 64 active_machines = [x for x in machines if g. uptimes.get(x)]67 active_machines = [x for x in machines if g.xmlist.get(x)] 65 68 if len(machines) >= MAX_VMS_TOTAL: 66 69 return 'You have too many VMs to create a new one.' -
trunk/packages/sipb-xen-www/code/webcommon.py
r264 r535 1 1 """Exceptions for the web interface.""" 2 2 3 import time 3 4 from sipb_xen_database import Machine, MachineAccess 4 5 … … 40 41 def __init__(self, user): 41 42 self.user = user 42 43 machines = cachedproperty(lambda self: 44 [ma.machine for ma in 45 MachineAccess.select_by(user=self.user)]) 46 uptimes = cachedproperty(lambda self: 47 controls.getUptimes(self.machines)) 43 44 machines = cachedproperty(lambda self: 45 Machine.query().join('acl').select_by(user=self.user)) 46 xmlist = cachedproperty(lambda self: 47 controls.getList(self.machines)) 48 48 49 49 def clear(self):
Note: See TracChangeset
for help on using the changeset viewer.