1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 09:26:03 +00:00

fix(instances): the Resize tab changes only what was asked

Disk sizes were pre-filled rounded to whole GiB, so a 3.5 GiB disk showed
4 and was grown, for good, whenever another disk was resized; an empty
field or a disk outside a pool was a 500. A disk's field is now empty with
its size as the placeholder: an empty field leaves the disk alone, a
larger whole number grows it, anything else is refused with a message.

vCPUs change only on a shut-off VM, also on a direct request: a running
VM got them at its next start, past the quota counted against its live
count. Current vCPUs or memory above the maximum are refused instead of
failing (and dropping vCPU hot-plug) or being capped by libvirt. A running
VM's maximum memory select is disabled, since its maximum is kept, and a
custom memory value is sent only while its box is ticked.
This commit is contained in:
catborise 2026-10-26 12:06:11 +03:00
parent a4dd493a5e
commit 3ef8361bff
6 changed files with 114 additions and 11 deletions

View file

@ -320,6 +320,8 @@
var container = $(this).closest('.js-custom__container');
var toggles = container.find('.js-custom__toggle');
toggles.toggle();
// a custom value is sent only while its box is ticked
container.find('input.js-custom__toggle').prop('disabled', !this.checked);
});
});
</script>

View file

@ -97,7 +97,7 @@
<option value="{{ mem }}" {% if mem == instance.cur_memory %}selected{% endif %}>{{ mem }}</option>
{% endfor %}
</select>
<input type="text" name="cur_memory_custom" class="form-select js-custom__toggle" style="display: none" />
<input type="text" name="cur_memory_custom" class="form-select js-custom__toggle" style="display: none" disabled />
<small><input type="checkbox" class="js-custom__checkbox" /> {% trans "Custom value" %}</small>
</div>
</div>
@ -106,13 +106,18 @@
{% trans "Maximum Allocation" %} ({% trans "MB" %})
</label>
<div class="col-sm-4 js-custom__container">
<select name="memory" class="form-select js-custom__toggle">
{# a running VM keeps its maximum: only the current memory changes #}
<select name="memory" class="form-select js-custom__toggle"{% if instance.status != 5 %} disabled{% endif %}>
{% for mem in memory_range %}
<option value="{{ mem }}" {% if mem == instance.memory %}selected{% endif %}>{{ mem }}</option>
{% endfor %}
</select>
<input type="text" name="memory_custom" class="form-select js-custom__toggle" style="display: none" />
{% if instance.status == 5 %}
<input type="text" name="memory_custom" class="form-select js-custom__toggle" style="display: none" disabled />
<small><input type="checkbox" class="js-custom__checkbox" /> {% trans "Custom value" %}</small>
{% else %}
<small class="text-body-secondary">{% trans "Shut off the VM to change the maximum" %}</small>
{% endif %}
</div>
</div>
<button type="submit" class="btn btn-lg btn-success float-end" name="resizevm_mem">{% trans "Resize" %}</button>
@ -127,7 +132,7 @@
{% if can_change %}
<form action="{% url 'instances:resize_disk' instance.id %}" method="post" role="form" aria-label="Resize instance disk form">
{% csrf_token %}
<p class="fw-bold">{% trans "Disk allocation (GB)" %}:</p>
<p class="fw-bold">{% trans "New disk size (GiB); leave empty to keep a disk as it is" %}:</p>
{% for disk in instance.disks %}
<div class="row">
<label class="col-sm-4 col-form-label">{% trans "Current Allocation" %} ({{ disk.dev }})</label>
@ -139,7 +144,9 @@
</div>
{% else %}
<div class="col-sm-4 js-custom__container">
<input type="number" name="disk_size_{{ disk.dev }}" class="form-control" value="{% widthratio disk.size 1073741824 1 %}" />
{# empty: the disk stays as it is #}
<input type="number" name="disk_size_{{ disk.dev }}" class="form-control" min="1" step="1"
placeholder="{{ disk.size|filesizeformat }}" aria-label="{% trans "New size (GiB)" %} {{ disk.dev }}" />
</div>
{% endif %}
</div>