- Timestamp:
- Jan 24, 2008, 9:34:53 PM (17 years ago)
- Location:
- trunk/web
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web/controls.py
r256 r261 75 75 """ 76 76 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) 79 79 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)) 81 91 82 92 def registerMachine(machine): … … 215 225 def commandResult(user, fields): 216 226 start_time = 0 217 print >> sys.stderr, time.time()-start_time218 227 machine = validation.testMachineId(user, fields.getfirst('machine_id')) 219 228 action = fields.getfirst('action') 220 229 cdrom = fields.getfirst('cdrom') 221 print >> sys.stderr, time.time()-start_time222 230 if cdrom is not None and not CDROM.get(cdrom): 223 231 raise CodeError("Invalid cdrom type '%s'" % cdrom) … … 269 277 elif action == 'Delete VM': 270 278 deleteVM(machine) 271 print >> sys.stderr, time.time()-start_time272 279 273 280 d = dict(user=user, -
trunk/web/main.py
r254 r261 37 37 import templates 38 38 from Cheetah.Template import Template 39 from sipb_xen_database import Machine, CDROM, ctx, connect 39 from sipb_xen_database import Machine, CDROM, ctx, connect, MachineAccess 40 40 import validation 41 41 from webcommon import InvalidInput, CodeError, g … … 184 184 185 185 def getListDict(user): 186 machines = [m for m in Machine.select() 187 if validation.haveAccess(user, m)] 186 machines = g.machines 188 187 checkpoint.checkpoint('Got my machines') 189 188 on = {} … … 328 327 if not back: 329 328 raise 330 print >> sys.stderr, err331 result = None329 #print >> sys.stderr, err 330 result = err 332 331 else: 333 332 result = 'Success!' … … 345 344 return templates.info(searchList=[d]) 346 345 else: 347 raise InvalidInput 348 ('back', back, 'Not a known back page.') 346 raise InvalidInput('back', back, 'Not a known back page.') 349 347 350 348 def modifyDict(user, fields): -
trunk/web/webcommon.py
r236 r261 1 1 """Exceptions for the web interface.""" 2 2 3 from sipb_xen_database import Machine 3 from sipb_xen_database import Machine, MachineAccess 4 4 5 5 class MyException(Exception): … … 25 25 import controls 26 26 27 def 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 27 38 class Global(object): 28 39 """Global state of the system, to avoid duplicate remctls to get state""" 29 40 def __init__(self, user): 30 41 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._uptimes36 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)) 37 48 38 49 def clear(self): 39 50 """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_'): 42 53 delattr(self, attr) 43 54
Note: See TracChangeset
for help on using the changeset viewer.