1 """Exceptions for the web interface."""
4 from sipb_xen_database import Machine, MachineAccess
6 class MyException(Exception):
7 """Base class for my exceptions"""
10 class InvalidInput(MyException):
11 """Exception for user-provided input is invalid but maybe in good faith.
13 This would include setting memory to negative (which might be a
14 typo) but not setting an invalid boot CD (which requires bypassing
17 def __init__(self, err_field, err_value, expl=None):
18 MyException.__init__(self, expl)
19 self.err_field = err_field
20 self.err_value = err_value
22 class CodeError(MyException):
23 """Exception for internal errors or bad faith input."""
28 def cachedproperty(func):
29 name = '__cache_' + func.__name__ + '_' + str(id(func))
32 return getattr(self, name)
33 except AttributeError:
35 setattr(self, name, value)
37 return property(getter)
40 """Global state of the system, to avoid duplicate remctls to get state"""
41 def __init__(self, user):
44 machines = cachedproperty(lambda self:
45 Machine.query().join('acl').select_by(user=self.user))
46 xmlist_raw = cachedproperty(lambda self: controls.getList())
47 xmlist = cachedproperty(lambda self:
48 dict((m, self.xmlist_raw[m.name])
49 for m in self.machines
50 if m.name in self.xmlist_raw))
53 """Clear the state so future accesses reload it."""
54 for attr in list(self.__dict__):
55 if attr.startswith('__cache_'):