mirror of
https://git.proxmox.com/git/pve-manager
synced 2025-10-09 18:14:21 +00:00

Implement a new "guest stop" confirmation message box which first checks if there is an active shutdown task for the same guest that is visible to the logged-in user. If there is at least one, the dialog displays an additional default-on checkbox for overruling active shutdown tasks. If the user confirms and the checkbox is checked, the UI sends a guest stop API request with the `overrule-shutdown` parameter set to 1. If there are no active shutdown tasks, or the checkbox is unchecked, the UI sends a guest stop API request without `overrule-shutdown`. To avoid an additional API request for querying active shutdown tasks, check the UI's current view of cluster tasks instead, which is fetched from the `pve-cluster-tasks` store. As the UI might hold an outdated task list, there are some opportunities for races, e.g., the UI may miss a new shutdown task or consider a shutdown task active even though it has already terminated. These races either result in a surviving shutdown task that the user still needs to abort manually, or a superfluous `override-shutdown=1` parameter that does not actually abort any tasks. Since "stop overrules shutdown" is merely a convenience feature, both outcomes seem bearable. The confirmation message box is now always marked as dangerous (with a warning sign icon), whereas previously it was only marked dangerous if the stop issued from the guest panel, but not when issued from the resource tree command menu. Signed-off-by: Friedrich Weber <f.weber@proxmox.com> Reviewed-by: Dominik Csapak <d.csapak@proxmox.com> [ TL: squash in some slightly opinionated code/style clean-ups ] Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
179 lines
4.4 KiB
JavaScript
179 lines
4.4 KiB
JavaScript
Ext.define('PVE.qemu.CmdMenu', {
|
|
extend: 'Ext.menu.Menu',
|
|
|
|
showSeparator: false,
|
|
initComponent: function() {
|
|
let me = this;
|
|
|
|
let info = me.pveSelNode.data;
|
|
if (!info.node) {
|
|
throw "no node name specified";
|
|
}
|
|
if (!info.vmid) {
|
|
throw "no VM ID specified";
|
|
}
|
|
|
|
let vm_command = function(cmd, params) {
|
|
Proxmox.Utils.API2Request({
|
|
params: params,
|
|
url: `/nodes/${info.node}/${info.type}/${info.vmid}/status/${cmd}`,
|
|
method: 'POST',
|
|
failure: (response, opts) => Ext.Msg.alert(gettext('Error'), response.htmlStatus),
|
|
});
|
|
};
|
|
let confirmedVMCommand = (cmd, params, confirmTask) => {
|
|
let task = confirmTask || `qm${cmd}`;
|
|
let msg = Proxmox.Utils.format_task_description(task, info.vmid);
|
|
Ext.Msg.confirm(gettext('Confirm'), msg, btn => {
|
|
if (btn === 'yes') {
|
|
vm_command(cmd, params);
|
|
}
|
|
});
|
|
};
|
|
|
|
let caps = Ext.state.Manager.get('GuiCap');
|
|
let standalone = PVE.Utils.isStandaloneNode();
|
|
|
|
let running = false, stopped = true, suspended = false;
|
|
switch (info.status) {
|
|
case 'running':
|
|
running = true;
|
|
stopped = false;
|
|
break;
|
|
case 'suspended':
|
|
stopped = false;
|
|
suspended = true;
|
|
break;
|
|
case 'paused':
|
|
stopped = false;
|
|
suspended = true;
|
|
break;
|
|
default: break;
|
|
}
|
|
|
|
me.title = "VM " + info.vmid;
|
|
|
|
me.items = [
|
|
{
|
|
text: gettext('Start'),
|
|
iconCls: 'fa fa-fw fa-play',
|
|
hidden: running || suspended,
|
|
disabled: running || suspended,
|
|
handler: () => vm_command('start'),
|
|
},
|
|
{
|
|
text: gettext('Pause'),
|
|
iconCls: 'fa fa-fw fa-pause',
|
|
hidden: stopped || suspended,
|
|
disabled: stopped || suspended,
|
|
handler: () => confirmedVMCommand('suspend', undefined, 'qmpause'),
|
|
},
|
|
{
|
|
text: gettext('Hibernate'),
|
|
iconCls: 'fa fa-fw fa-download',
|
|
hidden: stopped || suspended,
|
|
disabled: stopped || suspended,
|
|
tooltip: gettext('Suspend to disk'),
|
|
handler: () => confirmedVMCommand('suspend', { todisk: 1 }),
|
|
},
|
|
{
|
|
text: gettext('Resume'),
|
|
iconCls: 'fa fa-fw fa-play',
|
|
hidden: !suspended,
|
|
handler: () => vm_command('resume'),
|
|
},
|
|
{
|
|
text: gettext('Shutdown'),
|
|
iconCls: 'fa fa-fw fa-power-off',
|
|
disabled: stopped || suspended,
|
|
handler: () => confirmedVMCommand('shutdown'),
|
|
},
|
|
{
|
|
text: gettext('Stop'),
|
|
iconCls: 'fa fa-fw fa-stop',
|
|
disabled: stopped,
|
|
tooltip: Ext.String.format(gettext('Stop {0} immediately'), 'VM'),
|
|
handler: () => {
|
|
Ext.create('PVE.GuestStop', {
|
|
nodename: info.node,
|
|
vm: info,
|
|
autoShow: true,
|
|
});
|
|
},
|
|
},
|
|
{
|
|
text: gettext('Reboot'),
|
|
iconCls: 'fa fa-fw fa-refresh',
|
|
disabled: stopped,
|
|
tooltip: Ext.String.format(gettext('Reboot {0}'), 'VM'),
|
|
handler: () => confirmedVMCommand('reboot'),
|
|
},
|
|
{
|
|
xtype: 'menuseparator',
|
|
hidden: (standalone || !caps.vms['VM.Migrate']) && !caps.vms['VM.Allocate'] && !caps.vms['VM.Clone'],
|
|
},
|
|
{
|
|
text: gettext('Migrate'),
|
|
iconCls: 'fa fa-fw fa-send-o',
|
|
hidden: standalone || !caps.vms['VM.Migrate'],
|
|
handler: function() {
|
|
Ext.create('PVE.window.Migrate', {
|
|
vmtype: 'qemu',
|
|
nodename: info.node,
|
|
vmid: info.vmid,
|
|
autoShow: true,
|
|
});
|
|
},
|
|
},
|
|
{
|
|
text: gettext('Clone'),
|
|
iconCls: 'fa fa-fw fa-clone',
|
|
hidden: !caps.vms['VM.Clone'],
|
|
handler: () => PVE.window.Clone.wrap(info.node, info.vmid, me.isTemplate, 'qemu'),
|
|
},
|
|
{
|
|
text: gettext('Convert to template'),
|
|
iconCls: 'fa fa-fw fa-file-o',
|
|
hidden: !caps.vms['VM.Allocate'],
|
|
handler: function() {
|
|
let msg = Proxmox.Utils.format_task_description('qmtemplate', info.vmid);
|
|
Ext.Msg.confirm(gettext('Confirm'), msg, btn => {
|
|
if (btn === 'yes') {
|
|
Proxmox.Utils.API2Request({
|
|
url: `/nodes/${info.node}/qemu/${info.vmid}/template`,
|
|
method: 'POST',
|
|
failure: (response, opts) => Ext.Msg.alert('Error', response.htmlStatus),
|
|
});
|
|
}
|
|
});
|
|
},
|
|
},
|
|
{ xtype: 'menuseparator' },
|
|
{
|
|
text: gettext('Console'),
|
|
iconCls: 'fa fa-fw fa-terminal',
|
|
handler: function() {
|
|
Proxmox.Utils.API2Request({
|
|
url: `/nodes/${info.node}/qemu/${info.vmid}/status/current`,
|
|
failure: (response, opts) => Ext.Msg.alert('Error', response.htmlStatus),
|
|
success: function({ result: { data } }, opts) {
|
|
PVE.Utils.openDefaultConsoleWindow(
|
|
{
|
|
spice: data.spice,
|
|
xtermjs: data.serial,
|
|
},
|
|
'kvm',
|
|
info.vmid,
|
|
info.node,
|
|
info.name,
|
|
);
|
|
},
|
|
});
|
|
},
|
|
},
|
|
];
|
|
|
|
me.callParent();
|
|
},
|
|
});
|