mirror of
https://github.com/retspen/webvirtcloud
synced 2024-10-31 19:44:16 +00:00
resize disk image option added
This commit is contained in:
parent
8f2f95e128
commit
04f3a76c05
3 changed files with 39 additions and 2 deletions
|
@ -355,6 +355,15 @@
|
|||
<small><input type="checkbox" class="js-custom__checkbox" /> {% trans "Custom value" %}</small>
|
||||
</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 %}
|
||||
<button type="submit" class="btn btn-lg btn-success pull-right" name="resize">{% trans "Resize" %}</button>
|
||||
{% else %}
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue