"""Unregister a machine to not be controlled by the web interface"""
remctl('web', 'unregister', machine.name)
-def createVm(owner, contact, name, memory, disk_size, is_hvm, cdrom, clone_from):
+def createVm(owner, contact, name, memory, disk_size, machine_type, cdrom, clone_from):
"""Create a VM and put it in the database"""
# put stuff in the table
transaction = ctx.current.create_transaction()
machine.contact = contact
machine.uuid = uuidToString(randomUUID())
machine.boot_off_cd = True
- machine_type = Type.get_by(hvm=is_hvm)
machine.type_id = machine_type.type_id
ctx.current.save(machine)
disk = Disk(machine_id=machine.machine_id,
disk_size = validation.validDisk(owner, disk_size)
vm_type = fields.getfirst('vmtype')
- if vm_type not in ('hvm', 'paravm'):
- raise CodeError("Invalid vm type '%s'" % vm_type)
- is_hvm = (vm_type == 'hvm')
+ vm_type = validation.validVmType(vm_type)
cdrom = fields.getfirst('cdrom')
if cdrom is not None and not CDROM.get(cdrom):
raise CodeError("Invalid clone image '%s'" % clone_from)
return dict(contact=user, name=name, memory=memory, disk_size=disk_size,
- owner=owner, is_hvm=is_hvm, cdrom=cdrom, clone_from=clone_from)
+ owner=owner, machine_type=vm_type, cdrom=cdrom, clone_from=clone_from)
def create(user, fields):
"""Handler for create requests."""
import getafsgroups
import re
import string
-from sipb_xen_database import Machine, NIC
+from sipb_xen_database import Machine, NIC, Type
from webcommon import InvalidInput, g
MAX_MEMORY_TOTAL = 512
raise InvalidInput('disk', disk,
"Minimum %s GiB" % MIN_DISK_SINGLE)
return disk
-
+
+def validVmType(vm_type):
+ if vm_type == 'hvm':
+ return Type.get('linux-hvm')
+ elif vm_type == 'paravm':
+ return Type.get('linux')
+ else:
+ raise CodeError("Invalid vm type '%s'" % vm_type)
+
def testMachineId(user, machine_id, exists=True):
"""Parse, validate and check authorization for a given user and machine.