# 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]
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),
"""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:
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)