]>
Commit | Line | Data |
---|---|---|
d7683c68 | 1 | Ext.define('PVE.window.Restore', { |
9fccc702 | 2 | extend: 'Ext.window.Window', // fixme: Proxmox.window.Edit? |
d7683c68 DM |
3 | |
4 | resizable: false, | |
5 | ||
6 | initComponent : function() { | |
7 | var me = this; | |
8 | ||
9 | if (!me.nodename) { | |
10 | throw "no node name specified"; | |
11 | } | |
12 | ||
13 | if (!me.volid) { | |
14 | throw "no volume ID specified"; | |
15 | } | |
16 | ||
17 | if (!me.vmtype) { | |
18 | throw "no vmtype specified"; | |
19 | } | |
20 | ||
21 | var storagesel = Ext.create('PVE.form.StorageSelector', { | |
22 | nodename: me.nodename, | |
23 | name: 'storage', | |
24 | value: '', | |
25 | fieldLabel: gettext('Storage'), | |
a00a9ffd | 26 | storageContent: (me.vmtype === 'lxc') ? 'rootdir' : 'images', |
6fe863ba FE |
27 | // when restoring a container without specifying a storage, the backend defaults |
28 | // to 'local', which is unintuitive and 'rootdir' might not even be allowed on it | |
29 | allowBlank: me.vmtype !== 'lxc', | |
30 | emptyText: (me.vmtype === 'lxc') ? '' : gettext('From backup configuration'), | |
31 | autoSelect: me.vmtype === 'lxc', | |
d7683c68 DM |
32 | }); |
33 | ||
ed416f20 EK |
34 | var IDfield; |
35 | if (me.vmid) { | |
36 | IDfield = Ext.create('Ext.form.field.Display', { | |
37 | name: 'vmid', | |
38 | value: me.vmid, | |
39 | fieldLabel: (me.vmtype === 'lxc') ? 'CT' : 'VM' | |
40 | }); | |
41 | } else { | |
42 | IDfield = Ext.create('PVE.form.GuestIDSelector', { | |
43 | name: 'vmid', | |
44 | guestType: me.vmtype, | |
677bb0e8 | 45 | loadNextFreeID: true, |
ed416f20 EK |
46 | validateExists: false |
47 | }); | |
48 | } | |
49 | ||
9cf2e84b DM |
50 | var items = [ |
51 | { | |
52 | xtype: 'displayfield', | |
53 | value: me.volidText || me.volid, | |
54 | fieldLabel: gettext('Source') | |
55 | }, | |
56 | storagesel, | |
9fa4ce6d TL |
57 | IDfield, |
58 | { | |
a331258a | 59 | xtype: 'pveBandwidthField', |
9fa4ce6d | 60 | name: 'bwlimit', |
0545b2a5 | 61 | backendUnit: 'KiB', |
a331258a | 62 | fieldLabel: gettext('Read Limit'), |
9fa4ce6d TL |
63 | emptyText: gettext('Defaults to target storage restore limit'), |
64 | autoEl: { | |
65 | tag: 'div', | |
66 | 'data-qtip': gettext("Use '0' to disable all bandwidth limits.") | |
67 | } | |
c517e212 | 68 | }, |
8b030d08 | 69 | { |
24c55f41 TL |
70 | xtype: 'fieldcontainer', |
71 | layout: 'hbox', | |
72 | items: [{ | |
73 | xtype: 'proxmoxcheckbox', | |
74 | name: 'unique', | |
75 | fieldLabel: gettext('Unique'), | |
76 | hidden: !!me.vmid, | |
77 | flex: 1, | |
78 | autoEl: { | |
79 | tag: 'div', | |
80 | 'data-qtip': gettext('Autogenerate unique properties, e.g., MAC addresses') | |
81 | }, | |
82 | checked: false | |
8b030d08 | 83 | }, |
24c55f41 TL |
84 | { |
85 | xtype: 'proxmoxcheckbox', | |
86 | name: 'start', | |
87 | flex: 1, | |
88 | fieldLabel: gettext('Start after restore'), | |
89 | labelWidth: 105, | |
90 | checked: false | |
91 | }], | |
92 | }, | |
9cf2e84b DM |
93 | ]; |
94 | ||
95 | if (me.vmtype === 'lxc') { | |
96 | items.push({ | |
896c0d50 | 97 | xtype: 'proxmoxcheckbox', |
9cf2e84b | 98 | name: 'unprivileged', |
a1892701 | 99 | value: true, |
9cf2e84b DM |
100 | fieldLabel: gettext('Unprivileged container') |
101 | }); | |
102 | } | |
103 | ||
d7683c68 DM |
104 | me.formPanel = Ext.create('Ext.form.Panel', { |
105 | bodyPadding: 10, | |
106 | border: false, | |
107 | fieldDefaults: { | |
108 | labelWidth: 100, | |
109 | anchor: '100%' | |
110 | }, | |
9cf2e84b | 111 | items: items |
d7683c68 DM |
112 | }); |
113 | ||
114 | var form = me.formPanel.getForm(); | |
115 | ||
116 | var doRestore = function(url, params) { | |
e7ade592 | 117 | Proxmox.Utils.API2Request({ |
d7683c68 DM |
118 | url: url, |
119 | params: params, | |
120 | method: 'POST', | |
121 | waitMsgTarget: me, | |
122 | failure: function (response, opts) { | |
123 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
124 | }, | |
125 | success: function(response, options) { | |
126 | var upid = response.result.data; | |
2a4971d8 | 127 | |
8cbc11a7 | 128 | var win = Ext.create('Proxmox.window.TaskViewer', { |
d7683c68 DM |
129 | upid: upid |
130 | }); | |
131 | win.show(); | |
132 | me.close(); | |
133 | } | |
134 | }); | |
135 | }; | |
136 | ||
137 | var submitBtn = Ext.create('Ext.Button', { | |
138 | text: gettext('Restore'), | |
139 | handler: function(){ | |
d7683c68 DM |
140 | var values = form.getValues(); |
141 | ||
142 | var params = { | |
d7683c68 DM |
143 | vmid: me.vmid || values.vmid, |
144 | force: me.vmid ? 1 : 0 | |
145 | }; | |
c517e212 | 146 | if (values.unique) { params.unique = 1; } |
24c55f41 | 147 | if (values.start) { params.start = 1; } |
6fe863ba | 148 | if (values.storage) { params.storage = values.storage; } |
d7683c68 | 149 | |
9fa4ce6d | 150 | if (values.bwlimit !== undefined) { |
0545b2a5 | 151 | params.bwlimit = values.bwlimit; |
9fa4ce6d TL |
152 | } |
153 | ||
d7683c68 | 154 | var url; |
16152937 | 155 | var msg; |
a00a9ffd AG |
156 | if (me.vmtype === 'lxc') { |
157 | url = '/nodes/' + me.nodename + '/lxc'; | |
d7683c68 DM |
158 | params.ostemplate = me.volid; |
159 | params.restore = 1; | |
9cf2e84b | 160 | if (values.unprivileged) { params.unprivileged = 1; } |
e7ade592 | 161 | msg = Proxmox.Utils.format_task_description('vzrestore', params.vmid); |
d7683c68 DM |
162 | } else if (me.vmtype === 'qemu') { |
163 | url = '/nodes/' + me.nodename + '/qemu'; | |
164 | params.archive = me.volid; | |
e7ade592 | 165 | msg = Proxmox.Utils.format_task_description('qmrestore', params.vmid); |
d7683c68 DM |
166 | } else { |
167 | throw 'unknown VM type'; | |
168 | } | |
169 | ||
170 | if (me.vmid) { | |
16152937 | 171 | msg += '. ' + gettext('This will permanently erase current VM data.'); |
d7683c68 DM |
172 | Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) { |
173 | if (btn !== 'yes') { | |
174 | return; | |
175 | } | |
176 | doRestore(url, params); | |
177 | }); | |
178 | } else { | |
179 | doRestore(url, params); | |
180 | } | |
181 | } | |
182 | }); | |
183 | ||
184 | form.on('validitychange', function(f, valid) { | |
185 | submitBtn.setDisabled(!valid); | |
186 | }); | |
187 | ||
185a77e5 DM |
188 | var title = gettext('Restore') + ": " + ( |
189 | (me.vmtype === 'lxc') ? 'CT' : 'VM'); | |
190 | ||
191 | if (me.vmid) { | |
192 | title += " " + me.vmid; | |
193 | } | |
d7683c68 DM |
194 | |
195 | Ext.apply(me, { | |
196 | title: title, | |
197 | width: 500, | |
198 | modal: true, | |
199 | layout: 'auto', | |
200 | border: false, | |
201 | items: [ me.formPanel ], | |
202 | buttons: [ submitBtn ] | |
203 | }); | |
204 | ||
205 | me.callParent(); | |
206 | } | |
207 | }); |