[pve-devel] [PATCH v2 manager] ui: migrate: add checkbox to enable offline migration with local resources

Tim Marx t.marx at proxmox.com
Mon Oct 14 11:58:20 CEST 2019


Added to make use of [0] and because it does make sense for non HA vm's
as well, in accordance with #2241.

[0] pve-ha-manager: 6e8b0c225405da9472f56fe5c94c94b204259caa
Signed-off-by: Tim Marx <t.marx at proxmox.com>
---
changes v2:
* changed naming overwriteLocalResourceCheck, resetMigrationPossible, Force
* added tooltip to checkbox

 www/manager6/window/Migrate.js | 67 +++++++++++++++++++++++++++-------
 1 file changed, 54 insertions(+), 13 deletions(-)

diff --git a/www/manager6/window/Migrate.js b/www/manager6/window/Migrate.js
index 02ef6bfd..d8d9a7f3 100644
--- a/www/manager6/window/Migrate.js
+++ b/www/manager6/window/Migrate.js
@@ -25,7 +25,9 @@ Ext.define('PVE.window.Migrate', {
 		preconditions: [],
 		'with-local-disks': 0,
 		mode: undefined,
-		allowedNodes: undefined
+		allowedNodes: undefined,
+		overwriteLocalResourceCheck: false,
+		hasLocalResources: false
 	    }

 	},
@@ -48,6 +50,14 @@ Ext.define('PVE.window.Migrate', {
 		    } else {
 			return true;
 		    }
+	    },
+	    setLocalResourceCheckboxHidden: function(get) {
+		if (get('running') || !get('migration.hasLocalResources') ||
+		    Proxmox.UserName !== 'root at pam') {
+		    return true;
+		} else {
+		    return false;
+		}
 	    }
 	}
     },
@@ -121,6 +131,10 @@ Ext.define('PVE.window.Migrate', {
 		params.targetstorage = values.targetstorage;
 	    }

+	    if (vm.get('migration.overwriteLocalResourceCheck')) {
+		params['force'] = 1;
+	    }
+
 	    Proxmox.Utils.API2Request({
 		params: params,
 		url: '/nodes/' + vm.get('nodename') + '/' + vm.get('vmtype') + '/' + vm.get('vmid') + '/migrate',
@@ -144,11 +158,10 @@ Ext.define('PVE.window.Migrate', {

 	},

-	checkMigratePreconditions: function() {
+	checkMigratePreconditions: function(resetMigrationPossible) {
 	    var me = this,
 		vm = me.getViewModel();

-
 	    var vmrec = PVE.data.ResourceStore.findRecord('vmid', vm.get('vmid'),
 			0, false, false, true);
 	    if (vmrec && vmrec.data && vmrec.data.running) {
@@ -156,9 +169,9 @@ Ext.define('PVE.window.Migrate', {
 	    }

 	    if (vm.get('vmtype') === 'qemu') {
-		me.checkQemuPreconditions();
+		me.checkQemuPreconditions(resetMigrationPossible);
 	    } else {
-		me.checkLxcPreconditions();
+		me.checkLxcPreconditions(resetMigrationPossible);
 	    }
 	    me.lookup('pveNodeSelector').disallowedNodes = [vm.get('nodename')];

@@ -170,7 +183,7 @@ Ext.define('PVE.window.Migrate', {

 	},

-	checkQemuPreconditions: function() {
+	checkQemuPreconditions: function(resetMigrationPossible) {
 	    var me = this,
 		vm = me.getViewModel(),
 		migrateStats;
@@ -193,6 +206,7 @@ Ext.define('PVE.window.Migrate', {
 		    // Get migration object from viewmodel to prevent
 		    // to many bind callbacks
 		    var migration = vm.get('migration');
+		    if (resetMigrationPossible) migration.possible = true;
 		    migration.preconditions = [];

 		    if (migrateStats.allowed_nodes) {
@@ -212,11 +226,22 @@ Ext.define('PVE.window.Migrate', {
 		    }

 		    if (migrateStats.local_resources.length) {
-			migration.possible = false;
-			migration.preconditions.push({
-			    text: 'Can\'t migrate VM with local resources: '+ migrateStats.local_resources.join(', '),
-			    severity: 'error'
-			});
+			migration.hasLocalResources = true;
+			if(!migration.overwriteLocalResourceCheck || vm.get('running')){
+			    migration.possible = false;
+			    migration.preconditions.push({
+				text: Ext.String.format('Can\'t migrate VM with local resources: {0}',
+				migrateStats.local_resources.join(', ')),
+				severity: 'error'
+			    });
+			} else {
+			    migration.preconditions.push({
+				text: Ext.String.format('Migrate VM with local resources: {0}. ' +
+				'This might fail if resources aren\'t available on the target node.',
+				migrateStats.local_resources.join(', ')),
+				severity: 'warning'
+			    });
+			}
 		    }

 		    if (migrateStats.local_disks.length) {
@@ -252,7 +277,7 @@ Ext.define('PVE.window.Migrate', {
 		}
 	    });
 	},
-	checkLxcPreconditions: function() {
+	checkLxcPreconditions: function(resetMigrationPossible) {
 	    var me = this,
 		vm = me.getViewModel();
 	    if (vm.get('running')) {
@@ -324,7 +349,23 @@ Ext.define('PVE.window.Migrate', {
 			    bind: {
 				hidden: '{setStorageselectorHidden}'
 			    }
-		    }]
+		    },
+		    {
+			xtype: 'proxmoxcheckbox',
+			name: 'overwriteLocalResourceCheck',
+			fieldLabel: gettext('Force'),
+			autoEl: {
+			    tag: 'div',
+			    'data-qtip': 'Overwrite local resources unavailable check'
+			},
+			bind: {
+			    hidden: '{setLocalResourceCheckboxHidden}',
+			    value: '{migration.overwriteLocalResourceCheck}'
+			},
+			listeners: {
+			    change: {fn: 'checkMigratePreconditions', extraArg: true}
+			}
+		}]
 		}
 	    ]
 	},
--
2.20.1




More information about the pve-devel mailing list