1 """Exceptions for the web interface."""
3 from sipb_xen_database import Machine, MachineAccess
5 class MyException(Exception):
6 """Base class for my exceptions"""
9 class InvalidInput(MyException):
10 """Exception for user-provided input is invalid but maybe in good faith.
12 This would include setting memory to negative (which might be a
13 typo) but not setting an invalid boot CD (which requires bypassing
16 def __init__(self, err_field, err_value, expl=None):
17 MyException.__init__(self, expl)
18 self.err_field = err_field
19 self.err_value = err_value
21 class CodeError(MyException):
22 """Exception for internal errors or bad faith input."""
27 def cachedproperty(func):
28 name = '__cache_' + func.__name__ + '_' + str(id(func))
31 return getattr(self, name)
32 except AttributeError:
34 setattr(self, name, value)
36 return property(getter)
39 """Global state of the system, to avoid duplicate remctls to get state"""
40 def __init__(self, user):
43 machines = cachedproperty(lambda self:
45 MachineAccess.select_by(user=self.user)])
46 uptimes = cachedproperty(lambda self:
47 controls.getUptimes(self.machines))
50 """Clear the state so future accesses reload it."""
51 for attr in list(self.__dict__):
52 if attr.startswith('__cache_'):