From c51a587924139a9bb900735f02e0b2258ed6d239 Mon Sep 17 00:00:00 2001 From: Eric Price Date: Mon, 2 Jun 2008 23:58:25 -0400 Subject: [PATCH] Fix more bugs svn path=/trunk/packages/sipb-xen-www/; revision=577 --- code/controls.py | 2 +- code/main.py | 4 ++-- code/validation.py | 10 +++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/code/controls.py b/code/controls.py index 63221a2..ff3691c 100644 --- a/code/controls.py +++ b/code/controls.py @@ -97,7 +97,7 @@ def createVm(username, state, owner, contact, name, memory, disksize, machine_ty # put stuff in the table transaction = ctx.current.create_transaction() try: - validation.Validate(username, state, owner=owner, memory=memory, disksize=disksize/1024.) + validation.Validate(username, state, name=name, owner=owner, memory=memory, disksize=disksize/1024.) res = meta.engine.execute('select nextval(' '\'"machines_machine_id_seq"\')') id = res.fetchone()[0] diff --git a/code/main.py b/code/main.py index fdc2837..70e9a2a 100755 --- a/code/main.py +++ b/code/main.py @@ -144,7 +144,7 @@ def hasVnc(status): def parseCreate(username, state, fields): kws = dict([(kw, fields.getfirst(kw)) for kw in 'name owner memory disksize vmtype cdrom clone_from'.split()]) - validate = validation.Validate(username, state, **kws) + validate = validation.Validate(username, state, strict=True, **kws) return dict(contact=username, name=validate.name, memory=validate.memory, disksize=validate.disksize, owner=validate.owner, machine_type=validate.vmtype, cdrom=getattr(validate, 'cdrom', None), @@ -154,7 +154,7 @@ def create(username, state, fields): """Handler for create requests.""" try: parsed_fields = parseCreate(username, state, fields) - machine = controls.createVm(username, **parsed_fields) + machine = controls.createVm(username, state, **parsed_fields) except InvalidInput, err: pass else: diff --git a/code/validation.py b/code/validation.py index 7eb1b4f..db3a365 100644 --- a/code/validation.py +++ b/code/validation.py @@ -19,12 +19,20 @@ MAX_VMS_ACTIVE = 4 class Validate: def __init__(self, username, state, machine_id=None, name=None, owner=None, admin=None, contact=None, memory=None, disksize=None, - vmtype=None, cdrom=None, clone_from=None): + vmtype=None, cdrom=None, clone_from=None, strict=False): # XXX Successive quota checks aren't a good idea, since you # can't necessarily change the locker and disk size at the # same time. created_new = (machine_id is None) + if strict: + if name is None: + raise InvalidInput('name', name, "You must provide a machine name.") + if memory is None: + raise InvalidInput('memory', memory, "You must provide a memory size.") + if disksize is None: + raise InvalidInput('disk', disksize, "You must provide a disk size.") + if machine_id is not None: self.machine = testMachineId(username, machine_id) machine = getattr(self, 'machine', None) -- 1.7.9.5