+class User:
+ """User class (sort of useless, I admit)"""
+ def __init__(self, username, email):
+ self.username = username
+ self.email = email
+
+def makeErrorPre(old, addition):
+ if addition is None:
+ return
+ if old:
+ return old[:-6] + '\n----\n' + str(addition) + '</pre>'
+ else:
+ return '<p>STDERR:</p><pre>' + str(addition) + '</pre>'
+
+Template.helppopup = staticmethod(helppopup)
+Template.err = None
+
+class JsonDict:
+ """Class to store a dictionary that will be converted to JSON"""
+ def __init__(self, **kws):
+ self.data = kws
+ if 'err' in kws:
+ err = kws['err']
+ del kws['err']
+ self.addError(err)
+
+ def __str__(self):
+ return simplejson.dumps(self.data)
+
+ def addError(self, text):
+ """Add stderr text to be displayed on the website."""
+ self.data['err'] = \
+ makeErrorPre(self.data.get('err'), text)
+
+class Defaults:
+ """Class to store default values for fields."""
+ memory = 256
+ disk = 4.0
+ cdrom = ''
+ name = ''
+ vmtype = 'hvm'
+ def __init__(self, max_memory=None, max_disk=None, **kws):
+ if max_memory is not None:
+ self.memory = min(self.memory, max_memory)
+ if max_disk is not None:
+ self.max_disk = min(self.disk, max_disk)
+ for key in kws:
+ setattr(self, key, kws[key])
+
+
+
+default_headers = {'Content-Type': 'text/html'}