From 04f3a76c05aa9cf2656859d32dbb483d97fc5981 Mon Sep 17 00:00:00 2001 From: Jan Krcmar Date: Tue, 24 Nov 2015 08:53:13 +0000 Subject: [PATCH] resize disk image option added --- instances/templates/instance.html | 9 +++++++++ instances/views.py | 25 ++++++++++++++++++++++++- vrtManager/instance.py | 7 ++++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/instances/templates/instance.html b/instances/templates/instance.html index c3baecc..fb2075c 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -355,6 +355,15 @@ {% trans "Custom value" %} +

{% trans "Disk allocation (B):" %}

+ {% for disk in disks %} +
+ +
+ +
+
+ {% endfor %} {% ifequal status 5 %} {% else %} diff --git a/instances/views.py b/instances/views.py index 29a1a1b..a68f52c 100644 --- a/instances/views.py +++ b/instances/views.py @@ -186,6 +186,23 @@ def instance(request, compute_id, vname): {'dev': disk['dev'], 'storage': disk['storage'], 'image': image, 'format': disk['format']}) return clone_disk + + def filesizefstr(size_str): + if size_str == '': + return 0 + size_str = size_str.encode('ascii', 'ignore').upper().translate(None, " B") + if 'K' == size_str[-1]: + return long(float(size_str[:-1]))<<10 + elif 'M' == size_str[-1]: + return long(float(size_str[:-1]))<<20 + elif 'G' == size_str[-1]: + return long(float(size_str[:-1]))<<30 + elif 'T' == size_str[-1]: + return long(float(size_str[:-1]))<<40 + elif 'P' == size_str[-1]: + return long(float(size_str[:-1]))<<50 + else: + return long(float(size_str)) try: conn = wvmInstance(compute.hostname, @@ -340,7 +357,13 @@ def instance(request, compute_id, vname): cur_memory_custom = request.POST.get('cur_memory_custom', '') if cur_memory_custom: cur_memory = cur_memory_custom - conn.resize(cur_memory, memory, cur_vcpu, vcpu) + disks_new = [] + for disk in disks: + input_disk_size = filesizefstr(request.POST.get('disk_size_' + disk['dev'], '')) + if input_disk_size > disk['size']+(64<<20): + disk['size_new'] = input_disk_size + disks_new.append(disk) + conn.resize(cur_memory, memory, cur_vcpu, vcpu, disks_new) msg = _("Resize") addlogmsg(request.user.username, instance.name, msg) return HttpResponseRedirect(request.get_full_path() + '#resize') diff --git a/vrtManager/instance.py b/vrtManager/instance.py index ceec977..fe003b1 100644 --- a/vrtManager/instance.py +++ b/vrtManager/instance.py @@ -524,7 +524,7 @@ class wvmInstance(wvmConnect): return util.get_xml_path(self._XMLDesc(VIR_DOMAIN_XML_SECURE), "/domain/devices/graphics/@keymap") or '' - def resize(self, cur_memory, memory, cur_vcpu, vcpu): + def resize(self, cur_memory, memory, cur_vcpu, vcpu, disks=[]): """ Function change ram and cpu on vds. """ @@ -542,6 +542,11 @@ class wvmInstance(wvmConnect): set_vcpu.text = vcpu set_vcpu.set('current', cur_vcpu) + for disk in disks: + source_dev = disk['path'] + vol = self.get_volume_by_path(source_dev) + vol.resize(disk['size_new']) + new_xml = ElementTree.tostring(tree) self._defineXML(new_xml)