1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2025-03-19 19:42:59 +00:00

instances/view.py: Fix resize_disk and pep8 style corrections

This commit is contained in:
catborise 2019-09-10 09:45:49 +03:00
parent 1e22547b1a
commit fdbb6739c1

View file

@ -27,6 +27,7 @@ from logs.views import addlogmsg
from django.conf import settings from django.conf import settings
from django.contrib import messages from django.contrib import messages
@login_required @login_required
def index(request): def index(request):
""" """
@ -514,17 +515,13 @@ def instance(request, compute_id, vname):
msg = _("User %s quota reached, cannot resize disks of '%s'!" % (quota_msg, instance.name)) msg = _("User %s quota reached, cannot resize disks of '%s'!" % (quota_msg, instance.name))
error_messages.append(msg) error_messages.append(msg)
else: else:
cur_memory = new_cur_memory conn.resize_disk(disks_new)
memory = new_memory
cur_vcpu = new_cur_vcpu
vcpu = new_vcpu
conn.resize(cur_memory, memory, cur_vcpu, vcpu, disks_new)
msg = _("Resize") msg = _("Resize")
addlogmsg(request.user.username, instance.name, msg) addlogmsg(request.user.username, instance.name, msg)
return HttpResponseRedirect(request.get_full_path() + '#resize') return HttpResponseRedirect(request.get_full_path() + '#resize')
if 'add_new_vol' in request.POST and allow_admin_or_not_template: if 'add_new_vol' in request.POST and allow_admin_or_not_template:
connCreate = wvmCreate(compute.hostname, conn_create = wvmCreate(compute.hostname,
compute.login, compute.login,
compute.password, compute.password,
compute.type) compute.type)
@ -537,7 +534,7 @@ def instance(request, compute_id, vname):
cache = request.POST.get('cache', default_cache) cache = request.POST.get('cache', default_cache)
target = get_new_disk_dev(media, disks, bus) target = get_new_disk_dev(media, disks, bus)
path = connCreate.create_volume(storage, name, size, format, meta_prealloc, default_owner) path = conn_create.create_volume(storage, name, size, format, meta_prealloc, default_owner)
conn.attach_disk(path, target, subdriver=format, cache=cache, targetbus=bus) conn.attach_disk(path, target, subdriver=format, cache=cache, targetbus=bus)
msg = _('Attach new disk {} ({})'.format(name, format)) msg = _('Attach new disk {} ({})'.format(name, format))
addlogmsg(request.user.username, instance.name, msg) addlogmsg(request.user.username, instance.name, msg)
@ -549,16 +546,16 @@ def instance(request, compute_id, vname):
bus = request.POST.get('bus', default_bus) bus = request.POST.get('bus', default_bus)
cache = request.POST.get('cache', default_cache) cache = request.POST.get('cache', default_cache)
connCreate = wvmStorage(compute.hostname, conn_create = wvmStorage(compute.hostname,
compute.login, compute.login,
compute.password, compute.password,
compute.type, compute.type,
storage) storage)
format = connCreate.get_volume_type(name) format = conn_create.get_volume_type(name)
path = connCreate.get_target_path() path = conn_create.get_target_path()
target = get_new_disk_dev(media, disks, bus) target = get_new_disk_dev(media, disks, bus)
source = path + "/" + name; source = path + "/" + name
conn.attach_disk(source, target, subdriver=format, cache=cache, targetbus=bus) conn.attach_disk(source, target, subdriver=format, cache=cache, targetbus=bus)
msg = _('Attach Existing disk: ' + target) msg = _('Attach Existing disk: ' + target)
@ -567,7 +564,7 @@ def instance(request, compute_id, vname):
if 'delete_vol' in request.POST and allow_admin_or_not_template: if 'delete_vol' in request.POST and allow_admin_or_not_template:
storage = request.POST.get('storage', '') storage = request.POST.get('storage', '')
connDelete = wvmStorage(compute.hostname, conn_delete = wvmStorage(compute.hostname,
compute.login, compute.login,
compute.password, compute.password,
compute.type, compute.type,
@ -577,7 +574,7 @@ def instance(request, compute_id, vname):
name = request.POST.get('name', '') name = request.POST.get('name', '')
conn.detach_disk(dev) conn.detach_disk(dev)
connDelete.del_volume(name) conn_delete.del_volume(name)
msg = _('Delete disk: ' + dev) msg = _('Delete disk: ' + dev)
addlogmsg(request.user.username, instance.name, msg) addlogmsg(request.user.username, instance.name, msg)
@ -688,8 +685,8 @@ def instance(request, compute_id, vname):
if bootorder: if bootorder:
order_list = {} order_list = {}
for idx, val in enumerate(bootorder.split(',')): for idx, val in enumerate(bootorder.split(',')):
type, dev = val.split(':', 1) dev_type, dev = val.split(':', 1)
order_list[idx] = {"type": type, "dev": dev} order_list[idx] = {"type": dev_type, "dev": dev}
conn.set_bootorder(order_list) conn.set_bootorder(order_list)
msg = _("Set boot order") msg = _("Set boot order")
@ -859,7 +856,7 @@ def instance(request, compute_id, vname):
elif not re.match(r'^[a-zA-Z0-9-]+$', clone_data['name']): elif not re.match(r'^[a-zA-Z0-9-]+$', clone_data['name']):
msg = _("Instance name '%s' contains invalid characters!" % clone_data['name']) msg = _("Instance name '%s' contains invalid characters!" % clone_data['name'])
error_messages.append(msg) error_messages.append(msg)
elif not re.match(r'^([0-9A-F]{2})(\:?[0-9A-F]{2}){5}$', clone_data['clone-net-mac-0'], elif not re.match(r'^([0-9A-F]{2})(:?[0-9A-F]{2}){5}$', clone_data['clone-net-mac-0'],
re.IGNORECASE): re.IGNORECASE):
msg = _("Instance mac '%s' invalid format!" % clone_data['clone-net-mac-0']) msg = _("Instance mac '%s' invalid format!" % clone_data['clone-net-mac-0'])
error_messages.append(msg) error_messages.append(msg)
@ -1052,7 +1049,7 @@ def instances_actions(request):
return HttpResponseRedirect(request.get_full_path()) return HttpResponseRedirect(request.get_full_path())
if 'powerforce' in request.POST: if 'powerforce' in request.POST:
conn.force_shutdown() conn.force_shutdown(name)
msg = _("Force Off") msg = _("Force Off")
addlogmsg(request.user.username, instance.name, msg) addlogmsg(request.user.username, instance.name, msg)
return HttpResponseRedirect(request.get_full_path()) return HttpResponseRedirect(request.get_full_path())
@ -1243,7 +1240,7 @@ def _get_clone_disks(disks, vname=''):
def sshkeys(request, vname): def sshkeys(request, vname):
""" """
:param request: :param request:
:param vm: :param vname:
:return: :return:
""" """