]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/window/Clone.js
ui: restore: allow override of some settings
[pve-manager.git] / www / manager6 / window / Clone.js
1 Ext.define('PVE.window.Clone', {
2 extend: 'Ext.window.Window',
3
4 resizable: false,
5
6 isTemplate: false,
7
8 onlineHelp: 'qm_copy_and_clone',
9
10 controller: {
11 xclass: 'Ext.app.ViewController',
12 control: {
13 'panel[reference=cloneform]': {
14 validitychange: 'disableSubmit',
15 },
16 },
17 disableSubmit: function(form) {
18 this.lookupReference('submitBtn').setDisabled(!form.isValid());
19 },
20 },
21
22 statics: {
23 // display a snapshot selector only if needed
24 wrap: function(nodename, vmid, isTemplate, guestType) {
25 Proxmox.Utils.API2Request({
26 url: '/nodes/' + nodename + '/' + guestType + '/' + vmid +'/snapshot',
27 failure: function(response, opts) {
28 Ext.Msg.alert('Error', response.htmlStatus);
29 },
30 success: function(response, opts) {
31 var snapshotList = response.result.data;
32 var hasSnapshots = !(snapshotList.length === 1 &&
33 snapshotList[0].name === 'current');
34
35 Ext.create('PVE.window.Clone', {
36 nodename: nodename,
37 guestType: guestType,
38 vmid: vmid,
39 isTemplate: isTemplate,
40 hasSnapshots: hasSnapshots,
41 }).show();
42 },
43 });
44 },
45 },
46
47 create_clone: function(values) {
48 var me = this;
49
50 var params = { newid: values.newvmid };
51
52 if (values.snapname && values.snapname !== 'current') {
53 params.snapname = values.snapname;
54 }
55
56 if (values.pool) {
57 params.pool = values.pool;
58 }
59
60 if (values.name) {
61 if (me.guestType === 'lxc') {
62 params.hostname = values.name;
63 } else {
64 params.name = values.name;
65 }
66 }
67
68 if (values.target) {
69 params.target = values.target;
70 }
71
72 if (values.clonemode === 'copy') {
73 params.full = 1;
74 if (values.hdstorage) {
75 params.storage = values.hdstorage;
76 if (values.diskformat && me.guestType !== 'lxc') {
77 params.format = values.diskformat;
78 }
79 }
80 }
81
82 Proxmox.Utils.API2Request({
83 params: params,
84 url: '/nodes/' + me.nodename + '/' + me.guestType + '/' + me.vmid + '/clone',
85 waitMsgTarget: me,
86 method: 'POST',
87 failure: function(response, opts) {
88 Ext.Msg.alert('Error', response.htmlStatus);
89 },
90 success: function(response, options) {
91 me.close();
92 },
93 });
94 },
95
96 // disable the Storage selector when clone mode is linked clone
97 updateVisibility: function() {
98 var me = this;
99 var clonemode = me.lookupReference('clonemodesel').getValue();
100 var disksel = me.lookup('diskselector');
101 disksel.setDisabled(clonemode === 'clone');
102 },
103
104 // add to the list of valid nodes each node where
105 // all the VM disks are available
106 verifyFeature: function() {
107 var me = this;
108
109 var snapname = me.lookupReference('snapshotsel').getValue();
110 var clonemode = me.lookupReference('clonemodesel').getValue();
111
112 var params = { feature: clonemode };
113 if (snapname !== 'current') {
114 params.snapname = snapname;
115 }
116
117 Proxmox.Utils.API2Request({
118 waitMsgTarget: me,
119 url: '/nodes/' + me.nodename + '/' + me.guestType + '/' + me.vmid + '/feature',
120 params: params,
121 method: 'GET',
122 failure: function(response, opts) {
123 me.lookupReference('submitBtn').setDisabled(true);
124 Ext.Msg.alert('Error', response.htmlStatus);
125 },
126 success: function(response, options) {
127 var res = response.result.data;
128
129 me.lookupReference('targetsel').allowedNodes = res.nodes;
130 me.lookupReference('targetsel').validate();
131 },
132 });
133 },
134
135 initComponent: function() {
136 var me = this;
137
138 if (!me.nodename) {
139 throw "no node name specified";
140 }
141
142 if (!me.vmid) {
143 throw "no VM ID specified";
144 }
145
146 if (!me.snapname) {
147 me.snapname = 'current';
148 }
149
150 if (!me.guestType) {
151 throw "no Guest Type specified";
152 }
153
154 var titletext = me.guestType === 'lxc' ? 'CT' : 'VM';
155 if (me.isTemplate) {
156 titletext += ' Template';
157 }
158 me.title = "Clone " + titletext + " " + me.vmid;
159
160 var col1 = [];
161 var col2 = [];
162
163 col1.push({
164 xtype: 'pveNodeSelector',
165 name: 'target',
166 reference: 'targetsel',
167 fieldLabel: gettext('Target node'),
168 selectCurNode: true,
169 allowBlank: false,
170 onlineValidator: true,
171 listeners: {
172 change: function(f, value) {
173 me.lookupReference('hdstorage').setTargetNode(value);
174 },
175 },
176 });
177
178 var modelist = [['copy', gettext('Full Clone')]];
179 if (me.isTemplate) {
180 modelist.push(['clone', gettext('Linked Clone')]);
181 }
182
183 col1.push({
184 xtype: 'pveGuestIDSelector',
185 name: 'newvmid',
186 guestType: me.guestType,
187 value: '',
188 loadNextFreeID: true,
189 validateExists: false,
190 },
191 {
192 xtype: 'textfield',
193 name: 'name',
194 allowBlank: true,
195 fieldLabel: me.guestType === 'lxc' ? gettext('Hostname') : gettext('Name'),
196 },
197 {
198 xtype: 'pvePoolSelector',
199 fieldLabel: gettext('Resource Pool'),
200 name: 'pool',
201 value: '',
202 allowBlank: true,
203 },
204 );
205
206 col2.push({
207 xtype: 'proxmoxKVComboBox',
208 fieldLabel: gettext('Mode'),
209 name: 'clonemode',
210 reference: 'clonemodesel',
211 allowBlank: false,
212 hidden: !me.isTemplate,
213 value: me.isTemplate ? 'clone' : 'copy',
214 comboItems: modelist,
215 listeners: {
216 change: function(t, value) {
217 me.updateVisibility();
218 me.verifyFeature();
219 },
220 },
221 },
222 {
223 xtype: 'PVE.form.SnapshotSelector',
224 name: 'snapname',
225 reference: 'snapshotsel',
226 fieldLabel: gettext('Snapshot'),
227 nodename: me.nodename,
228 guestType: me.guestType,
229 vmid: me.vmid,
230 hidden: !!(me.isTemplate || !me.hasSnapshots),
231 disabled: false,
232 allowBlank: false,
233 value: me.snapname,
234 listeners: {
235 change: function(f, value) {
236 me.verifyFeature();
237 },
238 },
239 },
240 {
241 xtype: 'pveDiskStorageSelector',
242 reference: 'diskselector',
243 nodename: me.nodename,
244 autoSelect: false,
245 hideSize: true,
246 hideSelection: true,
247 storageLabel: gettext('Target Storage'),
248 allowBlank: true,
249 storageContent: me.guestType === 'qemu' ? 'images' : 'rootdir',
250 emptyText: gettext('Same as source'),
251 disabled: !!me.isTemplate, // because default mode is clone for templates
252 });
253
254 var formPanel = Ext.create('Ext.form.Panel', {
255 bodyPadding: 10,
256 reference: 'cloneform',
257 border: false,
258 layout: 'hbox',
259 defaultType: 'container',
260 fieldDefaults: {
261 labelWidth: 100,
262 anchor: '100%',
263 },
264 items: [
265 {
266 flex: 1,
267 padding: '0 10 0 0',
268 layout: 'anchor',
269 items: col1,
270 },
271 {
272 flex: 1,
273 padding: '0 0 0 10',
274 layout: 'anchor',
275 items: col2,
276 },
277 ],
278 });
279
280 Ext.apply(me, {
281 modal: true,
282 width: 600,
283 height: 250,
284 border: false,
285 layout: 'fit',
286 buttons: [{
287 xtype: 'proxmoxHelpButton',
288 listenToGlobalEvent: false,
289 hidden: false,
290 onlineHelp: me.onlineHelp,
291 },
292 '->',
293 {
294 reference: 'submitBtn',
295 text: gettext('Clone'),
296 disabled: true,
297 handler: function() {
298 var cloneForm = me.lookupReference('cloneform');
299 if (cloneForm.isValid()) {
300 me.create_clone(cloneForm.getValues());
301 }
302 },
303 }],
304 items: [formPanel],
305 });
306
307 me.callParent();
308
309 me.verifyFeature();
310 },
311 });