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