]>
Commit | Line | Data |
---|---|---|
aff192e6 DM |
1 | Ext.define('PVE.qemu.Config', { |
2 | extend: 'PVE.panel.Config', | |
3 | alias: 'widget.PVE.qemu.Config', | |
4 | ||
5 | initComponent: function() { | |
6 | var me = this; | |
7 | ||
8 | var nodename = me.pveSelNode.data.node; | |
9 | if (!nodename) { | |
10 | throw "no node name specified"; | |
11 | } | |
12 | ||
13 | var vmid = me.pveSelNode.data.vmid; | |
14 | if (!vmid) { | |
15 | throw "no VM ID specified"; | |
16 | } | |
17 | ||
3732a665 DM |
18 | me.statusStore = Ext.create('PVE.data.ObjectStore', { |
19 | url: "/api2/json/nodes/" + nodename + "/qemu/" + vmid + "/status/current", | |
20 | interval: 1000 | |
21 | }); | |
22 | ||
23 | var vm_command = function(cmd, params) { | |
24 | PVE.Utils.API2Request({ | |
25 | params: params, | |
26 | url: '/nodes/' + nodename + '/qemu/' + vmid + "/status/" + cmd, | |
27 | waitMsgTarget: me, | |
28 | method: 'POST', | |
29 | failure: function(response, opts) { | |
30 | Ext.Msg.alert('Error', response.htmlStatus); | |
31 | } | |
32 | }); | |
33 | }; | |
34 | ||
35 | var startBtn = Ext.create('Ext.Button', { | |
a2dca26b | 36 | text: gettext('Start'), |
3732a665 DM |
37 | handler: function() { |
38 | vm_command('start'); | |
39 | } | |
40 | }); | |
41 | ||
42 | var stopBtn = Ext.create('PVE.button.Button', { | |
a2dca26b DM |
43 | text: gettext('Stop'), |
44 | confirmMsg: Ext.String.format(gettext("Do you really want to stop VM {0}?"), vmid), | |
3732a665 DM |
45 | handler: function() { |
46 | vm_command("stop", { timeout: 30 }); | |
47 | } | |
48 | }); | |
49 | ||
50 | var migrateBtn = Ext.create('Ext.Button', { | |
a2dca26b | 51 | text: gettext('Migrate'), |
3732a665 | 52 | handler: function() { |
7e79e293 DM |
53 | var win = Ext.create('PVE.window.Migrate', { |
54 | vmtype: 'qemu', | |
55 | nodename: nodename, | |
56 | vmid: vmid | |
3732a665 DM |
57 | }); |
58 | win.show(); | |
59 | } | |
60 | }); | |
61 | ||
62 | var resetBtn = Ext.create('PVE.button.Button', { | |
a2dca26b DM |
63 | text: gettext('Reset'), |
64 | confirmMsg: Ext.String.format(gettext("Do you really want to reset VM {0}?"), vmid), | |
3732a665 DM |
65 | handler: function() { |
66 | vm_command("reset"); | |
67 | } | |
68 | }); | |
69 | ||
70 | var shutdownBtn = Ext.create('PVE.button.Button', { | |
2198a479 | 71 | text: gettext('Shutdown'), |
a2dca26b | 72 | confirmMsg: Ext.String.format(gettext("Do you really want to shutdown VM {0}?"), vmid), |
3732a665 DM |
73 | handler: function() { |
74 | vm_command('shutdown', { timeout: 30 }); | |
75 | } | |
76 | }); | |
77 | ||
78 | var removeBtn = Ext.create('PVE.button.Button', { | |
a2dca26b DM |
79 | text: gettext('Remove'), |
80 | confirmMsg: Ext.String.format(gettext('Are you sure you want to remove VM {0}? This will permanently erase all VM data.'), vmid), | |
3732a665 DM |
81 | handler: function() { |
82 | PVE.Utils.API2Request({ | |
83 | url: '/nodes/' + nodename + '/qemu/' + vmid, | |
84 | method: 'DELETE', | |
85 | waitMsgTarget: me, | |
86 | failure: function(response, opts) { | |
87 | Ext.Msg.alert('Error', response.htmlStatus); | |
88 | } | |
89 | }); | |
90 | } | |
91 | }); | |
92 | ||
fb3feb55 DM |
93 | var vmname = me.pveSelNode.data.name; |
94 | ||
3732a665 | 95 | var consoleBtn = Ext.create('Ext.Button', { |
a2dca26b | 96 | text: gettext('Console'), |
3732a665 | 97 | handler: function() { |
fb3feb55 | 98 | PVE.Utils.openConoleWindow('kvm', vmid, nodename, vmname); |
3732a665 DM |
99 | } |
100 | }); | |
101 | ||
a2dca26b DM |
102 | var descr = vmid + " (" + (vmname ? "'" + vmname + "' " : "'VM " + vmid + "'") + ")"; |
103 | ||
aff192e6 | 104 | Ext.apply(me, { |
58eb5905 | 105 | title: Ext.String.format(gettext("Virtual Machine {0} on node {1}"), descr, "'" + nodename + "'"), |
aff192e6 | 106 | hstateid: 'kvmtab', |
10f62558 DM |
107 | tbar: [ startBtn, shutdownBtn, stopBtn, resetBtn, |
108 | removeBtn, migrateBtn, consoleBtn ], | |
3732a665 | 109 | defaults: { statusStore: me.statusStore }, |
aff192e6 DM |
110 | items: [ |
111 | { | |
a2dca26b | 112 | title: gettext('Summary'), |
aff192e6 DM |
113 | xtype: 'pveQemuSummary', |
114 | itemId: 'summary' | |
115 | }, | |
116 | { | |
a2dca26b | 117 | title: gettext('Hardware'), |
aff192e6 DM |
118 | itemId: 'hardware', |
119 | xtype: 'PVE.qemu.HardwareView' | |
120 | }, | |
121 | { | |
a2dca26b | 122 | title: gettext('Options'), |
aff192e6 DM |
123 | itemId: 'options', |
124 | xtype: 'PVE.qemu.Options' | |
125 | }, | |
956d1b6e | 126 | { |
a2dca26b | 127 | title: gettext('Monitor'), |
956d1b6e DM |
128 | itemId: 'monitor', |
129 | xtype: 'pveQemuMonitor' | |
130 | }, | |
aff192e6 | 131 | { |
a2dca26b | 132 | title: gettext('Backup'), |
c5125d5a | 133 | xtype: 'pveBackupView', |
30edfad9 | 134 | itemId: 'backup' |
aff192e6 DM |
135 | }, |
136 | { | |
b23cd0a9 | 137 | xtype: 'pveACLView', |
a2dca26b | 138 | title: gettext('Permissions'), |
aff192e6 | 139 | itemId: 'permissions', |
b23cd0a9 | 140 | path: '/vms/' + vmid |
aff192e6 | 141 | } |
aff192e6 DM |
142 | ] |
143 | }); | |
144 | ||
145 | me.callParent(); | |
3732a665 DM |
146 | |
147 | me.statusStore.on('load', function(s, records, success) { | |
148 | var status; | |
149 | if (!success) { | |
150 | me.workspace.checkVmMigration(me.pveSelNode); | |
151 | status = 'unknown'; | |
152 | } else { | |
153 | var rec = s.data.get('status'); | |
154 | status = rec ? rec.data.value : 'unknown'; | |
155 | } | |
156 | ||
157 | startBtn.setDisabled(status === 'running'); | |
158 | resetBtn.setDisabled(status !== 'running'); | |
159 | shutdownBtn.setDisabled(status !== 'running'); | |
160 | stopBtn.setDisabled(status === 'stopped'); | |
3732a665 DM |
161 | removeBtn.setDisabled(status !== 'stopped'); |
162 | }); | |
163 | ||
164 | me.on('afterrender', function() { | |
165 | me.statusStore.startUpdate(); | |
166 | }); | |
167 | ||
168 | me.on('destroy', function() { | |
169 | me.statusStore.stopUpdate(); | |
170 | }); | |
aff192e6 DM |
171 | } |
172 | }); |