Blame SOURCES/bz1242181-virtualdomain-migrate_options.patch

937446
diff -uNr a/heartbeat/VirtualDomain b/heartbeat/VirtualDomain
937446
--- a/heartbeat/VirtualDomain	2016-02-29 10:54:21.870787072 +0100
937446
+++ b/heartbeat/VirtualDomain	2016-02-29 14:02:23.260696550 +0100
937446
@@ -106,11 +106,28 @@
937446
 
937446
 Note: Be sure this composed host name is locally resolveable and the
937446
 associated IP is reachable through the favored network.
937446
+
937446
+See also the migrate_options parameter below.
937446
 </longdesc>
937446
 <shortdesc lang="en">Migration network host name suffix</shortdesc>
937446
 <content type="string" default="" />
937446
 </parameter>
937446
 
937446
+<parameter name="migrate_options" unique="0" required="0">
937446
+<longdesc lang="en">
937446
+Extra virsh options for the guest live migration. You can also specify
937446
+here --migrateuri if the calculated migrate URI is unsuitable for your
937446
+environment. If --migrateuri is set then migration_network_suffix
937446
+and migrateport are effectively ignored. Use "%n" as the placeholder
937446
+for the target node name.
937446
+
937446
+Please refer to the libvirt documentation for details on guest
937446
+migration.
937446
+</longdesc>
937446
+<shortdesc lang="en">live migrate options</shortdesc>
937446
+<content type="string" />
937446
+</parameter>
937446
+
937446
 <parameter name="monitor_scripts" unique="0" required="0">
937446
 <longdesc lang="en">
937446
 To additionally monitor services within the virtual domain, add this
937446
@@ -485,14 +502,45 @@
937446
 	force_stop
937446
 }
937446
 
937446
+mk_migrateuri() {
937446
+	local target_node
937446
+	local migrate_target
937446
+	local hypervisor
937446
+
937446
+	target_node="$OCF_RESKEY_CRM_meta_migrate_target"
937446
+
937446
+	# A typical migration URI via a special  migration network looks
937446
+	# like "tcp://bar-mig:49152". The port would be randomly chosen
937446
+	# by libvirt from the range 49152-49215 if omitted, at least since
937446
+	# version 0.7.4 ...
937446
+	if [ -n "${OCF_RESKEY_migration_network_suffix}" ]; then
937446
+		hypervisor="${OCF_RESKEY_hypervisor%%[+:]*}"
937446
+		# Hostname might be a FQDN
937446
+		migrate_target=$(echo ${target_node} | sed -e "s,^\([^.]\+\),\1${OCF_RESKEY_migration_network_suffix},")
937446
+		case $hypervisor in
937446
+			qemu)
937446
+				# For quiet ancient libvirt versions a migration port is needed
937446
+				# and the URI must not contain the "//". Newer versions can handle
937446
+				# the "bad" URI.
937446
+				echo "tcp:${migrate_target}:${OCF_RESKEY_migrateport}"
937446
+				;;
937446
+			xen)
937446
+				echo "xenmigr://${migrate_target}"
937446
+				;;
937446
+			*)
937446
+				ocf_log warn "$DOMAIN_NAME: Migration via dedicated network currently not supported for ${hypervisor}."
937446
+				;;
937446
+		esac
937446
+	fi
937446
+}
937446
+
937446
 VirtualDomain_Migrate_To() {
937446
+	local rc
937446
 	local target_node
937446
 	local remoteuri
937446
 	local transport_suffix
937446
 	local migrateuri
937446
-	local migrateport
937446
-	local migrate_target
937446
-	local hypervisor
937446
+	local migrate_opts
937446
 
937446
 	target_node="$OCF_RESKEY_CRM_meta_migrate_target"
937446
 
937446
@@ -503,38 +551,26 @@
937446
 		if [ -n "${OCF_RESKEY_migration_transport}" ]; then
937446
 			transport_suffix="+${OCF_RESKEY_migration_transport}"
937446
 		fi
937446
-		# A typical migration URI via a special  migration network looks
937446
-		# like "tcp://bar-mig:49152". The port would be randomly chosen
937446
-		# by libvirt from the range 49152-49215 if omitted, at least since
937446
-		# version 0.7.4 ...
937446
-		if [ -n "${OCF_RESKEY_migration_network_suffix}" ]; then
937446
-			hypervisor="${OCF_RESKEY_hypervisor%%[+:]*}"
937446
-			# Hostname might be a FQDN
937446
-			migrate_target=$(echo ${target_node} | sed -e "s,^\([^.]\+\),\1${OCF_RESKEY_migration_network_suffix},")
937446
-			case $hypervisor in
937446
-				qemu)
937446
-					# For quiet ancient libvirt versions a migration port is needed
937446
-					# and the URI must not contain the "//". Newer versions can handle
937446
-					# the "bad" URI.
937446
-					migrateuri="tcp:${migrate_target}:${OCF_RESKEY_migrateport}"
937446
-					;;
937446
-				xen)
937446
-					migrateuri="xenmigr://${migrate_target}"
937446
-					;;
937446
-				*)
937446
-					ocf_log warn "$DOMAIN_NAME: Migration via dedicated network currently not supported for ${hypervisor}."
937446
-					;;
937446
-			esac
937446
+
937446
+		# User defined migrateuri or do we make one?
937446
+		migrate_opts="$OCF_RESKEY_migrate_options"
937446
+		if echo "$migrate_opts" | fgrep -qs -- "--migrateuri="; then
937446
+			migrateuri=`echo "$migrate_opts" |
937446
+				sed "s/.*--migrateuri=\([^ ]*\).*/\1/;s/%n/$target_node/g"`
937446
+			migrate_opts=`echo "$migrate_opts" |
937446
+				sed "s/\(.*\)--migrateuri=[^ ]*\(.*\)/\1\3/"`
937446
+		else
937446
+			migrateuri=`mk_migrateuri`
937446
 		fi
937446
 		# Scared of that sed expression? So am I. :-)
937446
 		remoteuri=$(echo ${OCF_RESKEY_hypervisor} | sed -e "s,\(.*\)://[^/:]*\(:\?[0-9]*\)/\(.*\),\1${transport_suffix}://${target_node}\2/\3,")
937446
 
937446
 		# OK, we know where to connect to. Now do the actual migration.
937446
-		ocf_log info "$DOMAIN_NAME: Starting live migration to ${target_node} (using remote hypervisor URI ${remoteuri} ${migrateuri})."
937446
-		virsh ${VIRSH_OPTIONS} migrate --live $DOMAIN_NAME ${remoteuri} ${migrateuri}
937446
+		ocf_log info "$DOMAIN_NAME: Starting live migration to ${target_node} (using virsh ${VIRSH_OPTIONS} migrate --live $migrate_opts $DOMAIN_NAME $remoteuri $migrateuri)."
937446
+		virsh ${VIRSH_OPTIONS} migrate --live $migrate_opts $DOMAIN_NAME $remoteuri $migrateuri
937446
 		rc=$?
937446
 		if [ $rc -ne 0 ]; then
937446
-			ocf_exit_reason "$DOMAIN_NAME: live migration to ${remoteuri} ${migrateuri} failed: $rc"
937446
+			ocf_exit_reason "$DOMAIN_NAME: live migration to ${target_node} failed: $rc"
937446
 			return $OCF_ERR_GENERIC
937446
 		else
937446
 			ocf_log info "$DOMAIN_NAME: live migration to ${target_node} succeeded."