diff --git a/src/mad/sh/scripts_common.sh b/src/mad/sh/scripts_common.sh
index 9201d919a9..b60c15d8a7 100755
--- a/src/mad/sh/scripts_common.sh
+++ b/src/mad/sh/scripts_common.sh
@@ -109,19 +109,20 @@ function error_message
function exec_and_log
{
message=$2
- output=`$1 2>&1 1>/dev/null`
- code=$?
- if [ "x$code" != "x0" ]; then
- log_error "Command \"$1\" failed."
- log_error "$output"
- if [ -z "$message" ]; then
- error_message "$output"
+
+ 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 "$message"
+ error_message "Error executing $1: $EXEC_LOG_ERR"
fi
exit $code
fi
- log "Executed \"$1\"."
}
# Like exec_and_log but the first argument is the number of seconds
diff --git a/src/tm_mad/common/context b/src/tm_mad/common/context
new file mode 100755
index 0000000000..a36c2e5699
--- /dev/null
+++ b/src/tm_mad/common/context
@@ -0,0 +1,78 @@
+#!/bin/bash
+
+# -------------------------------------------------------------------------- #
+# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
+# #
+# 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 #
+# #
+# http://www.apache.org/licenses/LICENSE-2.0 #
+# #
+# 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. #
+#--------------------------------------------------------------------------- #
+
+# context context.sh file1 file2 ... fileN host:remote_system_ds/disk.i
+# - context.sh file are the contents of the context ISO
+# - host is the target host to deploy the VM
+# - remote_system_ds is the path for the system datastore in the host
+
+while (( "$#" )); do
+ if [ "$#" == "1" ]; then
+ DST=$1
+ else
+ SRC="$SRC $1"
+ fi
+ shift
+done
+
+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
+
+. $TMCOMMON
+
+#-------------------------------------------------------------------------------
+# Set dst path and dirs
+#-------------------------------------------------------------------------------
+DST_PATH=`arg_path $DST`
+DST_HOST=`arg_host $DST`
+DST_DIR=`dirname $DST_PATH`
+
+ssh_make_path $DST_HOST $DST_DIR
+
+#-------------------------------------------------------------------------------
+# Build the Context Block device (locally) and copy it remotely
+#-------------------------------------------------------------------------------
+log "Generating context block device at $DST"
+
+VM_ID=`basename $DST_DIR`
+ISO_DIR="$DS_DIR/.isofiles/$VM_ID"
+ISO_FILE="$ISO_DIR/$VM_ID.iso"
+
+exec_and_log "mkdir -p $ISO_DIR" "Could not create tmp dir to make context dev"
+
+for f in $SRC; do
+ case $f in
+ http://*)
+ exec_and_log "$WGET -P $ISO_DIR $f" "Error downloading $f"
+ ;;
+ *)
+ exec_and_log "cp -R $f $ISO_DIR" "Error copying $f to $ISO_DIR"
+ ;;
+ esac
+done
+
+exec_and_log "$MKISOFS -o $ISO_FILE -J -R $ISO_DIR" "Error creating iso fs"
+
+exec_and_log "$SCP $ISO_FILE $DST" "Error copying context ISO to $DST"
+
+rm -rf $ISO_DIR > /dev/null 2>&1
+
+exit 0
diff --git a/src/tm_mad/common/delete b/src/tm_mad/common/delete
new file mode 100755
index 0000000000..f0c68244a6
--- /dev/null
+++ b/src/tm_mad/common/delete
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+# -------------------------------------------------------------------------- #
+# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
+# #
+# 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 #
+# #
+# http://www.apache.org/licenses/LICENSE-2.0 #
+# #
+# 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. #
+#--------------------------------------------------------------------------- #
+
+# DELETE
+# - host is the target host to deploy the VM
+# - remote_system_ds is the path for the system datastore in the host
+
+DST=$1
+
+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
+
+. $TMCOMMON
+
+#-------------------------------------------------------------------------------
+# Return if deleting a disk, we will delete them when removing the
+# remote_system_ds directory for the VM (remotely)
+#-------------------------------------------------------------------------------
+DST_PATH=`arg_path $DST`
+DST_HOST=`arg_host $DST`
+
+if [ `is_disk $DST_PATH` -eq 1 ]; then
+ exit 0
+fi
+
+log "Deleting $DST_PATH"
+ssh_exec_and_log $DST_HOST "rm -rf $DST_PATH" "Error deleting $DST_PATH"
+
+exit 0
diff --git a/src/tm_mad/dummy/dummy.sh b/src/tm_mad/common/dummy.sh
similarity index 100%
rename from src/tm_mad/dummy/dummy.sh
rename to src/tm_mad/common/dummy.sh
diff --git a/src/tm_mad/common/mkimage b/src/tm_mad/common/mkimage
new file mode 100755
index 0000000000..3471e81410
--- /dev/null
+++ b/src/tm_mad/common/mkimage
@@ -0,0 +1,61 @@
+#!/bin/bash
+
+# -------------------------------------------------------------------------- #
+# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
+# #
+# 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 #
+# #
+# http://www.apache.org/licenses/LICENSE-2.0 #
+# #
+# 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. #
+#--------------------------------------------------------------------------- #
+
+# mkimage size format host:remote_system_ds/disk.i size
+# - size in MB of the image
+# - format for the image
+# - host is the target host to deploy the VM
+# - remote_system_ds is the path for the system datastore in the host
+
+SIZE=$1
+FSTYPE=$2
+DST=$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
+
+. $TMCOMMON
+
+#-------------------------------------------------------------------------------
+# Set dst path and dir
+#-------------------------------------------------------------------------------
+DST_PATH=`arg_path $DST`
+DST_HOST=`arg_host $DST`
+DST_DIR=`dirname $DST_PATH`
+
+ssh_make_path $DST_HOST $DST_DIR
+
+#-------------------------------------------------------------------------------
+# Make the new image (file-based)
+#-------------------------------------------------------------------------------
+MKFS_CMD=`mkfs_command $DST_PATH $FSTYPE`
+
+MKSCRIPT=$(cat <
-# - host is the target host to deploy the VM
-# - remote_system_ds is the path for the system datastore in the host
-
-DST=$1
-
-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
-
-. $TMCOMMON
-
-#-------------------------------------------------------------------------------
-# Set dst path and dir
-# Return if deleting a disk, we will delete them when removing the
-# remote_system_ds directory for the VM
-#-------------------------------------------------------------------------------
-
-DST_PATH=`arg_path $DST`
-
-if [ `is_disk $DST_PATH` -eq 1 ]; then
- exit 0
-fi
-
-set_ds_location
-
-REL_DST_PATH=${DST_PATH##"$DS_LOCATION/"}
-DST_PATH="$ONE_LOCAL_VAR/datastores/$REL_DST_PATH"
-
-log "Deleting $DST_PATH"
-exec_and_log "rm -rf $DST_PATH" "Error deleting $DST_PATH"
diff --git a/src/tm_mad/shared/delete b/src/tm_mad/shared/delete
new file mode 120000
index 0000000000..230e56774f
--- /dev/null
+++ b/src/tm_mad/shared/delete
@@ -0,0 +1 @@
+../common/delete
\ No newline at end of file
diff --git a/src/tm_mad/shared/ln b/src/tm_mad/shared/ln
index 480ea50def..4ecb76e42b 100755
--- a/src/tm_mad/shared/ln
+++ b/src/tm_mad/shared/ln
@@ -37,30 +37,22 @@ fi
# Set dst path and dir
#-------------------------------------------------------------------------------
SRC_PATH=`arg_path $SRC`
+SRC_PATH="../../${SRC_PATH##"$DS_DIR/"}"
+
DST_PATH=`arg_path $DST`
-
-set_ds_location
-
-REL_DST_PATH=${DST_PATH##"$DS_LOCATION/"}
-REL_SRC_PATH=${SRC_PATH##"$ONE_LOCAL_VAR/datastores/"}
-
-DST_PATH="$ONE_LOCAL_VAR/datastores/$REL_DST_PATH"
+DST_HOST=`arg_host $DST`
DST_DIR=`dirname $DST_PATH`
-if [ ! -d $DST_DIR ]; then
- log "Creating directory $DST_DIR"
- exec_and_log "mkdir -p $DST_DIR"
-fi
-
-DST_FILE=`basename $DST_PATH`
+ssh_make_path $DST_HOST $DST_DIR
#-------------------------------------------------------------------------------
# Link (ln) SRC into DST
#-------------------------------------------------------------------------------
-log "Linking $SRC_PATH in $DST_PATH"
+log "Linking $SRC_PATH in $DST"
-cd $DST_DIR
+ssh_exec_and_log $DST_HOST \
+ "cd $DST_DIR; ln -s $SRC_PATH $DST_PATH" \
+ "Error linking $SRC to $DST"
-exec_and_log "ln -s ../../$REL_SRC_PATH ./$DST_FILE" \
- "Error linking $SRC to $DST"
+exit 0
diff --git a/src/tm_mad/shared/mkimage b/src/tm_mad/shared/mkimage
deleted file mode 100755
index d651075dcc..0000000000
--- a/src/tm_mad/shared/mkimage
+++ /dev/null
@@ -1,65 +0,0 @@
-#!/bin/bash
-
-# -------------------------------------------------------------------------- #
-# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
-# #
-# 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 #
-# #
-# http://www.apache.org/licenses/LICENSE-2.0 #
-# #
-# 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. #
-#--------------------------------------------------------------------------- #
-
-# mkimage size format host:remote_system_ds/disk.i size
-# - size in MB of the image
-# - format for the image
-# - host is the target host to deploy the VM
-# - remote_system_ds is the path for the system datastore in the host
-
-SIZE=$1
-FSTYPE=$2
-DST=$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
-
-. $TMCOMMON
-
-#-------------------------------------------------------------------------------
-# Set dst path and dir
-#-------------------------------------------------------------------------------
-DST_PATH=`arg_path $DST`
-
-set_ds_location
-
-REL_DST_PATH=${DST_PATH##"$DS_LOCATION/"}
-DST_PATH="$ONE_LOCAL_VAR/datastores/$REL_DST_PATH"
-
-DST_DIR=`dirname $DST_PATH`
-
-if [ ! -d $DST_DIR ]; then
- log "Creating directory $DST_DIR"
- exec_and_log "mkdir -p $DST_DIR"
-fi
-
-#-------------------------------------------------------------------------------
-# Make the new image (file-based)
-#-------------------------------------------------------------------------------
-
-MKFS_CMD=`mkfs_command $DST_PATH $FSTYPE`
-
-exec_and_log "$DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M" \
- "Could not create image $DST_PATH"
-
-if [ -n "$MKFS_CMD" ]; then
- exec_and_log "$MKFS_CMD" "Unable to create filesystem $FSTYPE in $DST_PATH"
-fi
\ No newline at end of file
diff --git a/src/tm_mad/shared/mkimage b/src/tm_mad/shared/mkimage
new file mode 120000
index 0000000000..ad1bdd354d
--- /dev/null
+++ b/src/tm_mad/shared/mkimage
@@ -0,0 +1 @@
+../common/mkimage
\ No newline at end of file
diff --git a/src/tm_mad/shared/mkswap b/src/tm_mad/shared/mkswap
deleted file mode 100755
index 51ac4d96a1..0000000000
--- a/src/tm_mad/shared/mkswap
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/bin/bash
-
-# -------------------------------------------------------------------------- #
-# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
-# #
-# 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 #
-# #
-# http://www.apache.org/licenses/LICENSE-2.0 #
-# #
-# 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. #
-#--------------------------------------------------------------------------- #
-
-# mkswap size host:remote_system_ds/disk.i size
-# - size in MB of the image
-# - host is the target host to deploy the VM
-# - remote_system_ds is the path for the system datastore in the host
-
-SIZE=$1
-DST=$2
-
-CMD="`dirname $0`/mkimage $SIZE swap $DST"
-`$CMD`
diff --git a/src/tm_mad/shared/mkswap b/src/tm_mad/shared/mkswap
new file mode 120000
index 0000000000..3e0699b0f3
--- /dev/null
+++ b/src/tm_mad/shared/mkswap
@@ -0,0 +1 @@
+../common/mkswap
\ No newline at end of file
diff --git a/src/tm_mad/shared/mv b/src/tm_mad/shared/mv
index 2507dfb82d..300563f2ad 120000
--- a/src/tm_mad/shared/mv
+++ b/src/tm_mad/shared/mv
@@ -1 +1 @@
-../dummy/dummy.sh
\ No newline at end of file
+../common/dummy.sh
\ No newline at end of file
diff --git a/src/tm_mad/ssh/clone b/src/tm_mad/ssh/clone
index 10e1c28a96..ef7a0b6db0 100755
--- a/src/tm_mad/ssh/clone
+++ b/src/tm_mad/ssh/clone
@@ -16,46 +16,49 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
+# clone fe:SOURCE host:remote_system_ds/disk.i size
+# - 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
+
SRC=$1
DST=$2
if [ -z "${ONE_LOCATION}" ]; then
- TMCOMMON=/usr/lib/one/mads/tm_common.sh
+ TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
else
- TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh
+ TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
fi
. $TMCOMMON
+#-------------------------------------------------------------------------------
+# Set dst path and dir
+#-------------------------------------------------------------------------------
+
SRC_PATH=`arg_path $SRC`
DST_PATH=`arg_path $DST`
SRC_HOST=`arg_host $SRC`
DST_HOST=`arg_host $DST`
-
-log_debug "$1 $2"
-log_debug "DST: $DST_PATH"
-
DST_DIR=`dirname $DST_PATH`
-log "Creating directory $DST_DIR"
-exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR" \
- "Error creating directory $DST_DIR"
+ssh_make_path $DST_HOST $DST_DIR
+#-------------------------------------------------------------------------------
+# Copy files to the remote host
+#-------------------------------------------------------------------------------
case $SRC in
http://*)
log "Downloading $SRC"
- exec_and_log "$SSH $DST_HOST $WGET -O $DST_PATH $SRC" \
- "Error downloading $SRC"
+ RMT_CMD="$WGET -O $DST_PATH $SRC"
+ ssh_exec_and_log "$DST_HOST" "$RMT_CMD" "Error downloading $SRC"
;;
*)
- log "Cloning $SRC"
- exec_and_log "$SCP $SRC $DST" \
- "Error copying $SRC to $DST"
+ log "Cloning $SRC in $DST_PATH"
+ exec_and_log "$SCP $SRC $DST" "Error copying $SRC to $DST"
;;
esac
-
-exec_and_log "$SSH $DST_HOST chmod a+rw $DST_PATH"
-
diff --git a/src/tm_mad/ssh/context b/src/tm_mad/ssh/context
deleted file mode 100755
index 0827fdef9f..0000000000
--- a/src/tm_mad/ssh/context
+++ /dev/null
@@ -1,72 +0,0 @@
-#!/bin/bash
-
-# -------------------------------------------------------------------------- #
-# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
-# #
-# 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 #
-# #
-# http://www.apache.org/licenses/LICENSE-2.0 #
-# #
-# 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. #
-#--------------------------------------------------------------------------- #
-
-while (( "$#" )); do
- if [ "$#" == "1" ]; then
- DST=$1
- else
- SRC="$SRC $1"
- fi
- shift
-done
-
-
-if [ -z "${ONE_LOCATION}" ]; then
- TMCOMMON=/usr/lib/one/mads/tm_common.sh
-else
- TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh
-fi
-
-. $TMCOMMON
-
-
-DST_PATH=`arg_path $DST`
-DST_DIR=`dirname $DST_PATH`
-DST_FILE=`basename $DST_PATH`
-DST_HASH=`echo -n $DST | $MD5SUM | $AWK '{print $1}'`
-if [ -z "$ONE_LOCATION" ]; then
- TMP_DIR="/var/lib/one/$DST_HASH"
-else
- TMP_DIR="$ONE_LOCATION/var/$DST_HASH"
-fi
-ISO_DIR="$TMP_DIR/isofiles"
-
-
-exec_and_log "mkdir -p $ISO_DIR" \
- "Error creating directory $ISO_DIR"
-
-for f in $SRC; do
- case $f in
- http://*)
- exec_and_log "$WGET -P $ISO_DIR $f" \
- "Error downloading $f"
- ;;
-
- *)
- exec_and_log "cp -R $f $ISO_DIR" \
- "Error copying $f to $ISO_DIR"
- ;;
- esac
-done
-
-exec_and_log "$MKISOFS -o $TMP_DIR/$DST_FILE -J -R $ISO_DIR" \
- "Error creating iso fs"
-exec_and_log "$SCP $TMP_DIR/$DST_FILE $DST" \
- "Error copying $TMP_DIR/$DST_FILE to $DST"
-exec_and_log "rm -rf $TMP_DIR" \
- "Error deleting $TMP_DIR"
diff --git a/src/tm_mad/ssh/context b/src/tm_mad/ssh/context
new file mode 120000
index 0000000000..921312e950
--- /dev/null
+++ b/src/tm_mad/ssh/context
@@ -0,0 +1 @@
+../common/context
\ No newline at end of file
diff --git a/src/tm_mad/ssh/delete b/src/tm_mad/ssh/delete
deleted file mode 100755
index 9046c19414..0000000000
--- a/src/tm_mad/ssh/delete
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/bin/bash
-
-# -------------------------------------------------------------------------- #
-# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
-# #
-# 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 #
-# #
-# http://www.apache.org/licenses/LICENSE-2.0 #
-# #
-# 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. #
-#--------------------------------------------------------------------------- #
-
-SRC=$1
-DST=$2
-
-if [ -z "${ONE_LOCATION}" ]; then
- TMCOMMON=/usr/lib/one/mads/tm_common.sh
-else
- TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh
-fi
-
-. $TMCOMMON
-
-SRC_PATH=`arg_path $SRC`
-SRC_HOST=`arg_host $SRC`
-
-log "Deleting $SRC_PATH"
-exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH" \
- "Error deleting $SRC_PATH"
diff --git a/src/tm_mad/ssh/delete b/src/tm_mad/ssh/delete
new file mode 120000
index 0000000000..230e56774f
--- /dev/null
+++ b/src/tm_mad/ssh/delete
@@ -0,0 +1 @@
+../common/delete
\ No newline at end of file
diff --git a/src/tm_mad/ssh/ln b/src/tm_mad/ssh/ln
deleted file mode 100755
index 40d8e6f2e5..0000000000
--- a/src/tm_mad/ssh/ln
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/bash
-
-# -------------------------------------------------------------------------- #
-# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
-# #
-# 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 #
-# #
-# http://www.apache.org/licenses/LICENSE-2.0 #
-# #
-# 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. #
-#--------------------------------------------------------------------------- #
-
-SRC=$1
-DST=$2
-
-if [ -z "${ONE_LOCATION}" ]; then
- TMCOMMON=/usr/lib/one/mads/tm_common.sh
- TM_COMMANDS_LOCATION=/usr/lib/one/tm_commands/
-else
- TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh
- TM_COMMANDS_LOCATION=$ONE_LOCATION/lib/tm_commands/
-fi
-
-. $TMCOMMON
-
-log "Link $SRC_PATH (non shared dir, will clone)"
-#exec_and_log "ln -s $SRC_PATH $DST_PATH"
-exec $TM_COMMANDS_LOCATION/ssh/tm_clone.sh $SRC $DST
diff --git a/src/tm_mad/ssh/ln b/src/tm_mad/ssh/ln
new file mode 120000
index 0000000000..4197517ec0
--- /dev/null
+++ b/src/tm_mad/ssh/ln
@@ -0,0 +1 @@
+./clone
\ No newline at end of file
diff --git a/src/tm_mad/ssh/mkimage b/src/tm_mad/ssh/mkimage
deleted file mode 100755
index ace8017ca8..0000000000
--- a/src/tm_mad/ssh/mkimage
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/bin/bash
-
-# -------------------------------------------------------------------------- #
-# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
-# #
-# 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 #
-# #
-# http://www.apache.org/licenses/LICENSE-2.0 #
-# #
-# 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. #
-#--------------------------------------------------------------------------- #
-
-if [ -z "${ONE_LOCATION}" ]; then
- TMCOMMON=/usr/lib/one/mads/tm_common.sh
-else
- TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh
-fi
-
-. $TMCOMMON
-
-SIZE=$1
-FSTYPE=$2
-DST=$3
-
-DST_PATH=`arg_path $DST`
-DST_HOST=`arg_host $DST`
-DST_DIR=`dirname $DST_PATH`
-
-MKFS_CMD=`mkfs_command $DST_PATH $FSTYPE`
-
-exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR" \
- "Error creating directory $DST_DIR"
-exec_and_log "$SSH $DST_HOST $DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M" \
- "Could not create image $DST_PATH"
-exec_and_log "$SSH $DST_HOST $MKFS_CMD" \
- "Unable to create filesystem $FSTYPE in $DST_PATH"
-exec_and_log "$SSH $DST_HOST chmod a+rw $DST_PATH"
diff --git a/src/tm_mad/ssh/mkimage b/src/tm_mad/ssh/mkimage
new file mode 120000
index 0000000000..ad1bdd354d
--- /dev/null
+++ b/src/tm_mad/ssh/mkimage
@@ -0,0 +1 @@
+../common/mkimage
\ No newline at end of file
diff --git a/src/tm_mad/ssh/mkswap b/src/tm_mad/ssh/mkswap
deleted file mode 100755
index b2c9b80665..0000000000
--- a/src/tm_mad/ssh/mkswap
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/bin/bash
-
-# -------------------------------------------------------------------------- #
-# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
-# #
-# 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 #
-# #
-# http://www.apache.org/licenses/LICENSE-2.0 #
-# #
-# 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. #
-#--------------------------------------------------------------------------- #
-
-SIZE=$1
-DST=$2
-
-if [ -z "${ONE_LOCATION}" ]; then
- TMCOMMON=/usr/lib/one/mads/tm_common.sh
-else
- TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh
-fi
-
-. $TMCOMMON
-
-DST_PATH=`arg_path $DST`
-DST_HOST=`arg_host $DST`
-
-DST_DIR=`dirname $DST_PATH`
-
-log "Creating ${SIZE}Mb image in $DST_PATH"
-exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR"
-exec_and_log "$SSH $DST_HOST $DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M" \
- "Could not create image file $DST_PATH"
-
-log "Initializing swap space"
-exec_and_log "$SSH $DST_HOST $MKSWAP $DST_PATH" \
- "Could not create swap on $DST_PATH"
-
-exec_and_log "$SSH $DST_HOST chmod a+w $DST_PATH"
-
diff --git a/src/tm_mad/ssh/mkswap b/src/tm_mad/ssh/mkswap
new file mode 120000
index 0000000000..3e0699b0f3
--- /dev/null
+++ b/src/tm_mad/ssh/mkswap
@@ -0,0 +1 @@
+../common/mkswap
\ No newline at end of file
diff --git a/src/tm_mad/ssh/mv b/src/tm_mad/ssh/mv
index e7c7e2d668..61319e6612 100755
--- a/src/tm_mad/ssh/mv
+++ b/src/tm_mad/ssh/mv
@@ -16,17 +16,26 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
+# MV
+#
+# - hostX is the target host to deploy the VM
+# - system_ds is the path for the system datastore in the host
+
SRC=$1
DST=$2
if [ -z "${ONE_LOCATION}" ]; then
- TMCOMMON=/usr/lib/one/mads/tm_common.sh
+ TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
else
- TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh
+ TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
fi
. $TMCOMMON
+#-------------------------------------------------------------------------------
+# Return if moving a disk, we will move them when moving the whole system_ds
+# directory for the VM
+#-------------------------------------------------------------------------------
SRC_PATH=`arg_path $SRC`
DST_PATH=`arg_path $DST`
@@ -35,14 +44,21 @@ DST_HOST=`arg_host $DST`
DST_DIR=`dirname $DST_PATH`
-if full_src_and_dst_equal; then
- log "Not moving $SRC to $DST, they are the same path"
-else
- log "Moving $SRC_PATH"
- exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR" \
- "Unable to create directory $DST_DIR"
- exec_and_log "$SCP -r $SRC $DST" \
- "Could not copy $SRC to $DST"
- exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH"
+if [ `is_disk $DST_PATH` -eq 1 ]; then
+ exit 0
fi
+if [ "$SRC" == "$DST" ]; then
+ log "Not moving $SRC to $DST, they are the same path"
+ exit 0
+fi
+
+ssh_make_path $DST_HOST $DST_DIR
+
+log "Moving $SRC to $DST"
+
+exec_and_log "$SCP -r $SRC $DST" "Could not copy $SRC to $DST"
+
+exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH"
+
+exit 0
diff --git a/src/tm_mad/tm_common.sh b/src/tm_mad/tm_common.sh
index 07578a18b8..6626ef591f 100644
--- a/src/tm_mad/tm_common.sh
+++ b/src/tm_mad/tm_common.sh
@@ -22,9 +22,11 @@ export 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
ONE_SH=$ONE_LIB/sh
@@ -56,8 +58,10 @@ function arg_path
#Return the DATASTORE_LOCATION from OpenNebula configuration
function set_ds_location
{
- DS_LOCATION=`$GREP '^DATASTORE_LOCATION=' $ONE_LOCAL_VAR/config | cut -d= -f2`
- DS_LOCATION=`fix_dir_slashes $DS_LOCATION`
+ RMT_DS_DIR=`$GREP '^DATASTORE_LOCATION=' $ONE_LOCAL_VAR/config | cut -d= -f2`
+ RMT_DS_DIR=`fix_dir_slashes $DS_LOCATION`
+
+ export RMT_DS_DIR
}
#Return 1 if the first argument is a disk
@@ -70,4 +74,58 @@ function is_disk
else
echo "0"
fi
-}
\ No newline at end of file
+}
+
+# ------------------------------------------------------------------------------
+# Function to get hosts and paths from arguments
+# ------------------------------------------------------------------------------
+
+#This function executes $2 at $1 host and report error $3
+function ssh_exec_and_log
+{
+ SSH_EXEC_ERR=`$SSH $1 bash -s 2>&1 1>/dev/null <&1 1>/dev/null <