diff --git a/install.sh b/install.sh index 0d3cf666df..5999a69ed9 100755 --- a/install.sh +++ b/install.sh @@ -803,10 +803,13 @@ TM_LVM_FILES="src/tm_mad/lvm/clone \ src/tm_mad/lvm/context" TM_VMWARE_FILES="src/tm_mad/vmware/clone \ + src/tm_mad/vmware/delete src/tm_mad/vmware/ln \ + src/tm_mad/vmware/mkswap \ + src/tm_mad/vmware/mkimage \ src/tm_mad/vmware/mv \ - src/tm_mad/vmware/functions.sh \ - src/tm_mad/vmware/context" + src/tm_mad/vmware/context \ + src/tm_mad/vmware/mvds" TM_ISCSI_FILES="src/tm_mad/iscsi/clone \ src/tm_mad/iscsi/ln \ diff --git a/src/mad/sh/scripts_common.sh b/src/mad/sh/scripts_common.sh index addd2ba59c..71acc0800b 100755 --- a/src/mad/sh/scripts_common.sh +++ b/src/mad/sh/scripts_common.sh @@ -40,6 +40,7 @@ SSH=ssh SUDO=sudo TAR=tar TGTADM=tgtadm +VMKFSTOOLS=/usr/sbin/vmkfstools WGET=wget if [ "x$(uname -s)" = "xLinux" ]; then @@ -180,6 +181,7 @@ function timeout_exec_and_log function mkfs_command { DST=$1 FSTYPE=${2:-ext3} + SIZE=${3:-0} # Specific options for different FS case "$FSTYPE" in @@ -202,6 +204,11 @@ function mkfs_command { echo "$MKSWAP $DST" return 0 ;; + "vmdk_*") + VMWARE_DISK_TYPE=`echo $FSTYPE|cut -d'_' -f 1` + echo "sudo $VMKFSTOOLS -U $DST/disk.vmdk ; sudo $VMKFSTOOLS -c ${SIZE}M -d ${VMWARE_DISK_TYPE} $DST_PATH/disk.vmdk" + return 0 + ;; *) OPTS="" ;; diff --git a/src/tm_mad/common/mkimage b/src/tm_mad/common/mkimage index 5f34e252ba..55e10ff27c 100755 --- a/src/tm_mad/common/mkimage +++ b/src/tm_mad/common/mkimage @@ -46,11 +46,15 @@ ssh_make_path $DST_HOST $DST_DIR #------------------------------------------------------------------------------- # Make the new image (file-based) #------------------------------------------------------------------------------- -MKFS_CMD=`mkfs_command $DST_PATH $FSTYPE` +MKFS_CMD=`mkfs_command $DST_PATH $FSTYPE $SIZE` +if ! echo "$FSTYPE"|grep -q ^vmdk; then + CREATE_IMAGE="$DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M" +fi + MKSCRIPT=$(cat < /dev/null 2>&1 - - if [ $? -eq 0 ]; then - bname=`basename $dst_path` - exec_and_log "ln -s $bname $dst_path/$bname.iso" \ - "Cannot link ISO file." - fi - fi -} - -#Creates the VM dir -function create_vmdir { - dst_path=$1 - - log "Creating directory `basename $dst_path`" - exec_and_log "mkdir -p $dst_path" - exec_and_log "chmod a+rw $dst_path" -} - -#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/} -} - -#Test if the source file is a disk (and not the image dir for the VM) -function is_disk { - echo $1 | grep -q 'disk\.[0-9]\+$' > /dev/null 2>&1 - echo $? -} - diff --git a/src/tm_mad/vmware/ln b/src/tm_mad/vmware/ln deleted file mode 100755 index 805e7de61c..0000000000 --- a/src/tm_mad/vmware/ln +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash - -# ---------------------------------------------------------------------------- # -# Copyright 2010-2011, C12G Labs S.L # -# # -# 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 -. "`dirname $0`/functions.sh" - -get_vmdir - -SRC_PATH=`arg_path $SRC` -DST_PATH=`arg_path $DST` - -fix_dst_path - -create_vmdir $DST_PATH - -# ---------------------------------------------------------------------------- # -# Link all files of the disk directory. Note that link paths needs to be # -# relative in order to be accessible from the vSphere Data Store # -# ---------------------------------------------------------------------------- # -REL_SRC_PATH=`make_relative $SRC_PATH $DST_PATH` - -log "Link all files in $SRC_PATH to $DST_PATH" - -for file in `find $SRC_PATH -type f`; do - FNAME=`basename $file` - exec_and_log "ln -sf $REL_SRC_PATH/$FNAME $DST_PATH/$FNAME" -done - -#Mark this disk persistent with a symlink for tm_mv and repo mv -exec_and_log "ln -sf ${REL_SRC_PATH#../../} $DST_PATH/.disk" - diff --git a/src/tm_mad/vmware/ln b/src/tm_mad/vmware/ln new file mode 120000 index 0000000000..2926cd697b --- /dev/null +++ b/src/tm_mad/vmware/ln @@ -0,0 +1 @@ +../shared/ln \ No newline at end of file diff --git a/src/tm_mad/vmware/mkimage b/src/tm_mad/vmware/mkimage new file mode 120000 index 0000000000..ad1bdd354d --- /dev/null +++ b/src/tm_mad/vmware/mkimage @@ -0,0 +1 @@ +../common/mkimage \ No newline at end of file diff --git a/src/tm_mad/vmware/mkswap b/src/tm_mad/vmware/mkswap new file mode 120000 index 0000000000..8cde16b79f --- /dev/null +++ b/src/tm_mad/vmware/mkswap @@ -0,0 +1 @@ +../dummy/mkswap \ No newline at end of file diff --git a/src/tm_mad/vmware/mv b/src/tm_mad/vmware/mv deleted file mode 100755 index a03071bf0e..0000000000 --- a/src/tm_mad/vmware/mv +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash - -# ---------------------------------------------------------------------------- # -# Copyright 2010-2011, C12G Labs S.L # -# # -# 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 -. "`dirname $0`/functions.sh" - -get_vmdir - -SRC_PATH=`arg_path $SRC` -DST_PATH=`arg_path $DST` - -fix_paths - -DST_PATH=`fix_dir_slashes "$DST_PATH"` -SRC_PATH=`fix_dir_slashes "$SRC_PATH"` - -if [ "$SRC_PATH" = "$DST_PATH" ]; then - log "Will not move, source and destination are equal" -elif [ -L "$SRC_PATH/.disk" ]; then - exec_and_log "mv $SRC_PATH/.disk $DST_PATH" -elif [ "`is_disk $SRC_PATH`" = "0" ] ; then - log "Moving $SRC_PATH" - exec_and_log "mv $SRC_PATH $DST_PATH" -elif [ -d $SRC_PATH ]; then - log "Will not move, it is not saving a VM disk image" -else - log "Moving $SRC_PATH" - exec_and_log "mv $SRC_PATH $DST_PATH" -fi diff --git a/src/tm_mad/vmware/mv b/src/tm_mad/vmware/mv new file mode 120000 index 0000000000..d7917aba94 --- /dev/null +++ b/src/tm_mad/vmware/mv @@ -0,0 +1 @@ +../shared/mv \ No newline at end of file diff --git a/src/tm_mad/vmware/mvds b/src/tm_mad/vmware/mvds new file mode 100755 index 0000000000..179c97200c --- /dev/null +++ b/src/tm_mad/vmware/mvds @@ -0,0 +1,73 @@ +#!/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. # +#--------------------------------------------------------------------------- # + +# mvds host:remote_system_ds/disk.i fe:SOURCE +# - 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=/var/lib/one/remotes/tm/tm_common.sh +else + TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh +fi + +. $TMCOMMON + +set_ds_location + +#------------------------------------------------------------------------------- +# Set dst path and dir +#------------------------------------------------------------------------------- +SRC_PATH=`arg_path $SRC`"/disk.vmdk" +DST_PATH=`arg_path $DST` + +DST_PATH="$RMT_DS_DIR/${DST_PATH##"$DS_DIR/"}/disk.vmdk" + +SRC_HOST=`arg_host $SRC` + +#------------------------------------------------------------------------------- +# Move the image back to the datastore +#------------------------------------------------------------------------------- +MVSCRIPT=$(cat <