mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-16 22:50:10 +03:00
Add vmware specific TM drivers
This commit is contained in:
parent
cb672e83d9
commit
3d1d8d7c57
@ -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,10 @@ 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=""
|
||||
;;
|
||||
|
@ -46,10 +46,14 @@ 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 <<EOF
|
||||
$DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M
|
||||
$CREATE_IMAGE
|
||||
$MKFS_CMD
|
||||
EOF
|
||||
)
|
||||
|
@ -1,48 +1,61 @@
|
||||
#!/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. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# -------------------------------------------------------------------------- #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# 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
|
||||
. "`dirname $0`/functions.sh"
|
||||
|
||||
get_vmdir
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
SRC_PATH=`arg_path $SRC`
|
||||
SRC_PATH="../../${SRC_PATH##"$DS_DIR/"}"
|
||||
|
||||
DST_PATH=`arg_path $DST`
|
||||
DST_HOST=`arg_host $DST`
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
|
||||
fix_paths
|
||||
ssh_make_path $DST_HOST $DST_DIR
|
||||
|
||||
log_debug "$1 $2"
|
||||
log_debug "DST: $DST_PATH"
|
||||
#-------------------------------------------------------------------------------
|
||||
# Clone (cp) SRC into DST
|
||||
#-------------------------------------------------------------------------------
|
||||
log "Cloning $SRC_PATH in $DST"
|
||||
|
||||
create_vmdir $DST_PATH
|
||||
CLONESCRIPT=$(cat <<EOF
|
||||
sudo $VMKFSTOOLS -U $DST_PATH/disk.vmdk
|
||||
sudo $VMKFSTOOLS -i $SRC_PATH/disk.vmdk -d thin $DST_PATH/disk.vmdk
|
||||
EOF
|
||||
)
|
||||
|
||||
log "Cloning $SRC_PATH"
|
||||
ssh_exec_and_log $DST_HOST "$CLONESCRIPT" "Error cloning $SRC to $DST"
|
||||
|
||||
exec_and_log "cp -r $SRC_PATH/* $DST_PATH" \
|
||||
"Error copying $SRC to $DST"
|
||||
|
||||
fix_iso $DST_PATH
|
||||
exit 0
|
||||
|
@ -1,63 +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. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
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
|
||||
. "`dirname $0`/functions.sh"
|
||||
|
||||
get_vmdir
|
||||
|
||||
DST_PATH=`arg_path $DST`
|
||||
|
||||
fix_dst_path
|
||||
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
ISO_DIR=$DST_DIR/isofiles
|
||||
|
||||
exec_and_log "mkdir -p $ISO_DIR"
|
||||
|
||||
for f in $SRC; do
|
||||
case $f in
|
||||
http://*)
|
||||
exec_and_log "$WGET -O $ISO_DIR $f"
|
||||
;;
|
||||
|
||||
*)
|
||||
exec_and_log "cp -R $f $ISO_DIR"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
exec_and_log "$MKISOFS -o $DST_PATH.iso -J -R $ISO_DIR"
|
||||
|
||||
exec_and_log "rm -rf $ISO_DIR"
|
1
src/tm_mad/vmware/context
Symbolic link
1
src/tm_mad/vmware/context
Symbolic link
@ -0,0 +1 @@
|
||||
../common/context
|
1
src/tm_mad/vmware/delete
Symbolic link
1
src/tm_mad/vmware/delete
Symbolic link
@ -0,0 +1 @@
|
||||
../common/delete
|
@ -1,61 +0,0 @@
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# 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. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
#Symlinks the dst_path to dst_path.iso if it is an ISO file
|
||||
function fix_iso {
|
||||
dst_path=$1
|
||||
|
||||
if [ -f $dst_path ]; then
|
||||
file -b $dst_path | grep "ISO 9660" > /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 $?
|
||||
}
|
||||
|
@ -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"
|
||||
|
1
src/tm_mad/vmware/ln
Symbolic link
1
src/tm_mad/vmware/ln
Symbolic link
@ -0,0 +1 @@
|
||||
../shared/ln
|
1
src/tm_mad/vmware/mkimage
Symbolic link
1
src/tm_mad/vmware/mkimage
Symbolic link
@ -0,0 +1 @@
|
||||
../common/mkimage
|
1
src/tm_mad/vmware/mkswap
Symbolic link
1
src/tm_mad/vmware/mkswap
Symbolic link
@ -0,0 +1 @@
|
||||
../dummy/mkswap
|
@ -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
|
1
src/tm_mad/vmware/mv
Symbolic link
1
src/tm_mad/vmware/mv
Symbolic link
@ -0,0 +1 @@
|
||||
../shared/mv
|
73
src/tm_mad/vmware/mvds
Executable file
73
src/tm_mad/vmware/mvds
Executable file
@ -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 <<EOF
|
||||
SRC_READLN=eval "$READLINK -f $SRC_PATH"
|
||||
DST_READLN=eval "$READLINK -f $DST_PATH"
|
||||
|
||||
if [ \( -L $SRC \) -a \( "$SRC_READLN" = "$DST_READLN" \) ] ; then
|
||||
echo "Not moving files to image repo, they are the same"
|
||||
else
|
||||
sudo $VMKFSTOOLS -i $SRC_PATH -d thin $DST_PATH
|
||||
fi
|
||||
|
||||
if [ -d $DST_PATH ]; then
|
||||
chmod 0770 $DST_PATH
|
||||
else
|
||||
chmod 0660 $DST_PATH
|
||||
fi
|
||||
EOF
|
||||
)
|
||||
|
||||
log "Moving $SRC_PATH to datastore as $DST_PATH"
|
||||
|
||||
ssh_exec_and_log $SRC_HOST "$MVSCRIPT" "Could not move image $DST_PATH"
|
||||
|
||||
exit 0
|
Loading…
x
Reference in New Issue
Block a user