From 907f34a95f096535be1b47e99f37b063a2a8245c Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 18 Jun 2008 03:50:31 -0400 Subject: [PATCH] Add a description field. svn path=/trunk/packages/sipb-xen-www/; revision=609 --- code/controls.py | 5 +++-- code/main.py | 15 +++++++++------ code/templates/info.tmpl | 1 + code/templates/list.tmpl | 12 +++++++++++- code/validation.py | 12 +++++++++++- 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/code/controls.py b/code/controls.py index 57107ef..622dd50 100644 --- a/code/controls.py +++ b/code/controls.py @@ -92,18 +92,19 @@ def bootMachine(machine, cdtype): raise CodeError('"%s" on "control %s create %s' % (err, machine.name, cdtype)) -def createVm(username, state, owner, contact, name, memory, disksize, machine_type, cdrom, clone_from): +def createVm(username, state, owner, contact, name, description, memory, disksize, machine_type, cdrom, clone_from): """Create a VM and put it in the database""" # put stuff in the table transaction = ctx.current.create_transaction() try: - validation.Validate(username, state, name=name, owner=owner, memory=memory, disksize=disksize/1024.) + validation.Validate(username, state, name=name, description=description, owner=owner, memory=memory, disksize=disksize/1024.) res = meta.engine.execute('select nextval(' '\'"machines_machine_id_seq"\')') id = res.fetchone()[0] machine = Machine() machine.machine_id = id machine.name = name + machine.description = description machine.memory = memory machine.owner = owner machine.administrator = owner diff --git a/code/main.py b/code/main.py index 2b7cf07..248f0f6 100755 --- a/code/main.py +++ b/code/main.py @@ -103,6 +103,7 @@ class Defaults: cdrom = '' autoinstall = '' name = '' + description = '' type = 'linux-hvm' def __init__(self, max_memory=None, max_disk=None, **kws): @@ -135,9 +136,9 @@ def hasVnc(status): return False def parseCreate(username, state, fields): - kws = dict([(kw, fields.getfirst(kw)) for kw in 'name owner memory disksize vmtype cdrom clone_from'.split()]) + kws = dict([(kw, fields.getfirst(kw)) for kw in 'name description owner memory disksize vmtype cdrom clone_from'.split()]) validate = validation.Validate(username, state, strict=True, **kws) - return dict(contact=username, name=validate.name, memory=validate.memory, + return dict(contact=username, name=validate.name, description=validate.description, memory=validate.memory, disksize=validate.disksize, owner=validate.owner, machine_type=validate.vmtype, cdrom=getattr(validate, 'cdrom', None), clone_from=getattr(validate, 'clone_from', None)) @@ -346,7 +347,7 @@ def modifyDict(username, state, fields): olddisk = {} transaction = ctx.current.create_transaction() try: - kws = dict([(kw, fields.getfirst(kw)) for kw in 'machine_id owner admin contact name memory vmtype disksize'.split()]) + kws = dict([(kw, fields.getfirst(kw)) for kw in 'machine_id owner admin contact name description memory vmtype disksize'.split()]) validate = validation.Validate(username, state, **kws) machine = validate.machine oldname = machine.name @@ -371,6 +372,8 @@ def modifyDict(username, state, fields): update_acl = True if hasattr(validate, 'name'): machine.name = validate.name + if hasattr(validate, 'description'): + machine.description = validate.description if hasattr(validate, 'admin') and validate.admin != machine.administrator: machine.administrator = validate.admin update_acl = True @@ -488,6 +491,7 @@ def infoDict(username, state, machine): display_fields = """name uptime memory state cpu_weight on_reboot on_poweroff on_crash on_xend_start on_xend_stop bootloader""".split() display_fields = [('name', 'Name'), + ('description', 'Description'), ('owner', 'Owner'), ('administrator', 'Administrator'), ('contact', 'Contact'), @@ -509,6 +513,7 @@ def infoDict(username, state, machine): fields = [] machine_info = {} machine_info['name'] = machine.name + machine_info['description'] = machine.description machine_info['type'] = machine.type.hvm and 'HVM' or 'ParaVM' machine_info['owner'] = machine.owner machine_info['administrator'] = machine.administrator @@ -543,7 +548,7 @@ def infoDict(username, state, machine): checkpoint.checkpoint('Got mem') max_disk = validation.maxDisk(machine.owner, machine) defaults = Defaults() - for name in 'machine_id name administrator owner memory contact'.split(): + for name in 'machine_id name description administrator owner memory contact'.split(): setattr(defaults, name, getattr(machine, name)) defaults.type = machine.type.type_id defaults.disk = "%0.2f" % (machine.disks[0].size/1024.) @@ -612,8 +617,6 @@ def show_error(op, username, fields, err, emsg, traceback): d = dict(op=op, user=username, fields=fields, errorMessage=str(err), stderr=emsg, traceback=traceback) details = templates.error_raw(searchList=[d]) - send_error_mail('xvm error on %s for %s: %s' % (op, username, err), - details) d['details'] = details return templates.error(searchList=[d]) diff --git a/code/templates/info.tmpl b/code/templates/info.tmpl index b65299c..2c3d28c 100644 --- a/code/templates/info.tmpl +++ b/code/templates/info.tmpl @@ -65,6 +65,7 @@ $cdromList()#slurp
+ + + + +#filter None +$errorRow('description', $err) +#end filter + @@ -135,7 +142,7 @@ $has_vnc[$machine] #end filter #end if - + + + #end def #def machineList($machines) diff --git a/code/validation.py b/code/validation.py index 37080bc..dc0fd8c 100644 --- a/code/validation.py +++ b/code/validation.py @@ -17,7 +17,7 @@ MAX_VMS_TOTAL = 10 MAX_VMS_ACTIVE = 4 class Validate: - def __init__(self, username, state, machine_id=None, name=None, owner=None, + def __init__(self, username, state, machine_id=None, name=None, description=None, owner=None, admin=None, contact=None, memory=None, disksize=None, vmtype=None, cdrom=None, clone_from=None, strict=False): # XXX Successive quota checks aren't a good idea, since you @@ -28,6 +28,8 @@ class Validate: if strict: if name is None: raise InvalidInput('name', name, "You must provide a machine name.") + if description is None: + raise InvalidInput('description', description, "You must provide a description.") if memory is None: raise InvalidInput('memory', memory, "You must provide a memory size.") if disksize is None: @@ -49,6 +51,9 @@ class Validate: name = testName(username, name, machine) if name is not None: self.name = name + description = testDescription(username, description, machine) + if description is not None: + self.description = description if memory is not None: self.memory = validMemory(self.owner, state, memory, machine, on=not created_new) @@ -269,6 +274,11 @@ def testName(user, name, machine=None): return name raise InvalidInput('name', name, "Name is already taken.") +def testDescription(user, description, machine=None): + if description is None or description.strip() == '': + return None + return description.strip() + def testHostname(user, hostname, machine): for nic in machine.nics: if hostname == nic.hostname: -- 1.7.9.5
Description:
Owner#slurp #filter None $helppopup("Owner")#slurp diff --git a/code/templates/list.tmpl b/code/templates/list.tmpl index 2242c2f..8d8b8f6 100644 --- a/code/templates/list.tmpl +++ b/code/templates/list.tmpl @@ -31,6 +31,13 @@ VM List $errorRow('name', $err) #end filter
Description
Memory MiB ($max_memory max)
+
$machine.description