1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-25 23:55:24 +00:00

resize disk image option added

This commit is contained in:
Jan Krcmar 2015-11-24 08:53:13 +00:00
parent 8f2f95e128
commit 04f3a76c05
3 changed files with 39 additions and 2 deletions

View file

@ -355,6 +355,15 @@
<small><input type="checkbox" class="js-custom__checkbox" /> {% trans "Custom value" %}</small> <small><input type="checkbox" class="js-custom__checkbox" /> {% trans "Custom value" %}</small>
</div> </div>
</div> </div>
<p style="font-weight:bold;">{% trans "Disk allocation (B):" %}</p>
{% for disk in disks %}
<div class="form-group">
<label class="col-sm-4 control-label" style="font-weight:normal;">{% trans "Current allocation" %} ({{ disk.dev }})</label>
<div class="col-sm-4 js-custom__container">
<input type="text" name="disk_size_{{ disk.dev }}" class="form-control" value="{{ disk.size|filesizeformat }}" />
</div>
</div>
{% endfor %}
{% ifequal status 5 %} {% ifequal status 5 %}
<button type="submit" class="btn btn-lg btn-success pull-right" name="resize">{% trans "Resize" %}</button> <button type="submit" class="btn btn-lg btn-success pull-right" name="resize">{% trans "Resize" %}</button>
{% else %} {% else %}

View file

@ -187,6 +187,23 @@ def instance(request, compute_id, vname):
'image': image, 'format': disk['format']}) 'image': image, 'format': disk['format']})
return clone_disk 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: try:
conn = wvmInstance(compute.hostname, conn = wvmInstance(compute.hostname,
compute.login, compute.login,
@ -340,7 +357,13 @@ def instance(request, compute_id, vname):
cur_memory_custom = request.POST.get('cur_memory_custom', '') cur_memory_custom = request.POST.get('cur_memory_custom', '')
if cur_memory_custom: if cur_memory_custom:
cur_memory = 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") 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')

View file

@ -524,7 +524,7 @@ class wvmInstance(wvmConnect):
return util.get_xml_path(self._XMLDesc(VIR_DOMAIN_XML_SECURE), return util.get_xml_path(self._XMLDesc(VIR_DOMAIN_XML_SECURE),
"/domain/devices/graphics/@keymap") or '' "/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. Function change ram and cpu on vds.
""" """
@ -542,6 +542,11 @@ class wvmInstance(wvmConnect):
set_vcpu.text = vcpu set_vcpu.text = vcpu
set_vcpu.set('current', cur_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) new_xml = ElementTree.tostring(tree)
self._defineXML(new_xml) self._defineXML(new_xml)