]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/lxc/CmdMenu.js
pvestatd: clear trailing newlines
[pve-manager.git] / www / manager6 / lxc / CmdMenu.js
1 Ext.define('PVE.lxc.CmdMenu', {
2 extend: 'Ext.menu.Menu',
3
4 showSeparator: false,
5 initComponent: function() {
6 let me = this;
7
8 let info = me.pveSelNode.data;
9 if (!info.node) {
10 throw "no node name specified";
11 }
12 if (!info.vmid) {
13 throw "no CT ID specified";
14 }
15
16 let vm_command = function(cmd, params) {
17 Proxmox.Utils.API2Request({
18 params: params,
19 url: `/nodes/${info.node}/${info.type}/${info.vmid}/status/${cmd}`,
20 method: 'POST',
21 failure: (response, opts) => Ext.Msg.alert(gettext('Error'), response.htmlStatus),
22 });
23 };
24 let confirmedVMCommand = (cmd, params) => {
25 let msg = Proxmox.Utils.format_task_description(`vz${cmd}`, info.vmid);
26 Ext.Msg.confirm(gettext('Confirm'), msg, btn => {
27 if (btn === 'yes') {
28 vm_command(cmd, params);
29 }
30 });
31 };
32
33 let caps = Ext.state.Manager.get('GuiCap');
34 let standalone = PVE.Utils.isStandaloneNode();
35
36 let running = false, stopped = true, suspended = false;
37 switch (info.status) {
38 case 'running':
39 running = true;
40 stopped = false;
41 break;
42 case 'paused':
43 stopped = false;
44 suspended = true;
45 break;
46 default: break;
47 }
48
49 me.title = 'CT ' + info.vmid;
50
51 me.items = [
52 {
53 text: gettext('Start'),
54 iconCls: 'fa fa-fw fa-play',
55 disabled: running,
56 handler: () => vm_command('start'),
57 },
58 {
59 text: gettext('Shutdown'),
60 iconCls: 'fa fa-fw fa-power-off',
61 disabled: stopped || suspended,
62 handler: () => confirmedVMCommand('shutdown'),
63 },
64 {
65 text: gettext('Stop'),
66 iconCls: 'fa fa-fw fa-stop',
67 disabled: stopped,
68 tooltip: Ext.String.format(gettext('Stop {0} immediately'), 'CT'),
69 handler: () => {
70 Ext.create('PVE.GuestStop', {
71 nodename: info.node,
72 vm: info,
73 autoShow: true,
74 });
75 },
76 },
77 {
78 text: gettext('Reboot'),
79 iconCls: 'fa fa-fw fa-refresh',
80 disabled: stopped,
81 tooltip: Ext.String.format(gettext('Reboot {0}'), 'CT'),
82 handler: () => confirmedVMCommand('reboot'),
83 },
84 {
85 xtype: 'menuseparator',
86 hidden: (standalone || !caps.vms['VM.Migrate']) && !caps.vms['VM.Allocate'] && !caps.vms['VM.Clone'],
87 },
88 {
89 text: gettext('Clone'),
90 iconCls: 'fa fa-fw fa-clone',
91 hidden: !caps.vms['VM.Clone'],
92 handler: () => PVE.window.Clone.wrap(info.node, info.vmid, me.isTemplate, 'lxc'),
93 },
94 {
95 text: gettext('Migrate'),
96 iconCls: 'fa fa-fw fa-send-o',
97 hidden: standalone || !caps.vms['VM.Migrate'],
98 handler: function() {
99 Ext.create('PVE.window.Migrate', {
100 vmtype: 'lxc',
101 nodename: info.node,
102 vmid: info.vmid,
103 autoShow: true,
104 });
105 },
106 },
107 {
108 text: gettext('Convert to template'),
109 iconCls: 'fa fa-fw fa-file-o',
110 handler: function() {
111 let msg = Proxmox.Utils.format_task_description('vztemplate', info.vmid);
112 Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
113 if (btn === 'yes') {
114 Proxmox.Utils.API2Request({
115 url: `/nodes/${info.node}/lxc/${info.vmid}/template`,
116 method: 'POST',
117 failure: (response, opts) => Ext.Msg.alert('Error', response.htmlStatus),
118 });
119 }
120 });
121 },
122 },
123 { xtype: 'menuseparator' },
124 {
125 text: gettext('Console'),
126 iconCls: 'fa fa-fw fa-terminal',
127 handler: () =>
128 PVE.Utils.openDefaultConsoleWindow(true, 'lxc', info.vmid, info.node, info.vmname),
129 },
130 ];
131
132 me.callParent();
133 },
134 });