X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=www%2Fmanager6%2Fqemu%2FCmdMenu.js;h=ccc5f74d4e4b4c73f6422d5d48dbbb28a3c858db;hb=refs%2Fheads%2Fmaster;hp=5e889c693d60882231260b7b19808d589f26799c;hpb=d59ed79b5d1ce383ada805b282e5d3c879477779;p=pve-manager.git diff --git a/www/manager6/qemu/CmdMenu.js b/www/manager6/qemu/CmdMenu.js index 5e889c69..834577e7 100644 --- a/www/manager6/qemu/CmdMenu.js +++ b/www/manager6/qemu/CmdMenu.js @@ -1,151 +1,178 @@ Ext.define('PVE.qemu.CmdMenu', { extend: 'Ext.menu.Menu', + showSeparator: false, initComponent: function() { - var me = this; + let me = this; - var nodename = me.pveSelNode.data.node; - if (!nodename) { + let info = me.pveSelNode.data; + if (!info.node) { throw "no node name specified"; } - - var vmid = me.pveSelNode.data.vmid; - if (!vmid) { + if (!info.vmid) { throw "no VM ID specified"; } - var vmname = me.pveSelNode.data.name; - - var vm_command = function(cmd, params) { - PVE.Utils.API2Request({ + let vm_command = function(cmd, params) { + Proxmox.Utils.API2Request({ params: params, - url: '/nodes/' + nodename + '/qemu/' + vmid + "/status/" + cmd, + url: `/nodes/${info.node}/${info.type}/${info.vmid}/status/${cmd}`, method: 'POST', - failure: function(response, opts) { - Ext.Msg.alert('Error', response.htmlStatus); + 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); } }); }; - me.title = "VM " + vmid; + 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'), - icon: '/pve2/images/start.png', - handler: function() { - vm_command('start'); - } + iconCls: 'fa fa-fw fa-play', + hidden: running || suspended, + disabled: running || suspended, + handler: () => vm_command('start'), }, - { - text: gettext('Migrate'), - icon: '/pve2/images/forward.png', - handler: function() { - var win = Ext.create('PVE.window.Migrate', { - vmtype: 'qemu', - nodename: nodename, - vmid: vmid - }); - win.show(); - } + { + text: gettext('Pause'), + iconCls: 'fa fa-fw fa-pause', + hidden: stopped || suspended, + disabled: stopped || suspended, + handler: () => confirmedVMCommand('suspend', undefined, 'qmpause'), }, { - text: gettext('Suspend'), - icon: '/pve2/images/forward.png', - handler: function() { - var msg = Ext.String.format(gettext("Do you really want to suspend {0}?"), 'VM ' + vmid); - Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) { - if (btn !== 'yes') { - return; - } - vm_command('suspend'); - }); - } + 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'), - icon: '/pve2/images/forward.png', - handler: function() { - vm_command('resume'); - } + iconCls: 'fa fa-fw fa-play', + hidden: !suspended, + handler: () => vm_command('resume'), }, { text: gettext('Shutdown'), - icon: '/pve2/images/stop.png', - handler: function() { - var msg = Ext.String.format(gettext("Do you really want to shutdown {0}?"), 'VM ' + vmid); - Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) { - if (btn !== 'yes') { - return; - } - - vm_command('shutdown'); - }); - } + iconCls: 'fa fa-fw fa-power-off', + disabled: stopped || suspended, + handler: () => confirmedVMCommand('shutdown'), }, { text: gettext('Stop'), - icon: '/pve2/images/gtk-stop.png', - handler: function() { - var msg = Ext.String.format(gettext("Do you really want to stop {0}?"), 'VM ' + vmid); - Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) { - if (btn !== 'yes') { - return; - } - - vm_command("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('Clone'), - icon: '/pve2/images/forward.png', + 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() { - var win = Ext.create('PVE.window.Clone', { - nodename: nodename, - vmid: vmid + Ext.create('PVE.window.Migrate', { + vmtype: 'qemu', + nodename: info.node, + vmid: info.vmid, + autoShow: true, }); - win.show(); - } + }, + }, + { + 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'), - icon: '/pve2/images/forward.png', + iconCls: 'fa fa-fw fa-file-o', + hidden: !caps.vms['VM.Allocate'], handler: function() { - var msg = Ext.String.format(gettext("Do you really want to convert {0} into a template?"), 'VM ' + vmid); - Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) { - if (btn !== 'yes') { - return; + 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), + }); } - - PVE.Utils.API2Request({ - url: '/nodes/' + nodename + '/qemu/' + vmid + '/template', - method: 'POST', - failure: function(response, opts) { - Ext.Msg.alert('Error', response.htmlStatus); - } - }); }); - } + }, }, + { xtype: 'menuseparator' }, { text: gettext('Console'), - icon: '/pve2/images/display.png', + iconCls: 'fa fa-fw fa-terminal', handler: function() { - PVE.Utils.API2Request({ - url: '/nodes/' + nodename + '/qemu/' + vmid + '/status/current', - failure: function(response, opts) { - Ext.Msg.alert('Error', response.htmlStatus); + 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, + ); }, - success: function(response, opts) { - var allowSpice = response.result.data.spice; - PVE.Utils.openDefaultConsoleWindow(allowSpice, 'kvm', vmid, nodename, vmname); - } }); - } - } + }, + }, ]; me.callParent(); - } + }, });