Changeset 261 for trunk/web


Ignore:
Timestamp:
Jan 24, 2008, 9:34:53 PM (17 years ago)
Author:
ecprice
Message:

Use cached ACLs

Location:
trunk/web
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/controls.py

    r256 r261  
    7575    """
    7676    if cdtype is not None:
    77         remctl('control', machine.name, 'create',
    78                cdtype)
     77        out, err = remctl('control', machine.name, 'create',
     78                          cdtype, err=True)
    7979    else:
    80         remctl('control', machine.name, 'create')
     80        out, err = remctl('control', machine.name, 'create',
     81                          err=True)
     82    if 'already exists' in out:
     83        raise InvalidInput('action', 'create',
     84                           'VM %s is already on' % machine.name)
     85    elif err:
     86        raise CodeError('"%s" on "control %s create %s'
     87                        % (err, machine.name, cdtype))
     88    else:
     89        raise CodeError('"%s" on "control %s create %s'
     90                        % (err, machine.name, cdtype))
    8191
    8292def registerMachine(machine):
     
    215225def commandResult(user, fields):
    216226    start_time = 0
    217     print >> sys.stderr, time.time()-start_time
    218227    machine = validation.testMachineId(user, fields.getfirst('machine_id'))
    219228    action = fields.getfirst('action')
    220229    cdrom = fields.getfirst('cdrom')
    221     print >> sys.stderr, time.time()-start_time
    222230    if cdrom is not None and not CDROM.get(cdrom):
    223231        raise CodeError("Invalid cdrom type '%s'" % cdrom)   
     
    269277    elif action == 'Delete VM':
    270278        deleteVM(machine)
    271     print >> sys.stderr, time.time()-start_time
    272279
    273280    d = dict(user=user,
  • trunk/web/main.py

    r254 r261  
    3737import templates
    3838from Cheetah.Template import Template
    39 from sipb_xen_database import Machine, CDROM, ctx, connect
     39from sipb_xen_database import Machine, CDROM, ctx, connect, MachineAccess
    4040import validation
    4141from webcommon import InvalidInput, CodeError, g
     
    184184
    185185def getListDict(user):
    186     machines = [m for m in Machine.select()
    187                 if validation.haveAccess(user, m)]
     186    machines = g.machines
    188187    checkpoint.checkpoint('Got my machines')
    189188    on = {}
     
    328327        if not back:
    329328            raise
    330         print >> sys.stderr, err
    331         result = None
     329        #print >> sys.stderr, err
     330        result = err
    332331    else:
    333332        result = 'Success!'
     
    345344        return templates.info(searchList=[d])
    346345    else:
    347         raise InvalidInput
    348     ('back', back, 'Not a known back page.')
     346        raise InvalidInput('back', back, 'Not a known back page.')
    349347
    350348def modifyDict(user, fields):
  • trunk/web/webcommon.py

    r236 r261  
    11"""Exceptions for the web interface."""
    22
    3 from sipb_xen_database import Machine
     3from sipb_xen_database import Machine, MachineAccess
    44
    55class MyException(Exception):
     
    2525import controls
    2626
     27def cachedproperty(func):
     28    name = '__cache_' + func.__name__ + '_' + str(id(func))
     29    def getter(self):
     30        try:
     31            return getattr(self, name)
     32        except AttributeError:
     33            value = func(self)
     34            setattr(self, name, value)
     35            return value
     36    return property(getter)
     37
    2738class Global(object):
    2839    """Global state of the system, to avoid duplicate remctls to get state"""
    2940    def __init__(self, user):
    3041        self.user = user
    31 
    32     def __get_uptimes(self):
    33         if not hasattr(self, '_uptimes'):
    34             self._uptimes = controls.getUptimes(Machine.select())
    35         return self._uptimes
    36     uptimes = property(__get_uptimes)
     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))
    3748
    3849    def clear(self):
    3950        """Clear the state so future accesses reload it."""
    40         for attr in ('_uptimes', ):
    41             if hasattr(self, attr):
     51        for attr in self.__dict__:
     52            if attr.startswith('__cache_'):
    4253                delattr(self, attr)
    4354
Note: See TracChangeset for help on using the changeset viewer.