From 41d9e000eddaf3c4d279ab06ede763f61bd3fee3 Mon Sep 17 00:00:00 2001 From: Jan Orel Date: Mon, 12 Aug 2019 16:02:25 +0200 Subject: [PATCH] B #3373: pass VM template via STDIN (#3583) --- src/tm_mad/ceph/postmigrate | 6 +++--- src/tm_mad/ceph/premigrate | 6 +++--- src/tm_mad/common/prepostmigrate | 3 +-- src/tm_mad/fs_lvm/postmigrate | 2 +- src/tm_mad/fs_lvm/premigrate | 2 +- src/tm_mad/one_tm.rb | 5 +++-- src/tm_mad/tm_common.sh | 7 ++++--- src/vmm_mad/exec/one_vmm_exec.rb | 13 ++++++++----- 8 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/tm_mad/ceph/postmigrate b/src/tm_mad/ceph/postmigrate index efd7b5566b..7b6b53ccbb 100755 --- a/src/tm_mad/ceph/postmigrate +++ b/src/tm_mad/ceph/postmigrate @@ -32,7 +32,7 @@ DST_PATH=$3 VMID=$4 DSID=$5 -TEMPLATE_64=$6 +TEMPLATE_64=$(cat) #-------------------------------------------------------------------------------- @@ -53,8 +53,8 @@ fi #-------------------------------------------------------------------------------- -if [ -n "$7" ]; then - log "Called from tm/$7 but I've nothing to do" +if [ -n "$6" ]; then + log "Called from tm/$6 but I've nothing to do" exit 0 fi diff --git a/src/tm_mad/ceph/premigrate b/src/tm_mad/ceph/premigrate index c041bd6f1e..c95c1a8c09 100755 --- a/src/tm_mad/ceph/premigrate +++ b/src/tm_mad/ceph/premigrate @@ -32,7 +32,7 @@ DST_PATH=$3 VMID=$4 DSID=$5 -TEMPLATE_64=$6 +TEMPLATE_64=$(cat) #-------------------------------------------------------------------------------- @@ -53,8 +53,8 @@ fi #-------------------------------------------------------------------------------- -if [ -n "$7" ]; then - log "Called from tm/$7 but I've nothing to do" +if [ -n "$6" ]; then + log "Called from tm/$6 but I've nothing to do" exit 0 fi diff --git a/src/tm_mad/common/prepostmigrate b/src/tm_mad/common/prepostmigrate index 6d93c53fb5..0a6c167df1 100755 --- a/src/tm_mad/common/prepostmigrate +++ b/src/tm_mad/common/prepostmigrate @@ -30,8 +30,7 @@ DST_HOST="$2" DST_PATH="$3" VM_ID="$4" DS_ID="$5" -TEMPLATE_64="$6" -SYSTEM_MAD="$7" +TEMPLATE_64=$(cat) #-------------------------------------------------------------------------------- diff --git a/src/tm_mad/fs_lvm/postmigrate b/src/tm_mad/fs_lvm/postmigrate index 110d66314b..7c68813b04 100755 --- a/src/tm_mad/fs_lvm/postmigrate +++ b/src/tm_mad/fs_lvm/postmigrate @@ -32,7 +32,7 @@ DST_PATH=$3 VMID=$4 DSID=$5 -TEMPLATE_64=$6 +TEMPLATE_64=$(cat) if [ -z "${ONE_LOCATION}" ]; then TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh diff --git a/src/tm_mad/fs_lvm/premigrate b/src/tm_mad/fs_lvm/premigrate index 72cd136c82..dddbb15cc3 100755 --- a/src/tm_mad/fs_lvm/premigrate +++ b/src/tm_mad/fs_lvm/premigrate @@ -32,7 +32,7 @@ DST_PATH=$3 VMID=$4 DSID=$5 -TEMPLATE_64=$6 +TEMPLATE_64=$(cat) if [ -z "${ONE_LOCATION}" ]; then TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh diff --git a/src/tm_mad/one_tm.rb b/src/tm_mad/one_tm.rb index dec2c62d00..e58d5acf15 100755 --- a/src/tm_mad/one_tm.rb +++ b/src/tm_mad/one_tm.rb @@ -96,7 +96,8 @@ class TransferManagerDriver < OpenNebulaDriver # method # @param id [String] with the OpenNebula ID for the TRANSFER action # @param command [Array] - def do_transfer_action(id, command) + # @param stdin [String] + def do_transfer_action(id, command, stdin=nil) cmd = command[0].downcase tm = command[1] args = command[2..-1].map{|e| Shellwords.escape(e)}.join(" ") @@ -122,7 +123,7 @@ class TransferManagerDriver < OpenNebulaDriver end path << " " << args - rc = LocalCommand.run(path, log_method(id)) + rc = LocalCommand.run(path, log_method(id), stdin) result, info = get_info_from_execution(rc) diff --git a/src/tm_mad/tm_common.sh b/src/tm_mad/tm_common.sh index d3e3d078a5..5e1d6ce977 100644 --- a/src/tm_mad/tm_common.sh +++ b/src/tm_mad/tm_common.sh @@ -115,6 +115,7 @@ function lcm_state function migrate_other { + DRIVER_PATH=$(dirname $0) MAD=${DRIVER_PATH##*/} @@ -123,7 +124,7 @@ function migrate_other unset i while IFS= read -r -d '' element; do XPATH_ELEMENTS[i++]="$element" - done< <("$XPATH" -b "$6" \ + done< <(echo $TEMPLATE_64 | base64 -d | "$XPATH" \ /VM/TEMPLATE/CONTEXT/DISK_ID \ %m%/VM/TEMPLATE/DISK/DISK_ID \ %m%/VM/TEMPLATE/DISK/CLONE \ @@ -138,7 +139,7 @@ function migrate_other CLONE_ARRAY=($CLONES) TM_MAD_ARRAY=($TM_MADS) - if [ -n "$7" ]; then + if [ -n "$6" ]; then return 0 fi @@ -152,7 +153,7 @@ function migrate_other # call the other TM_MADs with same arguments # but mark that it is not SYSTEM_DS log "Call $TM/${0##*/}" - "${DRIVER_PATH}/../$TM/${0##*/}" "$@" "$MAD" + echo $TEMPLATE_64 | "${DRIVER_PATH}/../$TM/${0##*/}" "$@" "$MAD" PROCESSED+=" $TM " fi done diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 215d39faa9..c9f2153270 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -227,7 +227,7 @@ class VmmAction result, info = vnm.do_action(@id, step[:action], :parameters => params) when :tm - result, info = @tm.do_transfer_action(@id, step[:parameters]) + result, info = @tm.do_transfer_action(@id, step[:parameters], stdin=step[:stdin]) else result = DriverExecHelper.const_get(:RESULT)[:failure] @@ -517,16 +517,17 @@ class ExecDriver < VirtualMachineDriver post = 'POST' failed = 'FAIL' - pre << action.data[:tm_command] << ' ' << action.data[:vm] - post << action.data[:tm_command] << ' ' << action.data[:vm] - failed << action.data[:tm_command] << ' ' << action.data[:vm] + pre << action.data[:tm_command] + post << action.data[:tm_command] + failed << action.data[:tm_command] steps = [ # Execute a pre-migrate TM setup { :driver => :tm, :action => :tm_premigrate, - :parameters => pre.split + :parameters => pre.split, + :stdin => action.data[:vm] }, # Execute pre-boot networking setup on migrating host { @@ -544,6 +545,7 @@ class ExecDriver < VirtualMachineDriver :driver => :tm, :action => :tm_failmigrate, :parameters => failed.split, + :stdin => action.data[:vm], :no_fail => true } ] @@ -569,6 +571,7 @@ class ExecDriver < VirtualMachineDriver :driver => :tm, :action => :tm_postmigrate, :parameters => post.split, + :stdin => action.data[:vm], :no_fail => true } ]