From 1da7f89f5efc30286586e217872488e6102dd4ee Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 2 Mar 2012 01:15:19 +0100 Subject: [PATCH] feature #1112: clone, ln, mkimage, delete are now functional for tm_shared. Added none fs type for images --- src/mad/sh/scripts_common.sh | 5 ++++ src/tm_mad/shared/delete | 33 ++++++++++++++++------- src/tm_mad/shared/mkimage | 47 ++++++++++++++++++++++----------- src/tm_mad/shared/mv | 51 +----------------------------------- src/tm_mad/tm_common.sh | 14 +++++++++- 5 files changed, 74 insertions(+), 76 deletions(-) mode change 100755 => 120000 src/tm_mad/shared/mv diff --git a/src/mad/sh/scripts_common.sh b/src/mad/sh/scripts_common.sh index a3a4254b21..a1c5cee375 100755 --- a/src/mad/sh/scripts_common.sh +++ b/src/mad/sh/scripts_common.sh @@ -36,6 +36,7 @@ SED=sed SSH=ssh SUDO=sudo WGET=wget +GREP=grep # Used for log messages SCRIPT_NAME=`basename $0` @@ -182,6 +183,10 @@ function mkfs_command { "jfs") OPTS="-q" ;; + "none") + echo "" + return 0 + ;; *) OPTS="" ;; diff --git a/src/tm_mad/shared/delete b/src/tm_mad/shared/delete index 7e498293fe..34f23dc9da 100755 --- a/src/tm_mad/shared/delete +++ b/src/tm_mad/shared/delete @@ -16,23 +16,36 @@ # limitations under the License. # #--------------------------------------------------------------------------- # -SRC=$1 -DST=$2 +# 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=/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 -get_vmdir +#------------------------------------------------------------------------------- +# Set dst path and dir +# Return if deleting a disk, we will delete them when removing the +# remote_system_ds directory for the VM +#------------------------------------------------------------------------------- -SRC_PATH=`arg_path $SRC` +DST_PATH=`arg_path $DST` -fix_src_path +if [ `is_disk $DST_PATH` -eq 1 ]; then + exit 0 +fi -log "Deleting $SRC_PATH" -exec_and_log "rm -rf $SRC_PATH" \ - "Error deleting $SRC_PATH" +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/mkimage b/src/tm_mad/shared/mkimage index 8684a321ff..7f1ccc11cd 100755 --- a/src/tm_mad/shared/mkimage +++ b/src/tm_mad/shared/mkimage @@ -16,33 +16,50 @@ # 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 - -get_vmdir +# 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` -fix_dst_path +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 "mkdir -p $DST_DIR" \ - "Error creating directory $DST_DIR" exec_and_log "$DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M" \ "Could not create image $DST_PATH" -exec_and_log "$MKFS_CMD" \ - "Unable to create filesystem $FSTYPE in $DST_PATH" -exec_and_log "chmod a+rw $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/mv b/src/tm_mad/shared/mv deleted file mode 100755 index 4e23a36dc5..0000000000 --- a/src/tm_mad/shared/mv +++ /dev/null @@ -1,50 +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 - VAR_LOCATION=/var/lib/one/ -else - TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh - VAR_LOCATION=$ONE_LOCATION/var/ -fi - -. $TMCOMMON - -get_vmdir - -SRC_PATH=`arg_path $SRC` -DST_PATH=`arg_path $DST` - -fix_paths - -if [ "$SRC_PATH" == "$DST_PATH" ]; then - log "Will not move, source and destination are equal" -else - if [ -d "$SRC_PATH" ]; then - log "Will not move, is not saving image" - else - log "Moving $SRC_PATH" - exec_and_log "mv $SRC_PATH $DST_PATH" \ - "Could not move $SRC_PATH to $DST_PATH" - fi -fi - diff --git a/src/tm_mad/shared/mv b/src/tm_mad/shared/mv new file mode 120000 index 0000000000..2507dfb82d --- /dev/null +++ b/src/tm_mad/shared/mv @@ -0,0 +1 @@ +../dummy/dummy.sh \ No newline at end of file diff --git a/src/tm_mad/tm_common.sh b/src/tm_mad/tm_common.sh index 05a75111c9..07578a18b8 100644 --- a/src/tm_mad/tm_common.sh +++ b/src/tm_mad/tm_common.sh @@ -56,6 +56,18 @@ 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=`$GREP '^DATASTORE_LOCATION=' $ONE_LOCAL_VAR/config | cut -d= -f2` DS_LOCATION=`fix_dir_slashes $DS_LOCATION` } + +#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 +} \ No newline at end of file