Hee Tiniva, this is the output of if:
root@opennebula-01:~# su oneadmin
oneadmin@opennebula-01:/home/user$ bash -xv /var/lib/one/remotes/tm/shared/clone opennebula-01:/var/lib/one//datastores/103/d394b97809d7a1b02d3fdac2fd6793a6 192.168.16.112:/var/lib/one//datastores/101/10/disk.0 10 103
#!/bin/bash
clone fe:SOURCE host:remote_system_ds/disk.i vmid dsid
- fe is the front-end hostname
- SOURCE is the path of the disk image in the form DS_BASE_PATH/disk
- host is the target host to deploy the VM
- remote_system_ds is the path for the system datastore in the host
- vmid is the id of the VM
- dsid is the target datastore (0 is the system datastore)
SRC=$1
- SRC=opennebula-01:/var/lib/one//datastores/103/d394b97809d7a1b02d3fdac2fd6793a6
DST=$2
- DST=192.168.16.112:/var/lib/one//datastores/101/10/disk.0
VMID=$3
if [ -z “${ONE_LOCATION}” ]; then
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
else
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
fi
- ‘[’ -z ‘’ ‘]’
- TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
. $TMCOMMON
- . /var/lib/one/remotes/tm/tm_common.sh
export LANG=C
++ export LANG=C
++ LANG=C
if [ -z “$ONE_LOCATION” ]; then
ONE_LOCAL_VAR=/var/lib/one
ONE_LIB=/usr/lib/one
DS_DIR=/var/lib/one/datastores
else
ONE_LOCAL_VAR=$ONE_LOCATION/var
ONE_LIB=$ONE_LOCATION/lib
DS_DIR=$ONE_LOCATION/var/datastores
fi
++ ‘[’ -z ‘’ ‘]’
++ ONE_LOCAL_VAR=/var/lib/one
++ ONE_LIB=/usr/lib/one
++ DS_DIR=/var/lib/one/datastores
ONE_SH=$ONE_LIB/sh
++ ONE_SH=/usr/lib/one/sh
. $ONE_SH/scripts_common.sh
++ . /usr/lib/one/sh/scripts_common.sh
--------------------------------------------------------------------------
Copyright 2002-2016, OpenNebula Project, OpenNebula Systems
Licensed under the Apache License, Version 2.0 (the “License”); you may
not use this file except in compliance with the License. You may obtain
a copy of the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#--------------------------------------------------------------------------- #
export LANG=C
+++ export LANG=C
+++ LANG=C
Paths for utilities
export PATH=/bin:/sbin:/usr/bin:$PATH
+++ export PATH=/bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
+++ PATH=/bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
AWK=${AWK:-awk}
+++ AWK=awk
BASH=${BASH:-bash}
+++ BASH=/bin/bash
CUT=${CUT:-cut}
+++ CUT=cut
CEPH=${CEPH:-ceph}
+++ CEPH=ceph
DATE=${DATE:-date}
+++ DATE=date
DD=${DD:-dd}
+++ DD=dd
DF=${DF:-df}
+++ DF=df
DU=${DU:-du}
+++ DU=du
GREP=${GREP:-grep}
+++ GREP=grep
ISCSIADM=${ISCSIADM:-iscsiadm}
+++ ISCSIADM=iscsiadm
LVCREATE=${LVCREATE:-lvcreate}
+++ LVCREATE=lvcreate
LVREMOVE=${LVREMOVE:-lvremove}
+++ LVREMOVE=lvremove
LVCHANGE=${LVCHANGE:-lvchange}
+++ LVCHANGE=lvchange
LVSCAN=${LVSCAN:-lvscan}
+++ LVSCAN=lvscan
LVS=${LVS:-lvs}
+++ LVS=lvs
LN=${LN:-ln}
+++ LN=ln
MD5SUM=${MD5SUM:-md5sum}
+++ MD5SUM=md5sum
MKFS=${MKFS:-mkfs}
+++ MKFS=mkfs
MKISOFS=${MKISOFS:-genisoimage}
+++ MKISOFS=genisoimage
MKSWAP=${MKSWAP:-mkswap}
+++ MKSWAP=mkswap
QEMU_IMG=${QMEMU_IMG:-qemu-img}
+++ QEMU_IMG=qemu-img
RADOS=${RADOS:-rados}
+++ RADOS=rados
RBD=${RBD:-rbd}
+++ RBD=rbd
READLINK=${READLINK:-readlink}
+++ READLINK=readlink
RM=${RM:-rm}
+++ RM=rm
CP=${CP:-cp}
+++ CP=cp
SCP=${SCP:-scp}
+++ SCP=scp
SED=${SED:-sed}
+++ SED=sed
SSH=${SSH:-ssh}
+++ SSH=ssh
SUDO=${SUDO:-sudo}
+++ SUDO=sudo
SYNC=${SYNC:-sync}
+++ SYNC=sync
TAR=${TAR:-tar}
+++ TAR=tar
TGTADM=${TGTADM:-tgtadm}
+++ TGTADM=tgtadm
TGTADMIN=${TGTADMIN:-tgt-admin}
+++ TGTADMIN=tgt-admin
TGTSETUPLUN=${TGTSETUPLUN:-tgt-setup-lun-one}
+++ TGTSETUPLUN=tgt-setup-lun-one
TR=${TR:-tr}
+++ TR=tr
VGDISPLAY=${VGDISPLAY:-vgdisplay}
+++ VGDISPLAY=vgdisplay
VMKFSTOOLS=${VMKFSTOOLS:-vmkfstools}
+++ VMKFSTOOLS=vmkfstools
WGET=${WGET:-wget}
+++ WGET=wget
if [ “x$(uname -s)” = “xLinux” ]; then
SED=“$SED -r”
else
SED=“/usr/bin/sed -E”
fi
uname -s
++++ uname -s
+++ ‘[’ xLinux = xLinux ‘]’
+++ SED=‘sed -r’
Used for log messages
SCRIPT_NAME=basename $0
basename $0
++++ basename /var/lib/one/remotes/tm/shared/clone
+++ SCRIPT_NAME=clone
------------------------------------------------------------------------------
Path manipulation functions
------------------------------------------------------------------------------
Takes out unneeded slashes. Repeated and final directory slashes:
/some//path///somewhere/ → /some/path/somewhere
function fix_dir_slashes
{
dirname “$1/file” | $SED ‘s//+///g’
}
------------------------------------------------------------------------------
Log functions
------------------------------------------------------------------------------
Formats date for logs
function log_date
{
$DATE +“%a %b %d %T %Y”
}
Logs a message, alias to log_info
function log
{
log_info “$1”
}
Log function that knows how to deal with severities and adds the
script name
function log_function
{
echo “$1: $SCRIPT_NAME: $2” 1>&2
}
Logs an info message
function log_info
{
log_function “INFO” “$1”
}
Logs an error message
function log_error
{
log_function “ERROR” “$1”
}
Logs a debug message
function log_debug
{
log_function “DEBUG” “$1”
}
This function is used to pass error message to the mad
function error_message
{
(
echo “ERROR MESSAGE --8<------”
echo “$1”
echo “ERROR MESSAGE ------>8–”
) 1>&2
}
Executes a command, if it fails returns error message and exits
If a second parameter is present it is used as the error message when
the command fails
function exec_and_log
{
message=$2
EXEC_LOG_ERR=`$1 2>&1 1>/dev/null`
EXEC_LOG_RC=$?
if [ $EXEC_LOG_RC -ne 0 ]; then
log_error "Command \"$1\" failed: $EXEC_LOG_ERR"
if [ -n "$2" ]; then
error_message "$2"
else
error_message "Error executing $1: $EXEC_LOG_ERR"
fi
exit $EXEC_LOG_RC
fi
}
This function executes $1 and returns stdout
If a second parameter is present it is used as the error message when
the command fails
function monitor_and_log
{
EXEC_OUT=“$(bash -s 2>/dev/null <<EOF
export LANG=C
export LC_ALL=C
set -xv
$1
EOF
)”
EXEC_RC=$?
if [ $EXEC_RC -ne 0 ]; then
if [ -n "$2" ]; then
log_error "Command \"$2\" failed: $EXEC_OUT"
else
log_error "Command \"$1\" failed: $EXEC_OUT"
fi
exit $EXEC_RC
fi
echo "$EXEC_OUT"
}
Executes a command, if it fails returns error message and exits. Similar to
exec_and_log, except that it allows multiline commands.
If a second parameter is present it is used as the error message when
the command fails.
function multiline_exec_and_log
{
message=$2
EXEC_LOG_ERR=`bash -s 2>&1 1>/dev/null <<EOF
export LANG=C
export LC_ALL=C
$1
EOF`
EXEC_LOG_RC=$?
if [ $EXEC_LOG_RC -ne 0 ]; then
log_error "Command \"$1\" failed: $EXEC_LOG_ERR"
if [ -n "$2" ]; then
error_message "$2"
else
error_message "Error executing $1: $EXEC_LOG_ERR"
fi
exit $EXEC_LOG_RC
fi
}
Like exec_and_log but does not exit on failure. Just sets the variable
ERROR to the error message.
function exec_and_set_error
{
message=$2
EXEC_LOG_ERR=$(bash -c "$1" 2>&1 1>/dev/null)
EXEC_LOG_RC=$?
export ERROR=""
if [ $EXEC_LOG_RC -ne 0 ]; then
log_error "Command \"$1\" failed: $EXEC_LOG_ERR"
if [ -n "$2" ]; then
export ERROR="$2"
else
export ERROR="Error executing $1: $EXEC_LOG_ERR"
fi
fi
}
Like exec_and_log but the first argument is the number of seconds
before here is timeout and kills the command
NOTE: if the command is killed because a timeout the exit code
will be 143 = 128+15 (SIGHUP)
function timeout_exec_and_log
{
TIMEOUT=$1
shift
CMD="$1"
exec_and_log "$CMD" &
CMD_PID=$!
# timeout process
(
sleep $TIMEOUT
kill $CMD_PID 2>/dev/null
log_error "Timeout executing $CMD"
error_message "Timeout executing $CMD"
exit -1
) &
TIMEOUT_PID=$!
# stops the execution until the command finalizes
wait $CMD_PID 2>/dev/null
CMD_CODE=$?
# if the script reaches here the command finished before it
# consumes timeout seconds so we can kill timeout process
kill $TIMEOUT_PID 2>/dev/null 1>/dev/null
wait $TIMEOUT_PID 2>/dev/null
# checks the exit code of the command and exits if it is not 0
if [ "x$CMD_CODE" != "x0" ]; then
exit $CMD_CODE
fi
}
Parameters are times (seconds) and monitoring command (or function).
Executes monitoring command until it is successful (VM is no longer
running) or the timeout is reached.
function retry
{
times=$1
function=$2
count=1
ret=$($function)
error=$?
while [ $count -lt $times -a "$error" != "0" ]; do
sleep 1
count=$(( $count + 1 ))
ret=$($function)
error=$?
done
[ "x$error" = "x0" ]
}
Parameters are deploy_id and cancel command. If the last command is
unsuccessful and $FORCE_DESTROY=yes then calls cancel command
function force_shutdown {
error=$?
deploy_id=$1
command=$2
if [ "x$error" != "x0" ]; then
if [ "$FORCE_DESTROY" = "yes" ]; then
log_error "Timeout shutting down $deploy_id. Destroying it"
$($command)
sleep 2
else
error_message "Timed out shutting down $deploy_id"
exit -1
fi
fi
}
This function will return a command that upon execution will format a
filesystem with its proper parameters based on the filesystem type
function mkfs_command {
DST=$1
FSTYPE=$2
SIZE=${3:-0}
if [ "$FSTYPE" = "qcow2" ]; then
QEMU_FORMAT="qcow2"
else
QEMU_FORMAT="raw"
fi
echo "$QEMU_IMG create -f ${QEMU_FORMAT} ${DST} ${SIZE}M"
if [ "$FSTYPE" = "swap" ]; then
echo "$MKSWAP -L swap $DST"
fi
}
#This function executes $2 at $1 host and report error $3 but does not exit
function ssh_exec_and_log_no_error
{
SSH_EXEC_ERR=$SSH $1 bash -s 2>&1 1>/dev/null <<EOF export LANG=C export LC_ALL=C $2 EOF
SSH_EXEC_RC=$?
if [ $SSH_EXEC_RC -ne 0 ]; then
log_error "Command \"$2\" failed: $SSH_EXEC_ERR"
if [ -n "$3" ]; then
error_message "$3"
else
error_message "Error executing $2: $SSH_EXEC_ERR"
fi
return $SSH_EXEC_RC
fi
return 0
}
#This function executes $2 at $1 host and report error $3
function ssh_exec_and_log
{
ssh_exec_and_log_no_error “$@”
EXEC_RC=$?
if [ "$EXEC_RC" != "0" ]; then
exit $EXEC_RC
fi
}
Remote command execution over SSH preloading a local file
$1: HOSTNAME
$2: COMMAND
$3: file to be loaded into the script
$4: ERROR_REPORT
function ssh_exec_and_log_stdin
{
SSH_EXEC_ERR=`$SSH $1 bash -s 2>&1 1>/dev/null <<EOF
export LANG=C
export LC_ALL=C
$(cat $3)
$2
EOF`
SSH_EXEC_RC=$?
if [ $SSH_EXEC_RC -ne 0 ]; then
log_error "Command \"$2\" failed: $SSH_EXEC_ERR"
if [ -n "$4" ]; then
error_message "$4"
else
error_message "Error executing $2: $SSH_EXEC_ERR"
fi
exit $SSH_EXEC_RC
fi
}
This function executes $2 at $1 host and returns stdout
If $3 is present, it is used as the error message when
the command fails
function ssh_monitor_and_log
{
SSH_EXEC_OUT=“$($SSH $1 bash -s 2>/dev/null <<EOF
export LANG=C
export LC_ALL=C
$2
EOF
)”
SSH_EXEC_RC=$?
if [ $SSH_EXEC_RC -ne 0 ]; then
if [ -n "$3" ]; then
log_error "Command \"$3\" failed: $SSH_EXEC_OUT"
else
log_error "Command \"$2\" failed: $SSH_EXEC_OUT"
fi
exit $SSH_EXEC_RC
fi
echo "$SSH_EXEC_OUT"
}
Creates path ($2) at $1. If there is a third parameter it is writen as
file “.monitor” in the directory. Used for local disk monitoring
function ssh_make_path
{
SSH_EXEC_ERR=`$SSH $1 bash -s 2>&1 1>/dev/null <<EOF
set -e -o pipefail
if [ ! -d $2 ]; then
mkdir -p $2
if [ -n “$3” ]; then
echo “$3” > “$(dirname $2)/.monitor”
fi
fi
EOF`
SSH_EXEC_RC=$?
if [ $SSH_EXEC_RC -ne 0 ]; then
error_message "Error creating directory $2 at $1: $SSH_EXEC_ERR"
exit $SSH_EXEC_RC
fi
}
TODO → Use a dynamically loaded scripts directory. Not removing this due
------------------------------------------------------------------------------
iSCSI functions
------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
Returns the command to create a new target
@param $1 - ID of the image
@param $2 - Target Host
@param $3 - Device
@return the command to create a new target
#-------------------------------------------------------------------------------
function tgtadm_target_new {
ID=“$1”
IQN=“$2”
echo "$TGTADM --lld iscsi --op new --mode target --tid $ID "\
"--targetname $IQN"
}
function tgtadm_target_bind_all {
ID=“$1”
echo “$TGTADM --lld iscsi --op bind --mode target --tid $ID -I ALL”
}
function tgtadm_logicalunit_new {
ID=“$1”
DEV=“$2”
echo "$TGTADM --lld iscsi --op new --mode logicalunit --tid $ID "\
"--lun 1 --backing-store $DEV"
}
function tgtadm_target_delete {
ID=“$1”
echo “$TGTADM --lld iscsi --op delete --mode target --tid $ID”
}
function tgtadm_get_tid_for_iqn {
IQN=“$1”
echo “$TGTADM --lld iscsi --op show --mode target | strings |
grep "$IQN" | awk ‘{split($2,tmp,":"); print(tmp[1]);}’”
}
function tgtadm_next_tid {
echo “$TGTADM --lld iscsi --op show --mode target | strings |
$GREP "Target" | tail -n 1 |
$AWK ‘{split($2,tmp,":"); print tmp[1]+1;}’”
}
function tgt_admin_dump_config {
FILE_PATH=“$1”
echo “$TGTADMIN --dump |sudo tee $FILE_PATH > /dev/null 2>&1”
}
function iscsiadm_discovery {
TARGET_HOST=“$1”
echo “$ISCSIADM -m discovery -t st -p $TARGET_HOST”
}
function iscsiadm_login {
IQN=“$1”
TARGET_HOST=“$2”
echo “$ISCSIADM -m node --targetname $IQN -p $TARGET_HOST --login”
}
function iscsiadm_logout {
IQN=“$1”
echo “$ISCSIADM -m node --targetname $IQN --logout”
}
function is_iscsi {
if echo “$NO_ISCSI”|grep -q “\b$1\b”; then
return 1
else
return 0
fi
}
Checks wether $IMAGE_TYPE is CDROM
function is_cdrom {
[ “$IMAGE_TYPE” = “1” ]
}
function iqn_get_lv_name {
IQN=“$1”
TARGET=echo "$IQN"|$CUT -d: -f2
echo $TARGET|$AWK -F. ‘{print $(NF)}’
}
function iqn_get_vg_name {
IQN=“$1”
TARGET=echo "$IQN"|$CUT -d: -f2
echo $TARGET|$AWK -F. ‘{print $(NF-1)}’
}
function tgt_setup_lun_install {
DST_HOST=“$1”
BASE_PATH=“$2”
CHECK_FILE="$BASE_PATH/.tgt-setup-lun"
if [ ! -f "$CHECK_FILE" ]; then
$SSH "$DST_HOST" "$SUDO $TGTSETUPLUN" 2>&1 | \
$GREP -q "command not found"
if [ "$?" = "0" ]; then
error_message "$TGTSETUPLUN is not installed in $DST_HOST."
exit 127
else
touch "$CHECK_FILE"
fi
fi
}
function tgt_setup_lun {
IQN=“$1”
DEV=“$2”
echo “$TGTSETUPLUN -d $DEV -n $IQN 1>&2”
}
function iqn_get_host {
IQN=“$1”
TARGET=echo "$IQN"|$CUT -d: -f2
LV_NAME=$(iqn_get_lv_name “$IQN”)
VG_NAME=$(iqn_get_vg_name “$IQN”)
echo ${TARGET%%.$VG_NAME.$LV_NAME}
}
------------------------------------------------------------------------------
VMM helpers
------------------------------------------------------------------------------
This function builds the XML necessary for attach-disk operations
that require declaration of host sources
@param $1 - Space separated list of hosts
@return The XML via STDOUT
function get_source_xml {
for host in $1 ; do
BCK_IFS=$IFS
IFS=‘:’
unset k HOST_PARTS SOURCE_HOST
for part in $host ; do
HOST_PARTS[k++]="$part"
done
SOURCE_HOST="$SOURCE_HOST<host name='${HOST_PARTS[0]}'"
if [ -n "${HOST_PARTS[1]}" ]; then
SOURCE_HOST="$SOURCE_HOST port='${HOST_PARTS[1]}'"
fi
SOURCE_HOST="$SOURCE_HOST/>"
IFS=$BCK_IFS
done
echo "$SOURCE_HOST"
}
------------------------------------------------------------------------------
Function to get hosts and paths from arguments
------------------------------------------------------------------------------
Gets the host from an argument
function arg_host
{
echo $1 | $SED ‘s/^([^:]):.$/\1/’
}
Gets the path from an argument
function arg_path
{
ARG_PATH=echo $1 | $SED 's/^[^:]*:(.*)$/\1/'
fix_dir_slashes “$ARG_PATH”
}
#Return 1 if the first argument is a disk
function is_disk
{
echo “$1” | $GREP ‘/disk.[0-9]+’ > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "1"
else
echo "0"
fi
}
#Makes path src ($1) relative to dst ($2)
function make_relative {
src=$1
dst=$2
common=$dst
while [ -z "`echo $src | grep -E "^$common"`" ]; do
common=`dirname $common`
dots="../$dots"
done
echo $dots${src#$common/}
}
#Return DISK_TYPE
function disk_type
{
# Let’s check if it is a CDROM
DISK_ID=$(echo “$DST_PATH” | $AWK -F. ‘{print $NF}’)
XPATH=“${ONE_LOCAL_VAR}/remotes/datastore/xpath.rb --stdin”
unset i XPATH_ELEMENTS
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <(onevm show -x $VMID| $XPATH \
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/TYPE )
DISK_TYPE="${XPATH_ELEMENTS[0]}"
echo $DISK_TYPE
}
#Return LCM_STATE
function lcm_state
{
XPATH=“${ONE_LOCAL_VAR}/remotes/datastore/xpath.rb --stdin”
unset i XPATH_ELEMENTS
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <(onevm show -x $VMID| $XPATH \
/VM/LCM_STATE )
LCM_STATE="${XPATH_ELEMENTS[0]}"
echo $LCM_STATE
}
function migrate_other
{
DRIVER_PATH=$(dirname $0)
MAD=${DRIVER_PATH##*/}
XPATH="$DRIVER_PATH/../../datastore/xpath.rb"
unset i
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done< <("$XPATH" -b "$6" \
/VM/TEMPLATE/CONTEXT/DISK_ID \
%m%/VM/TEMPLATE/DISK/DISK_ID \
%m%/VM/TEMPLATE/DISK/CLONE \
%m%/VM/TEMPLATE/DISK/TM_MAD)
unset i
CONTEXT_DISK_ID="${XPATH_ELEMENTS[i++]}"
DISK_IDS="${XPATH_ELEMENTS[i++]}"
CLONES="${XPATH_ELEMENTS[i++]}"
TM_MADS="${XPATH_ELEMENTS[i++]}"
DISK_ID_ARRAY=($DISK_IDS)
CLONE_ARRAY=($CLONES)
TM_MAD_ARRAY=($TM_MADS)
if [ -n "$7" ]; then
return 0
fi
for i in ${!TM_MAD_ARRAY[@]}; do
TM="${TM_MAD_ARRAY[i]}"
if [ "$TM" = "$MAD" ]; then
continue
fi
if [ "${PROCESSED/ $TM /}" = "$PROCESSED" ]; then
# 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"
PROCESSED+=" $TM "
fi
done
}
DRIVER_PATH=$(dirname $0)
dirname $0
++ dirname /var/lib/one/remotes/tm/shared/clone
- DRIVER_PATH=/var/lib/one/remotes/tm/shared
#-------------------------------------------------------------------------------
Set dst path and dir
#-------------------------------------------------------------------------------
DST_PATH=arg_path $DST
arg_path $DST
++ arg_path 192.168.16.112:/var/lib/one//datastores/101/10/disk.0
echo $1 | $SED ‘s/:(.)$/\1/’
+++ echo 192.168.16.112:/var/lib/one//datastores/101/10/disk.0
+++ sed -r ‘s/:(.)$/\1/’
++ ARG_PATH=/var/lib/one//datastores/101/10/disk.0
++ fix_dir_slashes /var/lib/one//datastores/101/10/disk.0
++ dirname /var/lib/one//datastores/101/10/disk.0/file
++ sed -r ‘s//+///g’
- DST_PATH=/var/lib/one/datastores/101/10/disk.0
DST_HOST=arg_host $DST
arg_host $DST
++ arg_host 192.168.16.112:/var/lib/one//datastores/101/10/disk.0
++ echo 192.168.16.112:/var/lib/one//datastores/101/10/disk.0
++ sed -r ‘s/^([^:]):.$/\1/’
- DST_HOST=192.168.16.112
DST_DIR=dirname $DST_PATH
dirname $DST_PATH
++ dirname /var/lib/one/datastores/101/10/disk.0
- DST_DIR=/var/lib/one/datastores/101/10
SRC_ARG_PATH=arg_path $SRC
arg_path $SRC
++ arg_path opennebula-01:/var/lib/one//datastores/103/d394b97809d7a1b02d3fdac2fd6793a6
echo $1 | $SED ‘s/:(.)$/\1/’
+++ echo opennebula-01:/var/lib/one//datastores/103/d394b97809d7a1b02d3fdac2fd6793a6
+++ sed -r ‘s/:(.)$/\1/’
++ ARG_PATH=/var/lib/one//datastores/103/d394b97809d7a1b02d3fdac2fd6793a6
++ fix_dir_slashes /var/lib/one//datastores/103/d394b97809d7a1b02d3fdac2fd6793a6
++ dirname /var/lib/one//datastores/103/d394b97809d7a1b02d3fdac2fd6793a6/file
++ sed -r ‘s//+///g’
- SRC_ARG_PATH=/var/lib/one/datastores/103/d394b97809d7a1b02d3fdac2fd6793a6
DST_DS_PATH=“$(dirname $(dirname $(dirname $DST_PATH)))”
dirname $(dirname $(dirname $DST_PATH))
dirname $(dirname $DST_PATH)
dirname $DST_PATH
++++ dirname /var/lib/one/datastores/101/10/disk.0
+++ dirname /var/lib/one/datastores/101/10
++ dirname /var/lib/one/datastores/101
- DST_DS_PATH=/var/lib/one/datastores
SRC_DS_PATH=“$(dirname $(dirname $SRC_ARG_PATH))”
dirname $(dirname $SRC_ARG_PATH)
dirname $SRC_ARG_PATH
+++ dirname /var/lib/one/datastores/103/d394b97809d7a1b02d3fdac2fd6793a6
++ dirname /var/lib/one/datastores/103
- SRC_DS_PATH=/var/lib/one/datastores
SRC_PATH=“${DST_DS_PATH}${SRC_ARG_PATH##$SRC_DS_PATH}”
- SRC_PATH=/var/lib/one/datastores/103/d394b97809d7a1b02d3fdac2fd6793a6
#-------------------------------------------------------------------------------
Get Image information
#-------------------------------------------------------------------------------
DISK_ID=$(basename ${DST_PATH} | cut -d. -f2)
basename ${DST_PATH} | cut -d. -f2
++ basename /var/lib/one/datastores/101/10/disk.0
++ cut -d. -f2
XPATH=“${DRIVER_PATH}/…/…/datastore/xpath.rb --stdin”
- XPATH=‘/var/lib/one/remotes/tm/shared/…/…/datastore/xpath.rb --stdin’
unset i j XPATH_ELEMENTS
while IFS= read -r -d ‘’ element; do
XPATH_ELEMENTS[i++]=“$element”
done < <(onevm show -x $VMID| $XPATH
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SIZE
/VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/ORIGINAL_SIZE
/VM/HISTORY_RECORDS/HISTORY[last()]/TM_MAD)
- IFS=
- read -r -d ‘’ element
onevm show -x $VMID| $XPATH /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SIZE /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/ORIGINAL_SIZE /VM/HISTORY_RECORDS/HISTORY[last()]/TM_MAD
++ onevm show -x 10
++ /var/lib/one/remotes/tm/shared/…/…/datastore/xpath.rb --stdin ‘/VM/TEMPLATE/DISK[DISK_ID=0]/SIZE’ ‘/VM/TEMPLATE/DISK[DISK_ID=0]/ORIGINAL_SIZE’ ‘/VM/HISTORY_RECORDS/HISTORY[last()]/TM_MAD’
- XPATH_ELEMENTS[i++]=40
- IFS=
- read -r -d ‘’ element
- XPATH_ELEMENTS[i++]=
- IFS=
- read -r -d ‘’ element
- XPATH_ELEMENTS[i++]=shared
- IFS=
- read -r -d ‘’ element
SIZE=“${XPATH_ELEMENTS[j++]}”
- SIZE=40
ORIGINAL_SIZE=“${XPATH_ELEMENTS[j++]}”
- ORIGINAL_SIZE=
TM_MAD=“${XPATH_ELEMENTS[j++]}”
- TM_MAD=shared
if [ “$TM_MAD” = “ssh” ]; then
MONITOR=“ssh”
else
MONITOR=“”
fi
- ‘[’ shared = ssh ‘]’
- MONITOR=
#-------------------------------------------------------------------------------
Create DST path
#-------------------------------------------------------------------------------
ssh_make_path $DST_HOST $DST_DIR $MONITOR
-
ssh_make_path 192.168.16.112 /var/lib/one/datastores/101/10
$SSH $1 bash -s 2>&1 1>/dev/null <<EOF
set -e -o pipefail
if [ ! -d $2 ]; then
mkdir -p $2
if [ -n “$3” ]; then
echo “$3” > “$(dirname $2)/.monitor”
fi
fi
EOF
++ ssh 192.168.16.112 bash -s
-
SSH_EXEC_ERR=‘dirname $2
+++ dirname /var/lib/one/datastores/101/10’
-
SSH_EXEC_RC=0
-
‘[’ 0 -ne 0 ‘]’
#-------------------------------------------------------------------------------
Clone (cp) SRC into DST
#-------------------------------------------------------------------------------
if [ -n “$ORIGINAL_SIZE” -a “$SIZE” -gt “$ORIGINAL_SIZE” ]; then
RESIZE_CMD=“; qemu-img resize ${DST_PATH} ${SIZE}M”
fi
- ‘[’ -n ‘’ -a 40 -gt ‘’ ‘]’
/var/lib/one/remotes/tm/shared/clone: line 94: [: : integer expression expected
log “Cloning $SRC_PATH in $DST”
- log ‘Cloning /var/lib/one/datastores/103/d394b97809d7a1b02d3fdac2fd6793a6 in 192.168.16.112:/var/lib/one//datastores/101/10/disk.0’
- log_info ‘Cloning /var/lib/one/datastores/103/d394b97809d7a1b02d3fdac2fd6793a6 in 192.168.16.112:/var/lib/one//datastores/101/10/disk.0’
- log_function INFO ‘Cloning /var/lib/one/datastores/103/d394b97809d7a1b02d3fdac2fd6793a6 in 192.168.16.112:/var/lib/one//datastores/101/10/disk.0’
- echo ‘INFO: clone: Cloning /var/lib/one/datastores/103/d394b97809d7a1b02d3fdac2fd6793a6 in 192.168.16.112:/var/lib/one//datastores/101/10/disk.0’
INFO: clone: Cloning /var/lib/one/datastores/103/d394b97809d7a1b02d3fdac2fd6793a6 in 192.168.16.112:/var/lib/one//datastores/101/10/disk.0
CLONE_CMD=“cd ${DST_DIR};
rm -f ${DST_PATH};
cp ${SRC_PATH} ${DST_PATH}
${RESIZE_CMD}”
- CLONE_CMD='cd /var/lib/one/datastores/101/10; rm -f /var/lib/one/datastores/101/10/disk.0; cp /var/lib/one/datastores/103/d394b97809d7a1b02d3fdac2fd6793a6 /var/lib/one/datastores/101/10/disk.0 ’
ssh_exec_and_log $DST_HOST
“$CLONE_CMD”
“Error copying $SRC to $DST”
- ssh_exec_and_log 192.168.16.112 'cd /var/lib/one/datastores/101/10; rm -f /var/lib/one/datastores/101/10/disk.0; cp /var/lib/one/datastores/103/d394b97809d7a1b02d3fdac2fd6793a6 /var/lib/one/datastores/101/10/disk.0 ’ ‘Error copying opennebula-01:/var/lib/one//datastores/103/d394b97809d7a1b02d3fdac2fd6793a6 to 192.168.16.112:/var/lib/one//datastores/101/10/disk.0’
- ssh_exec_and_log_no_error 192.168.16.112 'cd /var/lib/one/datastores/101/10; rm -f /var/lib/one/datastores/101/10/disk.0; cp /var/lib/one/datastores/103/d394b97809d7a1b02d3fdac2fd6793a6 /var/lib/one/datastores/101/10/disk.0 ’ ‘Error copying opennebula-01:/var/lib/one//datastores/103/d394b97809d7a1b02d3fdac2fd6793a6 to 192.168.16.112:/var/lib/one//datastores/101/10/disk.0’
$SSH $1 bash -s 2>&1 1>/dev/null <<EOF
export LANG=C
export LC_ALL=C
$2
EOF
++ ssh 192.168.16.112 bash -s
- SSH_EXEC_ERR=‘cp: cannot create regular file ‘'’/var/lib/one/datastores/101/10/disk.0’'‘: Operation not permitted’
- SSH_EXEC_RC=1
- ‘[’ 1 -ne 0 ‘]’
- log_error ‘Command "cd /var/lib/one/datastores/101/10; rm -f /var/lib/one/datastores/101/10/disk.0; cp /var/lib/one/datastores/103/d394b97809d7a1b02d3fdac2fd6793a6 /var/lib/one/datastores/101/10/disk.0 " failed: cp: cannot create regular file ‘'’/var/lib/one/datastores/101/10/disk.0’'‘: Operation not permitted’
- log_function ERROR ‘Command "cd /var/lib/one/datastores/101/10; rm -f /var/lib/one/datastores/101/10/disk.0; cp /var/lib/one/datastores/103/d394b97809d7a1b02d3fdac2fd6793a6 /var/lib/one/datastores/101/10/disk.0 " failed: cp: cannot create regular file ‘'’/var/lib/one/datastores/101/10/disk.0’'‘: Operation not permitted’
- echo ‘ERROR: clone: Command "cd /var/lib/one/datastores/101/10; rm -f /var/lib/one/datastores/101/10/disk.0; cp /var/lib/one/datastores/103/d394b97809d7a1b02d3fdac2fd6793a6 /var/lib/one/datastores/101/10/disk.0 " failed: cp: cannot create regular file ‘'’/var/lib/one/datastores/101/10/disk.0’'‘: Operation not permitted’
ERROR: clone: Command "cd /var/lib/one/datastores/101/10; rm -f /var/lib/one/datastores/101/10/disk.0; cp /var/lib/one/datastores/103/d394b97809d7a1b02d3fdac2fd6793a6 /var/lib/one/datastores/101/10/disk.0 " failed: cp: cannot create regular file ‘/var/lib/one/datastores/101/10/disk.0’: Operation not permitted
- ‘[’ -n ‘Error copying opennebula-01:/var/lib/one//datastores/103/d394b97809d7a1b02d3fdac2fd6793a6 to 192.168.16.112:/var/lib/one//datastores/101/10/disk.0’ ‘]’
- error_message ‘Error copying opennebula-01:/var/lib/one//datastores/103/d394b97809d7a1b02d3fdac2fd6793a6 to 192.168.16.112:/var/lib/one//datastores/101/10/disk.0’
- echo ‘ERROR MESSAGE --8<------’
ERROR MESSAGE --8<------
- echo ‘Error copying opennebula-01:/var/lib/one//datastores/103/d394b97809d7a1b02d3fdac2fd6793a6 to 192.168.16.112:/var/lib/one//datastores/101/10/disk.0’
Error copying opennebula-01:/var/lib/one//datastores/103/d394b97809d7a1b02d3fdac2fd6793a6 to 192.168.16.112:/var/lib/one//datastores/101/10/disk.0
- echo ‘ERROR MESSAGE ------>8–’
ERROR MESSAGE ------>8–
- return 1
- EXEC_RC=1
- ‘[’ 1 ‘!=’ 0 ‘]’
- exit 1
oneadmin@opennebula-01:/home/user$