mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-25 15:45:23 +00:00
fix instance create error handling
This commit is contained in:
parent
6d52587e60
commit
83ba6da572
2 changed files with 163 additions and 164 deletions
|
@ -1242,6 +1242,7 @@ def create_instance(request, compute_id, arch, machine):
|
||||||
flavors = Flavor.objects.filter().order_by('id')
|
flavors = Flavor.objects.filter().order_by('id')
|
||||||
appsettings = AppSettings.objects.all()
|
appsettings = AppSettings.objects.all()
|
||||||
|
|
||||||
|
try:
|
||||||
conn = wvmCreate(compute.hostname, compute.login, compute.password, compute.type)
|
conn = wvmCreate(compute.hostname, compute.login, compute.password, compute.type)
|
||||||
|
|
||||||
default_firmware = app_settings.INSTANCE_FIRMWARE_DEFAULT_TYPE
|
default_firmware = app_settings.INSTANCE_FIRMWARE_DEFAULT_TYPE
|
||||||
|
@ -1285,11 +1286,9 @@ def create_instance(request, compute_id, arch, machine):
|
||||||
|
|
||||||
if conn:
|
if conn:
|
||||||
if not storages:
|
if not storages:
|
||||||
msg = _("You haven't defined any storage pools")
|
raise libvirtError(_("You haven't defined any storage pools"))
|
||||||
messages.error(request, msg)
|
|
||||||
if not networks:
|
if not networks:
|
||||||
msg = _("You haven't defined any network pools")
|
raise libvirtError(_("You haven't defined any network pools"))
|
||||||
messages.error(request, msg)
|
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
if 'create' in request.POST:
|
if 'create' in request.POST:
|
||||||
|
@ -1304,14 +1303,13 @@ def create_instance(request, compute_id, arch, machine):
|
||||||
meta_prealloc = True
|
meta_prealloc = True
|
||||||
if instances:
|
if instances:
|
||||||
if data['name'] in instances:
|
if data['name'] in instances:
|
||||||
msg = _("A virtual machine with this name already exists")
|
raise libvirtError(_("A virtual machine with this name already exists"))
|
||||||
messages.error(request, msg)
|
|
||||||
if Instance.objects.filter(name__exact=data['name']):
|
if Instance.objects.filter(name__exact=data['name']):
|
||||||
messages.warning(request, _("There is an instance with same name. Are you sure?"))
|
raise libvirtError(_("There is an instance with same name. Remove it and try again!"))
|
||||||
|
|
||||||
if data['hdd_size']:
|
if data['hdd_size']:
|
||||||
if not data['mac']:
|
if not data['mac']:
|
||||||
error_msg = _("No Virtual Machine MAC has been entered")
|
raise libvirtError(_("No Virtual Machine MAC has been entered"))
|
||||||
messages.error(request, msg)
|
|
||||||
else:
|
else:
|
||||||
path = conn.create_volume(data['storage'], data['name'], data['hdd_size'], default_disk_format,
|
path = conn.create_volume(data['storage'], data['name'], data['hdd_size'], default_disk_format,
|
||||||
meta_prealloc, default_disk_owner_uid, default_disk_owner_gid)
|
meta_prealloc, default_disk_owner_uid, default_disk_owner_gid)
|
||||||
|
@ -1334,8 +1332,7 @@ def create_instance(request, compute_id, arch, machine):
|
||||||
templ_path = conn.get_volume_path(data['template'])
|
templ_path = conn.get_volume_path(data['template'])
|
||||||
dest_vol = conn.get_volume_path(data["name"] + ".img", data['storage'])
|
dest_vol = conn.get_volume_path(data["name"] + ".img", data['storage'])
|
||||||
if dest_vol:
|
if dest_vol:
|
||||||
error_msg = _("Image has already exist. Please check volumes or change instance name")
|
raise libvirtError(_("Image has already exist. Please check volumes or change instance name"))
|
||||||
messages.error(request, error_msg)
|
|
||||||
else:
|
else:
|
||||||
clone_path = conn.clone_from_template(data['name'], templ_path, data['storage'], meta_prealloc,
|
clone_path = conn.clone_from_template(data['name'], templ_path, data['storage'], meta_prealloc,
|
||||||
default_disk_owner_uid, default_disk_owner_gid)
|
default_disk_owner_uid, default_disk_owner_gid)
|
||||||
|
@ -1355,8 +1352,7 @@ def create_instance(request, compute_id, arch, machine):
|
||||||
is_disk_created = True
|
is_disk_created = True
|
||||||
else:
|
else:
|
||||||
if not data['images']:
|
if not data['images']:
|
||||||
error_msg = _("First you need to create or select an image")
|
raise libvirtError(_("First you need to create or select an image"))
|
||||||
messages.error(request, error_msg)
|
|
||||||
else:
|
else:
|
||||||
for idx, vol in enumerate(data['images'].split(',')):
|
for idx, vol in enumerate(data['images'].split(',')):
|
||||||
path = conn.get_volume_path(vol)
|
path = conn.get_volume_path(vol)
|
||||||
|
@ -1375,7 +1371,7 @@ def create_instance(request, compute_id, arch, machine):
|
||||||
volume_list.append(volume)
|
volume_list.append(volume)
|
||||||
if data['cache_mode'] not in conn.get_cache_modes():
|
if data['cache_mode'] not in conn.get_cache_modes():
|
||||||
error_msg = _("Invalid cache mode")
|
error_msg = _("Invalid cache mode")
|
||||||
messages.error(request ,error_msg)
|
raise libvirtError
|
||||||
|
|
||||||
if 'UEFI' in data["firmware"]:
|
if 'UEFI' in data["firmware"]:
|
||||||
firmware["loader"] = data["firmware"].split(":")[1].strip()
|
firmware["loader"] = data["firmware"].split(":")[1].strip()
|
||||||
|
@ -1422,6 +1418,8 @@ def create_instance(request, compute_id, arch, machine):
|
||||||
conn.delete_volume(vol['path'])
|
conn.delete_volume(vol['path'])
|
||||||
messages.error(request, lib_err)
|
messages.error(request, lib_err)
|
||||||
conn.close()
|
conn.close()
|
||||||
|
except libvirtError as lib_err:
|
||||||
|
messages.error(request, lib_err)
|
||||||
return render(request, 'create_instance_w2.html', locals())
|
return render(request, 'create_instance_w2.html', locals())
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -283,6 +283,10 @@ class wvmCreate(wvmConnect):
|
||||||
else:
|
else:
|
||||||
xml += """<target dev='sd%s'/>""" % sd_disk_letters.pop(0)
|
xml += """<target dev='sd%s'/>""" % sd_disk_letters.pop(0)
|
||||||
xml += """</disk>"""
|
xml += """</disk>"""
|
||||||
|
|
||||||
|
if volume.get('bus') == 'scsi':
|
||||||
|
xml += f"""<controller type='scsi' model='{volume.get('scsi_model')}'/>"""
|
||||||
|
|
||||||
if add_cd:
|
if add_cd:
|
||||||
xml += """<disk type='file' device='cdrom'>
|
xml += """<disk type='file' device='cdrom'>
|
||||||
<driver name='qemu' type='raw'/>
|
<driver name='qemu' type='raw'/>
|
||||||
|
@ -298,9 +302,6 @@ class wvmCreate(wvmConnect):
|
||||||
xml += """<target dev='vd%s' bus='%s'/>""" % (vd_disk_letters.pop(0), 'virtio')
|
xml += """<target dev='vd%s' bus='%s'/>""" % (vd_disk_letters.pop(0), 'virtio')
|
||||||
xml += """</disk>"""
|
xml += """</disk>"""
|
||||||
|
|
||||||
if volume.get('bus') == 'scsi':
|
|
||||||
xml += f"""<controller type='scsi' model='{volume.get('scsi_model')}'/>"""
|
|
||||||
|
|
||||||
for net in networks.split(','):
|
for net in networks.split(','):
|
||||||
xml += """<interface type='network'>"""
|
xml += """<interface type='network'>"""
|
||||||
if mac:
|
if mac:
|
||||||
|
|
Loading…
Reference in a new issue