]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/window/Restore.js
ui: safe destroy guest: add checkbox for removal of unreferenced disks
[pve-manager.git] / www / manager6 / window / Restore.js
1 Ext.define('PVE.window.Restore', {
2 extend: 'Ext.window.Window', // fixme: Proxmox.window.Edit?
3
4 resizable: false,
5
6 controller: {
7 xclass: 'Ext.app.ViewController',
8 control: {
9 '#liveRestore': {
10 change: function(el, newVal) {
11 let liveWarning = this.lookupReference('liveWarning');
12 liveWarning.setHidden(!newVal);
13 let start = this.lookupReference('start');
14 start.setDisabled(newVal);
15 },
16 },
17 },
18 },
19
20 initComponent: function() {
21 var me = this;
22
23 if (!me.nodename) {
24 throw "no node name specified";
25 }
26
27 if (!me.volid) {
28 throw "no volume ID specified";
29 }
30
31 if (!me.vmtype) {
32 throw "no vmtype specified";
33 }
34
35 var storagesel = Ext.create('PVE.form.StorageSelector', {
36 nodename: me.nodename,
37 name: 'storage',
38 value: '',
39 fieldLabel: gettext('Storage'),
40 storageContent: me.vmtype === 'lxc' ? 'rootdir' : 'images',
41 // when restoring a container without specifying a storage, the backend defaults
42 // to 'local', which is unintuitive and 'rootdir' might not even be allowed on it
43 allowBlank: me.vmtype !== 'lxc',
44 emptyText: me.vmtype === 'lxc' ? '' : gettext('From backup configuration'),
45 autoSelect: me.vmtype === 'lxc',
46 });
47
48 var IDfield;
49 if (me.vmid) {
50 IDfield = Ext.create('Ext.form.field.Display', {
51 name: 'vmid',
52 value: me.vmid,
53 fieldLabel: me.vmtype === 'lxc' ? 'CT' : 'VM',
54 });
55 } else {
56 IDfield = Ext.create('PVE.form.GuestIDSelector', {
57 name: 'vmid',
58 guestType: me.vmtype,
59 loadNextFreeID: true,
60 validateExists: false,
61 });
62 }
63
64 var items = [
65 {
66 xtype: 'displayfield',
67 value: me.volidText || me.volid,
68 fieldLabel: gettext('Source'),
69 },
70 storagesel,
71 IDfield,
72 {
73 xtype: 'pveBandwidthField',
74 name: 'bwlimit',
75 backendUnit: 'KiB',
76 allowZero: true,
77 fieldLabel: gettext('Bandwidth Limit'),
78 emptyText: gettext('Defaults to target storage restore limit'),
79 autoEl: {
80 tag: 'div',
81 'data-qtip': gettext("Use '0' to disable all bandwidth limits."),
82 },
83 },
84 {
85 xtype: 'fieldcontainer',
86 layout: 'hbox',
87 items: [{
88 xtype: 'proxmoxcheckbox',
89 name: 'unique',
90 fieldLabel: gettext('Unique'),
91 hidden: !!me.vmid,
92 flex: 1,
93 autoEl: {
94 tag: 'div',
95 'data-qtip': gettext('Autogenerate unique properties, e.g., MAC addresses'),
96 },
97 checked: false,
98 },
99 {
100 xtype: 'proxmoxcheckbox',
101 name: 'start',
102 reference: 'start',
103 flex: 1,
104 fieldLabel: gettext('Start after restore'),
105 labelWidth: 105,
106 checked: false,
107 }],
108 },
109 ];
110
111 if (me.vmtype === 'lxc') {
112 items.push({
113 xtype: 'proxmoxcheckbox',
114 name: 'unprivileged',
115 value: true,
116 fieldLabel: gettext('Unprivileged container'),
117 });
118 } else if (me.vmtype === 'qemu') {
119 items.push({
120 xtype: 'proxmoxcheckbox',
121 name: 'live-restore',
122 itemId: 'liveRestore',
123 flex: 1,
124 fieldLabel: gettext('Live restore'),
125 checked: false,
126 hidden: !me.isPBS,
127 // align checkbox with 'start' if 'unique' is hidden
128 labelWidth: me.vmid ? 105 : 100,
129 });
130 items.push({
131 xtype: 'displayfield',
132 reference: 'liveWarning',
133 // TODO: Remove once more tested/stable?
134 value: gettext('Note: If anything goes wrong during the live-restore, new data written by the VM will be lost.'),
135 userCls: 'pmx-hint',
136 hidden: true,
137 });
138 }
139
140 me.formPanel = Ext.create('Ext.form.Panel', {
141 bodyPadding: 10,
142 border: false,
143 fieldDefaults: {
144 labelWidth: 100,
145 anchor: '100%',
146 },
147 items: items,
148 });
149
150 var form = me.formPanel.getForm();
151
152 var doRestore = function(url, params) {
153 Proxmox.Utils.API2Request({
154 url: url,
155 params: params,
156 method: 'POST',
157 waitMsgTarget: me,
158 failure: function(response, opts) {
159 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
160 },
161 success: function(response, options) {
162 var upid = response.result.data;
163
164 var win = Ext.create('Proxmox.window.TaskViewer', {
165 upid: upid,
166 });
167 win.show();
168 me.close();
169 },
170 });
171 };
172
173 var submitBtn = Ext.create('Ext.Button', {
174 text: gettext('Restore'),
175 handler: function() {
176 var values = form.getValues();
177
178 var params = {
179 vmid: me.vmid || values.vmid,
180 force: me.vmid ? 1 : 0,
181 };
182 if (values.unique) { params.unique = 1; }
183 if (values.start && !values['live-restore']) { params.start = 1; }
184 if (values['live-restore']) { params['live-restore'] = 1; }
185 if (values.storage) { params.storage = values.storage; }
186
187 if (values.bwlimit !== undefined) {
188 params.bwlimit = values.bwlimit;
189 }
190
191 var url;
192 var msg;
193 if (me.vmtype === 'lxc') {
194 url = '/nodes/' + me.nodename + '/lxc';
195 params.ostemplate = me.volid;
196 params.restore = 1;
197 if (values.unprivileged) { params.unprivileged = 1; }
198 msg = Proxmox.Utils.format_task_description('vzrestore', params.vmid);
199 } else if (me.vmtype === 'qemu') {
200 url = '/nodes/' + me.nodename + '/qemu';
201 params.archive = me.volid;
202 msg = Proxmox.Utils.format_task_description('qmrestore', params.vmid);
203 } else {
204 throw 'unknown VM type';
205 }
206
207 if (me.vmid) {
208 msg += '. ' + gettext('This will permanently erase current VM data.');
209 Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
210 if (btn !== 'yes') {
211 return;
212 }
213 doRestore(url, params);
214 });
215 } else {
216 doRestore(url, params);
217 }
218 },
219 });
220
221 form.on('validitychange', function(f, valid) {
222 submitBtn.setDisabled(!valid);
223 });
224
225 var title = gettext('Restore') + ": " + (
226 me.vmtype === 'lxc' ? 'CT' : 'VM');
227
228 if (me.vmid) {
229 title += " " + me.vmid;
230 }
231
232 Ext.apply(me, {
233 title: title,
234 width: 500,
235 modal: true,
236 layout: 'auto',
237 border: false,
238 items: [me.formPanel],
239 buttons: [submitBtn],
240 });
241
242 me.callParent();
243 },
244 });