Files
dualfroz f1c3f66086 fix #5871: ui: resize disk: show current and new size
The resize dialogs of VMs and containers only ask for the size
increment, so users have to look up the current size of the disk in
the config to know which size the disk will have afterwards.

Load the config of the guest in the dialogs and show the current size
of the disk, and the size it will have with the entered increment,
which gets updated while typing. As the dialogs load the size
themselves, callers do not need to change.

The size of the config is in the 'disk-size' format, where the units
are binary, while Proxmox.Utils.parse_size_unit() takes 'G' as GB, so
add a small parser for it, like parse_size() of PVE::JSONSchema.

Signed-off-by: Michal Fox <me@dualfroz.com>
2026-10-03 03:28:43 +02:00

138 lines
4.0 KiB
JavaScript

Ext.define('PVE.window.MPResize', {
extend: 'Ext.window.Window',
resizable: false,
resize_disk: function (disk, size) {
var me = this;
var params = { disk: disk, size: '+' + size + 'G' };
Proxmox.Utils.API2Request({
params: params,
url: '/nodes/' + me.nodename + '/lxc/' + me.vmid + '/resize',
waitMsgTarget: me,
method: 'PUT',
failure: function (response, opts) {
Ext.Msg.alert(gettext('Error'), response.htmlStatus);
},
success: function (response, opts) {
var upid = response.result.data;
var win = Ext.create('Proxmox.window.TaskViewer', { upid: upid });
win.show();
me.close();
},
});
},
updateNewSize: function () {
let me = this;
let newSize = '';
if (me.currentSize !== undefined && me.hdsizesel.isValid()) {
newSize = Proxmox.Utils.format_size(
me.currentSize + me.hdsizesel.getValue() * 1024 ** 3,
);
}
me.down('#newSize').setValue(newSize);
},
initComponent: function () {
var me = this;
if (!me.nodename) {
throw 'no node name specified';
}
if (!me.vmid) {
throw 'no VM ID specified';
}
var items = [
{
xtype: 'displayfield',
name: 'disk',
value: me.disk,
fieldLabel: gettext('Disk'),
vtype: 'StorageId',
allowBlank: false,
},
{
xtype: 'displayfield',
itemId: 'currentSize',
fieldLabel: gettext('Current Size'),
},
];
me.hdsizesel = Ext.createWidget('numberfield', {
name: 'size',
minValue: 0,
maxValue: 128 * 1024,
decimalPrecision: 3,
value: '0',
fieldLabel: `${gettext('Size Increment')} (${gettext('GiB')})`,
allowBlank: false,
listeners: {
change: () => me.updateNewSize(),
},
});
items.push(me.hdsizesel);
items.push({
xtype: 'displayfield',
itemId: 'newSize',
fieldLabel: gettext('New Size'),
});
me.formPanel = Ext.create('Ext.form.Panel', {
bodyPadding: 10,
border: false,
fieldDefaults: {
labelWidth: 120,
anchor: '100%',
},
items: items,
});
var form = me.formPanel.getForm();
var submitBtn;
me.title = gettext('Resize disk');
submitBtn = Ext.create('Ext.Button', {
text: gettext('Resize disk'),
handler: function () {
if (form.isValid()) {
let values = form.getValues();
me.resize_disk(me.disk, values.size);
}
},
});
Ext.apply(me, {
modal: true,
border: false,
layout: 'fit',
buttons: [submitBtn],
items: [me.formPanel],
});
me.callParent();
Proxmox.Utils.API2Request({
url: `/nodes/${me.nodename}/lxc/${me.vmid}/config`,
method: 'GET',
waitMsgTarget: me,
failure: (response) => Ext.Msg.alert(gettext('Error'), response.htmlStatus),
success: function (response) {
let size = PVE.Parser.parseLxcMountPoint(response.result.data[me.disk])?.size;
me.currentSize = size ? PVE.Utils.parse_disk_size(size) : undefined;
me.down('#currentSize').setValue(
me.currentSize !== undefined
? Proxmox.Utils.format_size(me.currentSize)
: Proxmox.Utils.unknownText,
);
me.updateNewSize();
},
});
},
});