1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-10-31 19:44:16 +00:00

fix instance create error handling

This commit is contained in:
catborise 2020-08-17 09:58:42 +03:00
parent 6d52587e60
commit 83ba6da572
2 changed files with 163 additions and 164 deletions

View file

@ -1242,6 +1242,7 @@ def create_instance(request, compute_id, arch, machine):
flavors = Flavor.objects.filter().order_by('id')
appsettings = AppSettings.objects.all()
try:
conn = wvmCreate(compute.hostname, compute.login, compute.password, compute.type)
default_firmware = app_settings.INSTANCE_FIRMWARE_DEFAULT_TYPE
@ -1285,11 +1286,9 @@ def create_instance(request, compute_id, arch, machine):
if conn:
if not storages:
msg = _("You haven't defined any storage pools")
messages.error(request, msg)
raise libvirtError(_("You haven't defined any storage pools"))
if not networks:
msg = _("You haven't defined any network pools")
messages.error(request, msg)
raise libvirtError(_("You haven't defined any network pools"))
if request.method == 'POST':
if 'create' in request.POST:
@ -1304,14 +1303,13 @@ def create_instance(request, compute_id, arch, machine):
meta_prealloc = True
if instances:
if data['name'] in instances:
msg = _("A virtual machine with this name already exists")
messages.error(request, msg)
raise libvirtError(_("A virtual machine with this name already exists"))
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 not data['mac']:
error_msg = _("No Virtual Machine MAC has been entered")
messages.error(request, msg)
raise libvirtError(_("No Virtual Machine MAC has been entered"))
else:
path = conn.create_volume(data['storage'], data['name'], data['hdd_size'], default_disk_format,
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'])
dest_vol = conn.get_volume_path(data["name"] + ".img", data['storage'])
if dest_vol:
error_msg = _("Image has already exist. Please check volumes or change instance name")
messages.error(request, error_msg)
raise libvirtError(_("Image has already exist. Please check volumes or change instance name"))
else:
clone_path = conn.clone_from_template(data['name'], templ_path, data['storage'], meta_prealloc,
default_disk_owner_uid, default_disk_owner_gid)
@ -1355,8 +1352,7 @@ def create_instance(request, compute_id, arch, machine):
is_disk_created = True
else:
if not data['images']:
error_msg = _("First you need to create or select an image")
messages.error(request, error_msg)
raise libvirtError(_("First you need to create or select an image"))
else:
for idx, vol in enumerate(data['images'].split(',')):
path = conn.get_volume_path(vol)
@ -1375,7 +1371,7 @@ def create_instance(request, compute_id, arch, machine):
volume_list.append(volume)
if data['cache_mode'] not in conn.get_cache_modes():
error_msg = _("Invalid cache mode")
messages.error(request ,error_msg)
raise libvirtError
if 'UEFI' in data["firmware"]:
firmware["loader"] = data["firmware"].split(":")[1].strip()
@ -1422,6 +1418,8 @@ def create_instance(request, compute_id, arch, machine):
conn.delete_volume(vol['path'])
messages.error(request, lib_err)
conn.close()
except libvirtError as lib_err:
messages.error(request, lib_err)
return render(request, 'create_instance_w2.html', locals())

View file

@ -283,6 +283,10 @@ class wvmCreate(wvmConnect):
else:
xml += """<target dev='sd%s'/>""" % sd_disk_letters.pop(0)
xml += """</disk>"""
if volume.get('bus') == 'scsi':
xml += f"""<controller type='scsi' model='{volume.get('scsi_model')}'/>"""
if add_cd:
xml += """<disk type='file' device='cdrom'>
<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 += """</disk>"""
if volume.get('bus') == 'scsi':
xml += f"""<controller type='scsi' model='{volume.get('scsi_model')}'/>"""
for net in networks.split(','):
xml += """<interface type='network'>"""
if mac: