]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/window/Restore.js
vzdump: set 'pbs' option when backing up to PBS target
[pve-manager.git] / www / manager6 / window / Restore.js
CommitLineData
d7683c68 1Ext.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',
d7683c68
DM
27 allowBlank: true
28 });
29
ed416f20
EK
30 var IDfield;
31 if (me.vmid) {
32 IDfield = Ext.create('Ext.form.field.Display', {
33 name: 'vmid',
34 value: me.vmid,
35 fieldLabel: (me.vmtype === 'lxc') ? 'CT' : 'VM'
36 });
37 } else {
38 IDfield = Ext.create('PVE.form.GuestIDSelector', {
39 name: 'vmid',
40 guestType: me.vmtype,
677bb0e8 41 loadNextFreeID: true,
ed416f20
EK
42 validateExists: false
43 });
44 }
45
9cf2e84b
DM
46 var items = [
47 {
48 xtype: 'displayfield',
49 value: me.volidText || me.volid,
50 fieldLabel: gettext('Source')
51 },
52 storagesel,
9fa4ce6d
TL
53 IDfield,
54 {
a331258a 55 xtype: 'pveBandwidthField',
9fa4ce6d 56 name: 'bwlimit',
0545b2a5 57 backendUnit: 'KiB',
a331258a 58 fieldLabel: gettext('Read Limit'),
9fa4ce6d
TL
59 emptyText: gettext('Defaults to target storage restore limit'),
60 autoEl: {
61 tag: 'div',
62 'data-qtip': gettext("Use '0' to disable all bandwidth limits.")
63 }
c517e212 64 },
8b030d08 65 {
24c55f41
TL
66 xtype: 'fieldcontainer',
67 layout: 'hbox',
68 items: [{
69 xtype: 'proxmoxcheckbox',
70 name: 'unique',
71 fieldLabel: gettext('Unique'),
72 hidden: !!me.vmid,
73 flex: 1,
74 autoEl: {
75 tag: 'div',
76 'data-qtip': gettext('Autogenerate unique properties, e.g., MAC addresses')
77 },
78 checked: false
8b030d08 79 },
24c55f41
TL
80 {
81 xtype: 'proxmoxcheckbox',
82 name: 'start',
83 flex: 1,
84 fieldLabel: gettext('Start after restore'),
85 labelWidth: 105,
86 checked: false
87 }],
88 },
9cf2e84b
DM
89 ];
90
21ef191b 91 /*jslint confusion: true*/
9cf2e84b
DM
92 if (me.vmtype === 'lxc') {
93 items.push({
896c0d50 94 xtype: 'proxmoxcheckbox',
9cf2e84b 95 name: 'unprivileged',
a1892701 96 value: true,
9cf2e84b
DM
97 fieldLabel: gettext('Unprivileged container')
98 });
99 }
21ef191b 100 /*jslint confusion: false*/
9cf2e84b 101
d7683c68
DM
102 me.formPanel = Ext.create('Ext.form.Panel', {
103 bodyPadding: 10,
104 border: false,
105 fieldDefaults: {
106 labelWidth: 100,
107 anchor: '100%'
108 },
9cf2e84b 109 items: items
d7683c68
DM
110 });
111
112 var form = me.formPanel.getForm();
113
114 var doRestore = function(url, params) {
e7ade592 115 Proxmox.Utils.API2Request({
d7683c68
DM
116 url: url,
117 params: params,
118 method: 'POST',
119 waitMsgTarget: me,
120 failure: function (response, opts) {
121 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
122 },
123 success: function(response, options) {
124 var upid = response.result.data;
125
8cbc11a7 126 var win = Ext.create('Proxmox.window.TaskViewer', {
d7683c68
DM
127 upid: upid
128 });
129 win.show();
130 me.close();
131 }
132 });
133 };
134
135 var submitBtn = Ext.create('Ext.Button', {
136 text: gettext('Restore'),
137 handler: function(){
138 var storage = storagesel.getValue();
139 var values = form.getValues();
140
141 var params = {
142 storage: storage,
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; }
d7683c68 148
9fa4ce6d 149 if (values.bwlimit !== undefined) {
0545b2a5 150 params.bwlimit = values.bwlimit;
9fa4ce6d
TL
151 }
152
d7683c68 153 var url;
16152937 154 var msg;
a00a9ffd
AG
155 if (me.vmtype === 'lxc') {
156 url = '/nodes/' + me.nodename + '/lxc';
d7683c68
DM
157 params.ostemplate = me.volid;
158 params.restore = 1;
9cf2e84b 159 if (values.unprivileged) { params.unprivileged = 1; }
e7ade592 160 msg = Proxmox.Utils.format_task_description('vzrestore', params.vmid);
d7683c68
DM
161 } else if (me.vmtype === 'qemu') {
162 url = '/nodes/' + me.nodename + '/qemu';
163 params.archive = me.volid;
e7ade592 164 msg = Proxmox.Utils.format_task_description('qmrestore', params.vmid);
d7683c68
DM
165 } else {
166 throw 'unknown VM type';
167 }
168
169 if (me.vmid) {
16152937 170 msg += '. ' + gettext('This will permanently erase current VM data.');
d7683c68
DM
171 Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
172 if (btn !== 'yes') {
173 return;
174 }
175 doRestore(url, params);
176 });
177 } else {
178 doRestore(url, params);
179 }
180 }
181 });
182
183 form.on('validitychange', function(f, valid) {
184 submitBtn.setDisabled(!valid);
185 });
186
185a77e5
DM
187 var title = gettext('Restore') + ": " + (
188 (me.vmtype === 'lxc') ? 'CT' : 'VM');
189
190 if (me.vmid) {
191 title += " " + me.vmid;
192 }
d7683c68
DM
193
194 Ext.apply(me, {
195 title: title,
196 width: 500,
197 modal: true,
198 layout: 'auto',
199 border: false,
200 items: [ me.formPanel ],
201 buttons: [ submitBtn ]
202 });
203
204 me.callParent();
205 }
206});