]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/window/Migrate.js
1 /*jslint confusion: true*/
2 Ext
.define('PVE.window.Migrate', {
3 extend
: 'Ext.window.Window',
16 onlineHelp
: 'qm_migration',
20 onlineHelp
: 'pct_migration',
26 'with-local-disks': 0,
28 allowedNodes
: undefined
34 setMigrationMode: function(get) {
36 if (get('vmtype') === 'qemu') {
37 return gettext('Online');
39 return gettext('Restart Mode');
42 return gettext('Offline');
45 setStorageselectorHidden: function(get) {
46 if (get('migration.with-local-disks') && get('running')) {
56 xclass
: 'Ext.app.ViewController',
58 'panel[reference=formPanel]': {
59 validityChange: function(panel
, isValid
) {
60 this.getViewModel().set('migration.possible', isValid
);
61 this.checkMigratePreconditions();
66 init: function(view
) {
68 vm
= view
.getViewModel();
71 throw "missing custom view config: nodename";
73 vm
.set('nodename', view
.nodename
);
76 throw "missing custom view config: vmid";
78 vm
.set('vmid', view
.vmid
);
81 throw "missing custom view config: vmtype";
83 vm
.set('vmtype', view
.vmtype
);
87 Ext
.String
.format('{0} {1}{2}', gettext('Migrate'), vm
.get(view
.vmtype
).commonName
, view
.vmid
)
89 me
.lookup('proxmoxHelpButton').setHelpConfig({
90 onlineHelp
: vm
.get(view
.vmtype
).onlineHelp
92 me
.checkMigratePreconditions();
93 me
.lookup('formPanel').isValid();
97 onTargetChange: function (nodeSelector
) {
98 //Always display the storages of the currently seleceted migration target
99 this.lookup('pveDiskStorageSelector').setNodename(nodeSelector
.value
);
100 this.checkMigratePreconditions();
103 startMigration: function() {
106 vm
= me
.getViewModel();
108 var values
= me
.lookup('formPanel').getValues();
110 target
: values
.target
113 if (vm
.get('migration.mode')) {
114 params
[vm
.get('migration.mode')] = 1;
116 if (vm
.get('migration.with-local-disks')) {
117 params
['with-local-disks'] = 1;
119 //only submit targetstorage if vm is running, storage migration to different storage is only possible online
120 if (vm
.get('migration.with-local-disks') && vm
.get('running')) {
121 params
.targetstorage
= values
.targetstorage
;
124 Proxmox
.Utils
.API2Request({
126 url
: '/nodes/' + vm
.get('nodename') + '/' + vm
.get('vmtype') + '/' + vm
.get('vmid') + '/migrate',
129 failure: function(response
, opts
) {
130 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);
132 success: function(response
, options
) {
133 var upid
= response
.result
.data
;
134 var extraTitle
= Ext
.String
.format(' ({0} ---> {1})', vm
.get('nodename'), params
.target
);
136 Ext
.create('Proxmox.window.TaskViewer', {
138 extraTitle
: extraTitle
147 checkMigratePreconditions: function() {
149 vm
= me
.getViewModel();
152 var vmrec
= PVE
.data
.ResourceStore
.findRecord('vmid', vm
.get('vmid'),
153 0, false, false, true);
154 if (vmrec
&& vmrec
.data
&& vmrec
.data
.running
) {
155 vm
.set('running', true);
158 if (vm
.get('vmtype') === 'qemu') {
159 me
.checkQemuPreconditions();
161 me
.checkLxcPreconditions();
163 me
.lookup('pveNodeSelector').disallowedNodes
= [vm
.get('nodename')];
165 // Only allow nodes where the local storage is available in case of offline migration
166 // where storage migration is not possible
167 me
.lookup('pveNodeSelector').allowedNodes
= vm
.get('migration.allowedNodes');
169 me
.lookup('formPanel').isValid();
173 checkQemuPreconditions: function() {
175 vm
= me
.getViewModel(),
178 if (vm
.get('running')) {
179 vm
.set('migration.mode', 'online');
182 Proxmox
.Utils
.API2Request({
183 url
: '/nodes/' + vm
.get('nodename') + '/' + vm
.get('vmtype') + '/' + vm
.get('vmid') + '/migrate',
185 failure: function(response
, opts
) {
186 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);
188 success: function(response
, options
) {
189 migrateStats
= response
.result
.data
;
190 if (migrateStats
.running
) {
191 vm
.set('running', true);
193 // Get migration object from viewmodel to prevent
194 // to many bind callbacks
195 var migration
= vm
.get('migration');
196 migration
.preconditions
= [];
198 if (migrateStats
.allowed_nodes
) {
199 migration
.allowedNodes
= migrateStats
.allowed_nodes
;
201 if (!migrateStats
.allowed_nodes
.includes(me
.lookup('pveNodeSelector').value
)) {
202 migration
.possible
= false;
203 migration
.preconditions
.push({
204 text
: 'Local storage not available on selected Node, start VM to use live storage migration or select other target node',
210 if (migrateStats
.local_resources
.length
) {
211 migration
.possible
= false;
212 migration
.preconditions
.push({
213 text
: 'Can\'t migrate VM with local resources: '+ migrateStats
.local_resources
.join(', '),
218 if (migrateStats
.local_disks
.length
) {
220 migrateStats
.local_disks
.forEach(function (disk
) {
221 if (disk
.cdrom
&& disk
.cdrom
=== 1) {
222 migration
.possible
= false;
223 migration
.preconditions
.push({
224 text
:'Can\'t migrate VM with local CD/DVD',
228 } else if (!disk
.referenced_in_config
) {
229 migration
.possible
= false;
230 migration
.preconditions
.push({
231 text
: 'Found not referenced/unused disk via storage: '+ disk
.volid
,
235 migration
['with-local-disks'] = 1;
236 migration
.preconditions
.push({
237 text
:'Migration with local disk might take long: '+ disk
.volid
,
245 vm
.set('migration', migration
);
250 checkLxcPreconditions: function() {
252 vm
= me
.getViewModel();
253 if (vm
.get('running')) {
254 vm
.set('migration.mode', 'restart');
271 reference
: 'formPanel',
282 xtype
: 'displayfield',
284 fieldLabel
: gettext('Source node'),
290 xtype
: 'displayfield',
291 reference
: 'migrationMode',
292 fieldLabel
: gettext('Mode'),
294 value
: '{setMigrationMode}'
302 xtype
: 'pveNodeSelector',
303 reference
: 'pveNodeSelector',
305 fieldLabel
: gettext('Target node'),
307 disallowedNodes
: undefined,
308 onlineValidator
: true,
310 change
: 'onTargetChange'
314 xtype
: 'pveStorageSelector',
315 reference
: 'pveDiskStorageSelector',
316 name
: 'targetstorage',
317 fieldLabel
: gettext('Target storage'),
318 storageContent
: 'images',
320 hidden
: '{setStorageselectorHidden}'
328 reference
: 'preconditionGrid',
333 dataIndex
: 'severity',
334 renderer: function(v
) {
337 return '<i class="fa fa-exclamation-triangle warning"></i> ';
339 return '<i class="fa fa-times critical"></i>';
353 hidden
: '{!migration.preconditions.length}',
355 fields
: ['severity','text'],
356 data
: '{migration.preconditions}'
364 xtype
: 'proxmoxHelpButton',
365 reference
: 'proxmoxHelpButton',
366 onlineHelp
: 'pct_migration',
367 listenToGlobalEvent
: false,
373 reference
: 'submitButton',
374 text
: gettext('Migrate'),
375 handler
: 'startMigration',
377 disabled
: '{!migration.possible}'