Changeset 152 for trunk/web


Ignore:
Timestamp:
Oct 9, 2007, 7:28:19 AM (17 years ago)
Author:
ecprice
Message:

Store a little global state to avoid an extra remctls.

Location:
trunk/web/templates
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/templates/main.py

    r147 r152  
    3838    pass
    3939
    40 
     40class 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
     50g = None
    4151
    4252def helppopup(subj):
     
    7383    return Machine.select_by(owner=owner)
    7484
    75 def maxMemory(user, machine=None, on=None):
     85def maxMemory(user, machine=None):
    7686    """Return the maximum memory for a machine or a user.
    7787
     
    8494
    8595    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]]
    8997    mem_usage = sum([x.memory for x in active_machines if x != machine])
    9098    return min(MAX_MEMORY_SINGLE, MAX_MEMORY_TOTAL-mem_usage)
     
    96104    return min(MAX_DISK_SINGLE, MAX_DISK_TOTAL-disk_usage/1024.)
    97105
    98 def canAddVm(user, on=None):
     106def canAddVm(user):
    99107    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]]
    103109    return (len(machines) < MAX_VMS_TOTAL and
    104110            len(active_machines) < MAX_VMS_ACTIVE)
     
    160166    return p.stdout.read()
    161167
    162 def makeDisks():
    163     """Update the lvm partitions to include all disks in the database."""
    164     remctl('web', 'lvcreate')
     168def 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   
     173def makeDisks(machine):
     174    """Update the lvm partitions to add a disk."""
     175    for disk in machine.disks:
     176        lvcreate(machine, disk)
    165177
    166178def bootMachine(machine, cdtype):
     
    287299        raise
    288300    registerMachine(machine)
    289     makeDisks()
     301    makeDisks(machine)
    290302    # tell it to boot with cdrom
    291303    bootMachine(machine, cdrom)
     
    356368    on = {}
    357369    has_vnc = {}
    358     uptimes = getUptimes(machines)
    359     on = uptimes
     370    on = g.uptimes
    360371    for m in machines:
    361372        if not on[m]:
     
    369380    #         on[m.name] = status is not None
    370381    #         has_vnc[m.name] = hasVnc(status)
    371     max_mem=maxMemory(user, on=on)
     382    max_mem=maxMemory(user)
    372383    max_disk=maxDisk(user)
    373384    d = dict(user=user,
    374              can_add_vm=canAddVm(user, on=on),
     385             can_add_vm=canAddVm(user),
    375386             max_mem=max_mem,
    376387             max_disk=max_disk,
     
    433444    token = base64.urlsafe_b64encode(token)
    434445   
     446    status = statusInfo(machine)
     447    has_vnc = hasVnc(status)
     448   
    435449    d = dict(user=user,
     450             on=status,
     451             has_vnc=has_vnc,
    436452             machine=machine,
    437453             hostname=os.environ.get('SERVER_NAME', 'localhost'),
     
    647663        email = 'moo@cow.com'
    648664    u = User()
     665    g = Global(u)
    649666    if 'SSL_CLIENT_S_DN_Email' in os.environ:
    650667        username = os.environ[ 'SSL_CLIENT_S_DN_Email'].split("@")[0]
  • trunk/web/templates/vnc.tmpl

    r133 r152  
    88#def body
    99<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
    1015<p>Here is a console to ${machine.name}.</p>
    1116<APPLET CODE="VncViewer.class" ARCHIVE="../VncViewer.jar"
Note: See TracChangeset for help on using the changeset viewer.