mirror of
https://github.com/retspen/webvirtcloud
synced 2024-10-31 19:44:16 +00:00
instance: seperate resize operations as cpu, mem and disk
This commit is contained in:
parent
b18290794e
commit
e47f97facf
3 changed files with 169 additions and 14 deletions
|
@ -341,17 +341,27 @@
|
|||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="resize">
|
||||
<div role="tabpanel">
|
||||
<!-- Nav tabs -->
|
||||
<ul class="nav nav-tabs" role="tablist">
|
||||
<li role="presentation" class="active">
|
||||
<a href="#resizevm" aria-controls="resizevm" role="tab" data-toggle="tab">
|
||||
{% trans "Resize Instance" %}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- Tab panes -->
|
||||
<!-- Nav tabs -->
|
||||
<ul class="nav nav-tabs" role="tablist">
|
||||
<li role="presentation" class="active">
|
||||
<a href="#resizevm_cpu" aria-controls="resizevm_cpu" role="tab" data-toggle="tab">
|
||||
{% trans "CPU" %}
|
||||
</a>
|
||||
</li>
|
||||
<li role="presentation">
|
||||
<a href="#resizevm_mem" aria-controls="resizevm_mem" role="tab" data-toggle="tab">
|
||||
{% trans "Memory" %}
|
||||
</a>
|
||||
</li>
|
||||
<li role="presentation">
|
||||
<a href="#resizevm_disk" aria-controls="resizevm_disk" role="tab" data-toggle="tab">
|
||||
{% trans "Disk" %}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- Tab panes -->
|
||||
<div class="tab-content">
|
||||
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="resizevm">
|
||||
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="resizevm_cpu">
|
||||
{% if request.user.is_superuser or request.user.is_staff or userinstance.is_change %}
|
||||
<form class="form-horizontal" method="post" role="form">{% csrf_token %}
|
||||
<p style="font-weight:bold;">{% trans "Logical host CPUs" %} : {{ vcpu_host }}</p>
|
||||
|
@ -379,6 +389,22 @@
|
|||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% ifequal status 5 %}
|
||||
<button type="submit" class="btn btn-lg btn-success pull-right" name="resizevm_cpu">{% trans "Resize" %}</button>
|
||||
{% else %}
|
||||
<button class="btn btn-lg btn-success pull-right disabled">{% trans "Resize" %}</button>
|
||||
{% endifequal %}
|
||||
</form>
|
||||
{% else %}
|
||||
{% trans "You don't have permission for resizing instance" %}
|
||||
<button class="btn btn-lg btn-success pull-right disabled">{% trans "Resize" %}</button>
|
||||
{% endif %}
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="resizevm_mem">
|
||||
{% if request.user.is_superuser or request.user.is_staff or userinstance.is_change %}
|
||||
<form class="form-horizontal" method="post" role="form">{% csrf_token %}
|
||||
<p style="font-weight:bold;">{% trans "Total host memory:" %} {{ memory_host|filesizeformat }}</p>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label" style="font-weight:normal;">{% trans "Current allocation" %} ({% trans "MB" %})</label>
|
||||
|
@ -406,6 +432,21 @@
|
|||
<small><input type="checkbox" class="js-custom__checkbox" /> {% trans "Custom value" %}</small>
|
||||
</div>
|
||||
</div>
|
||||
{% ifequal status 5 %}
|
||||
<button type="submit" class="btn btn-lg btn-success pull-right" name="resizevm_mem">{% trans "Resize" %}</button>
|
||||
{% else %}
|
||||
<button class="btn btn-lg btn-success pull-right disabled">{% trans "Resize" %}</button>
|
||||
{% endifequal %}
|
||||
</form>
|
||||
{% else %}
|
||||
{% trans "You don't have permission for resizing instance" %}
|
||||
<button class="btn btn-lg btn-success pull-right disabled">{% trans "Resize" %}</button>
|
||||
{% endif %}
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="resizevm_disk">
|
||||
{% if request.user.is_superuser or request.user.is_staff or userinstance.is_change %}
|
||||
<form class="form-horizontal" method="post" role="form">{% csrf_token %}
|
||||
<p style="font-weight:bold;">{% trans "Disk allocation (B):" %}</p>
|
||||
{% for disk in disks %}
|
||||
<div class="form-group">
|
||||
|
@ -416,9 +457,9 @@
|
|||
</div>
|
||||
{% endfor %}
|
||||
{% 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="resizevm_disk">{% trans "Resize" %}</button>
|
||||
{% else %}
|
||||
<button class="btn btn-lg btn-success pull-right disabled" name="resize">{% trans "Resize" %}</button>
|
||||
<button class="btn btn-lg btn-success pull-right disabled">{% trans "Resize" %}</button>
|
||||
{% endifequal %}
|
||||
</form>
|
||||
{% else %}
|
||||
|
@ -1867,7 +1908,7 @@
|
|||
}
|
||||
});
|
||||
}
|
||||
if (~$.inArray(hash, ['#resize'])) {
|
||||
if (~$.inArray(hash, ['#resize', "resizevm_cpu", "resizevm_mem", "resizevm_disk"])) {
|
||||
var btnsect = $('#navbtn>li>a');
|
||||
$(btnsect).each(function () {
|
||||
if ($(this).attr('href') === '#resize') {
|
||||
|
|
|
@ -460,6 +460,69 @@ def instance(request, compute_id, vname):
|
|||
addlogmsg(request.user.username, instance.name, msg)
|
||||
return HttpResponseRedirect(request.get_full_path() + '#resize')
|
||||
|
||||
if 'resizevm_cpu' in request.POST and (
|
||||
request.user.is_superuser or request.user.is_staff or userinstance.is_change):
|
||||
new_vcpu = request.POST.get('vcpu', '')
|
||||
new_cur_vcpu = request.POST.get('cur_vcpu', '')
|
||||
|
||||
quota_msg = check_user_quota(0, int(new_vcpu) - vcpu, 0, 0)
|
||||
if not request.user.is_superuser and quota_msg:
|
||||
msg = _("User %s quota reached, cannot resize CPU of '%s'!" % (quota_msg, instance.name))
|
||||
error_messages.append(msg)
|
||||
else:
|
||||
cur_vcpu = new_cur_vcpu
|
||||
vcpu = new_vcpu
|
||||
conn.resize_cpu(cur_vcpu, vcpu)
|
||||
msg = _("Resize CPU")
|
||||
addlogmsg(request.user.username, instance.name, msg)
|
||||
return HttpResponseRedirect(request.get_full_path() + '#resize')
|
||||
|
||||
if 'resizevm_mem' in request.POST and (
|
||||
request.user.is_superuser or request.user.is_staff or userinstance.is_change):
|
||||
new_memory = request.POST.get('memory', '')
|
||||
new_memory_custom = request.POST.get('memory_custom', '')
|
||||
if new_memory_custom:
|
||||
new_memory = new_memory_custom
|
||||
new_cur_memory = request.POST.get('cur_memory', '')
|
||||
new_cur_memory_custom = request.POST.get('cur_memory_custom', '')
|
||||
if new_cur_memory_custom:
|
||||
new_cur_memory = new_cur_memory_custom
|
||||
quota_msg = check_user_quota(0, 0, int(new_memory) - memory, 0)
|
||||
if not request.user.is_superuser and quota_msg:
|
||||
msg = _("User %s quota reached, cannot resize memory of '%s'!" % (quota_msg, instance.name))
|
||||
error_messages.append(msg)
|
||||
else:
|
||||
cur_memory = new_cur_memory
|
||||
memory = new_memory
|
||||
conn.resize_mem(cur_memory, memory)
|
||||
msg = _("Resize Memory")
|
||||
addlogmsg(request.user.username, instance.name, msg)
|
||||
return HttpResponseRedirect(request.get_full_path() + '#resize')
|
||||
|
||||
if 'resizevm_disk' in request.POST and (
|
||||
request.user.is_superuser or request.user.is_staff or userinstance.is_change):
|
||||
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)
|
||||
disk_sum = sum([disk['size'] >> 30 for disk in disks_new])
|
||||
disk_new_sum = sum([disk['size_new'] >> 30 for disk in disks_new])
|
||||
quota_msg = check_user_quota(0, 0, 0, disk_new_sum - disk_sum)
|
||||
if not request.user.is_superuser and quota_msg:
|
||||
msg = _("User %s quota reached, cannot resize disks of '%s'!" % (quota_msg, instance.name))
|
||||
error_messages.append(msg)
|
||||
else:
|
||||
cur_memory = new_cur_memory
|
||||
memory = new_memory
|
||||
cur_vcpu = new_cur_vcpu
|
||||
vcpu = new_vcpu
|
||||
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')
|
||||
|
||||
if 'add_new_vol' in request.POST and allow_admin_or_not_template:
|
||||
connCreate = wvmCreate(compute.hostname,
|
||||
compute.login,
|
||||
|
|
|
@ -741,7 +741,6 @@ class wvmInstance(wvmConnect):
|
|||
"""
|
||||
Function change ram and cpu on vds.
|
||||
"""
|
||||
|
||||
memory = int(memory) * 1024
|
||||
cur_memory = int(cur_memory) * 1024
|
||||
# if dom is running change only ram
|
||||
|
@ -769,6 +768,58 @@ class wvmInstance(wvmConnect):
|
|||
new_xml = ElementTree.tostring(tree)
|
||||
self._defineXML(new_xml)
|
||||
|
||||
def resize_cpu(self, cur_vcpu, vcpu):
|
||||
"""
|
||||
Function change ram and cpu on vds.
|
||||
"""
|
||||
xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE)
|
||||
tree = ElementTree.fromstring(xml)
|
||||
|
||||
set_vcpu = tree.find('vcpu')
|
||||
set_vcpu.text = vcpu
|
||||
set_vcpu.set('current', cur_vcpu)
|
||||
|
||||
new_xml = ElementTree.tostring(tree)
|
||||
self._defineXML(new_xml)
|
||||
|
||||
def resize_mem(self, cur_memory, memory):
|
||||
"""
|
||||
Function change ram and cpu on vds.
|
||||
"""
|
||||
memory = int(memory) * 1024
|
||||
cur_memory = int(cur_memory) * 1024
|
||||
# if dom is running change only ram
|
||||
if self.get_status() == VIR_DOMAIN_RUNNING:
|
||||
self.set_memory(cur_memory, VIR_DOMAIN_AFFECT_LIVE)
|
||||
self.set_memory(cur_memory, VIR_DOMAIN_AFFECT_CONFIG)
|
||||
return
|
||||
|
||||
xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE)
|
||||
tree = ElementTree.fromstring(xml)
|
||||
|
||||
set_mem = tree.find('memory')
|
||||
set_mem.text = str(memory)
|
||||
set_cur_mem = tree.find('currentMemory')
|
||||
set_cur_mem.text = str(cur_memory)
|
||||
|
||||
new_xml = ElementTree.tostring(tree)
|
||||
self._defineXML(new_xml)
|
||||
|
||||
def resize_disk(self, disks=[]):
|
||||
"""
|
||||
Function change disks on vds.
|
||||
"""
|
||||
xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE)
|
||||
tree = ElementTree.fromstring(xml)
|
||||
|
||||
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)
|
||||
|
||||
def get_iso_media(self):
|
||||
iso = []
|
||||
storages = self.get_storages(only_actives=True)
|
||||
|
|
Loading…
Reference in a new issue