1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

feature #1112: TM shared and ssh. It should allow any combination of system datastore and images

datastore types (shared-shared, ssh-shared, shared-ssh, ssh-ssh)
This commit is contained in:
Ruben S. Montero 2012-03-03 03:39:21 +01:00
parent 193c3d2c94
commit 4dc9a34b79
29 changed files with 374 additions and 529 deletions

View File

@ -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

78
src/tm_mad/common/context Executable file
View File

@ -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

47
src/tm_mad/common/delete Executable file
View File

@ -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:remote_system_ds/disk.i|host:remote_system_ds/>
# - 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

61
src/tm_mad/common/mkimage Executable file
View File

@ -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 <<EOF
$DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M
$MKFS_CMD
EOF
)
log "Making filesystem of ${SIZE}M and type $FSTYPE at $DST"
ssh_exec_and_log $DST_HOST "$MKSCRIPT" "Could not create image $DST_PATH"
exit 0

30
src/tm_mad/common/mkswap Executable file
View File

@ -0,0 +1,30 @@
#!/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`
exit 0

View File

@ -1 +1 @@
dummy.sh
../common/dummy.sh

View File

@ -1 +1 @@
dummy.sh
../common/dummy.sh

View File

@ -1 +1 @@
dummy.sh
../common/dummy.sh

View File

@ -1 +1 @@
dummy.sh
../common/dummy.sh

View File

@ -1 +1 @@
dummy.sh
../common/dummy.sh

View File

@ -1 +1 @@
dummy.sh
../common/dummy.sh

View File

@ -1 +1 @@
dummy.sh
../common/dummy.sh

1
src/tm_mad/dummy/mvds Symbolic link
View File

@ -0,0 +1 @@
../common/dummy.sh

View File

@ -37,19 +37,13 @@ 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/"}
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
ssh_make_path $DST_HOST $DST_DIR
#-------------------------------------------------------------------------------
# Clone (cp) SRC into DST
@ -57,11 +51,17 @@ fi
case $SRC in
http://*)
log "Downloading $SRC into $DST_PATH"
exec_and_log "$WGET -O $DST_PATH $SRC" "Error downloading $SRC"
ssh_exec_and_log $DST_HOST \
"$WGET -O $DST_PATH $SRC" \
"Error downloading $SRC"
;;
*)
log "Cloning $SRC_PATH in $DST_PATH"
exec_and_log "cp -r $SRC_PATH $DST_PATH" "Error copying $SRC to $DST"
log "Cloning $SRC_PATH in $DST"
ssh_exec_and_log $DST_HOST \
"cd $DST_DIR; cp -r $SRC_PATH $DST_PATH" \
"Error copying $SRC to $DST"
;;
esac
exit 0

View File

@ -1,78 +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. #
#--------------------------------------------------------------------------- #
# 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`
set_ds_location
REL_DST_PATH=${DST_PATH##"$DS_LOCATION/"}
DST_PATH="$ONE_LOCAL_VAR/datastores/$REL_DST_PATH"
DST_DIR=`dirname $DST_PATH`
ISO_DIR=$DST_DIR/isofiles
if [ ! -d $DST_DIR ]; then
log "Creating directory $DST_DIR"
exec_and_log "mkdir -p $DST_DIR"
fi
exec_and_log "mkdir -p $ISO_DIR"
#-------------------------------------------------------------------------------
# Build the Context Block device
#-------------------------------------------------------------------------------
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 $DST_PATH -J -R $ISO_DIR" "Error creating iso fs"
exec_and_log "rm -rf $ISO_DIR"

1
src/tm_mad/shared/context Symbolic link
View File

@ -0,0 +1 @@
../common/context

View File

@ -1,51 +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. #
#--------------------------------------------------------------------------- #
# DELETE <host:remote_system_ds/disk.i|host:remote_system_ds/>
# - 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"

1
src/tm_mad/shared/delete Symbolic link
View File

@ -0,0 +1 @@
../common/delete

View File

@ -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

View File

@ -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

1
src/tm_mad/shared/mkimage Symbolic link
View File

@ -0,0 +1 @@
../common/mkimage

View File

@ -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`

1
src/tm_mad/shared/mkswap Symbolic link
View File

@ -0,0 +1 @@
../common/mkswap

View File

@ -1 +1 @@
../dummy/dummy.sh
../common/dummy.sh

View File

@ -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"

View File

@ -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"

1
src/tm_mad/ssh/context Symbolic link
View File

@ -0,0 +1 @@
../common/context

View File

@ -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"

1
src/tm_mad/ssh/delete Symbolic link
View File

@ -0,0 +1 @@
../common/delete

View File

@ -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

1
src/tm_mad/ssh/ln Symbolic link
View File

@ -0,0 +1 @@
./clone

View File

@ -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"

1
src/tm_mad/ssh/mkimage Symbolic link
View File

@ -0,0 +1 @@
../common/mkimage

View File

@ -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"

1
src/tm_mad/ssh/mkswap Symbolic link
View File

@ -0,0 +1 @@
../common/mkswap

View File

@ -16,17 +16,26 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
# MV <hostA:system_ds/disk.i|hostB:system_ds/disk.i>
# <hostA:system_ds/|hostB:system_ds/>
# - 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

View File

@ -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
}
}
# ------------------------------------------------------------------------------
# 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 <<EOF
$2
EOF`
SSH_EXEC_RC=$?
if [ $? -ne 0 ]; then
log_error "Command $2 failed"
log_error "$SSH_EXEC_ERR"
if [ -n "$3" ]; then
error_message "$3"
else
error_message "Error executing $2: $SSH_EXEC_ERR"
fi
exit $SSH_EXEC_RC
fi
}
#Creates path ($2) at $1
function ssh_make_path
{
SSH_EXEC_ERR=`$SSH $1 bash -s 2>&1 1>/dev/null <<EOF
if [ ! -d $2 ]; then
mkdir -p $2
fi
EOF`
SSH_EXEC_RC=$?
if [ $? -ne 0 ]; then
error_message "Error creating directory $2 at $1: $SSH_EXEC_ERR"
exit $SSH_EXEC_RC
fi
}
#Transform a system data store path from its remote location to the local one
#$1 remote path
function remote2local_path
{
if [ -z "$RMT_DS_DIR" ]; then
set_ds_location
fi
echo "$ONE_LOCAL_VAR/datastores/${1##"$RMT_DS_DIR/"}"
}