mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
Add all actions to TM VMware
This commit is contained in:
parent
82eb4db593
commit
6fd4ee567d
@ -52,22 +52,21 @@ DST_PATH=`arg_path $DST`
|
||||
DST_HOST=`arg_host $DST`
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
|
||||
|
||||
IMAGE_DS_NAME=`basename $(dirname $SRC_PATH)`
|
||||
SYSTEM_DS_NAME=`basename $(dirname $(dirname $DST_PATH))`
|
||||
USERNAME=`echo $(cat $VMWARERC |grep ":username:"|cut -d":" -f 3)`
|
||||
PASSWORD=`echo $(cat $VMWARERC |grep ":password:"|cut -d":" -f 3)`
|
||||
|
||||
|
||||
DST_DIR_WITHOUT_DS_PATH="[$SYSTEM_DS_NAME] ${DST_PATH##"$DS_DIR/$SYSTEM_DS_NAME/"}"
|
||||
|
||||
if [ "$SSH" != "yes" ]; then
|
||||
USERNAME=`echo $(cat $VMWARERC |grep ":username:"|cut -d":" -f 3)`
|
||||
PASSWORD=`echo $(cat $VMWARERC |grep ":password:"|cut -d":" -f 3)`
|
||||
IMAGE_DS_NAME=`basename $(dirname $SRC_PATH)`
|
||||
SYSTEM_DS_NAME=`basename $(dirname $(dirname $DST_PATH))`
|
||||
DST_DIR_WITHOUT_DS_PATH="[$SYSTEM_DS_NAME] ${DST_PATH##"$DS_DIR/$SYSTEM_DS_NAME/"}"
|
||||
VI_PARAMS="--server $DST_HOST --username $USERNAME --password $PASSWORD"
|
||||
fi
|
||||
|
||||
if [ "$SSH" == "yes" ]; then
|
||||
ssh_make_path $DST_HOST $DST_PATH
|
||||
else
|
||||
# Two calls needed since vifs cannot do a mkdir -p
|
||||
vifs --server $DST_HOST --username $USERNAME --password $PASSWORD --mkdir "[$SYSTEM_DS_NAME] $VMID"
|
||||
vifs --server $DST_HOST --username $USERNAME --password $PASSWORD --mkdir "$DST_DIR_WITHOUT_DS_PATH"
|
||||
exec_and_log 'vifs $VI_PARAMS --mkdir "[$SYSTEM_DS_NAME] $VMID"' "Cannot create [$SYSTEM_DS_NAME] $VMID in $DST_HOST"
|
||||
exec_and_log 'vifs $VI_PARAMS --mkdir "$DST_DIR_WITHOUT_DS_PATH"' "Cannot create $DST_DIR_WITHOUT_DS_PATH in $DST_HOST"
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -92,7 +91,7 @@ EOF
|
||||
)
|
||||
ssh_exec_and_log $DST_HOST "$CLONESCRIPT" "Error cloning $SRC to $DST"
|
||||
else
|
||||
$VMKFSTOOLS --server $DST_HOST --username $USERNAME --password $PASSWORD -i "$SRC_DIR_WITHOUT_DS_PATH/disk.vmdk" -d thin "$DST_DIR_WITHOUT_DS_PATH/disk.vmdk"
|
||||
exec_and_log '$VMKFSTOOLS $VI_PARAMS -i "$SRC_DIR_WITHOUT_DS_PATH/disk.vmdk" -d thin "$DST_DIR_WITHOUT_DS_PATH/disk.vmdk"' "Error cloning $SRC to $DST"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
@ -1 +0,0 @@
|
||||
../common/context
|
97
src/tm_mad/vmware/context
Executable file
97
src/tm_mad/vmware/context
Executable file
@ -0,0 +1,97 @@
|
||||
#!/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 vmid 0
|
||||
# - 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
|
||||
# - vmid is the id of the VM
|
||||
# - 0 is the target datastore (system)
|
||||
|
||||
ARGV=("$@")
|
||||
|
||||
DS_ID="${ARGV[$(($#-1))]}"
|
||||
VM_ID="${ARGV[$(($#-2))]}"
|
||||
DST="${ARGV[$(($#-3))]}"
|
||||
SRC="${ARGV[@]:0:$(($#-3))}"
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
|
||||
VMWARERC=/etc/one/vmwarerc
|
||||
else
|
||||
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
|
||||
VMWARERC=$ONE_LOCATION/etc/vmwarerc
|
||||
fi
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
source $(dirname $0)/tm_vmwarerc
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set dst path and dirs
|
||||
#-------------------------------------------------------------------------------
|
||||
DST_PATH=`arg_path $DST`
|
||||
DST_HOST=`arg_host $DST`
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
|
||||
if [ "$SSH" != "yes" ]; then
|
||||
USERNAME=`echo $(cat $VMWARERC |grep ":username:"|cut -d":" -f 3)`
|
||||
PASSWORD=`echo $(cat $VMWARERC |grep ":password:"|cut -d":" -f 3)`
|
||||
VI_PARAMS="--server $DST_HOST --username $USERNAME --password $PASSWORD"
|
||||
fi
|
||||
|
||||
if [ "$SSH" == "yes" ]; then
|
||||
ssh_make_path $DST_HOST $DST_DIR
|
||||
else
|
||||
exec_and_log 'vifs $VI_PARAMS --mkdir "$DST_DIR"' "Cannot create $DST_DIR on %DST_HOST"
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# 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"
|
||||
|
||||
if [ "$SSH" == "yes" ]; then
|
||||
exec_and_log "$SCP $ISO_FILE $DST" "Error copying context ISO to $DST"
|
||||
else
|
||||
# Copies the iso file with .iso suffix, needed for VMware CDROMs
|
||||
exec_and_log 'vifs $VI_PARAMS -p $ISO_FILE $DST_PATH.iso' "Error copying context ISO to $DST"
|
||||
fi
|
||||
|
||||
rm -rf $ISO_DIR > /dev/null 2>&1
|
||||
|
||||
exit 0
|
@ -1 +0,0 @@
|
||||
../common/delete
|
63
src/tm_mad/vmware/delete
Executable file
63
src/tm_mad/vmware/delete
Executable file
@ -0,0 +1,63 @@
|
||||
#!/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/> vmid dsid
|
||||
# - host is the target host to deploy the VM
|
||||
# - remote_system_ds is the path for the system datastore in the host
|
||||
# - vmid is the id of the VM
|
||||
# - dsid is the target datastore (0 is the system datastore)
|
||||
|
||||
DST=$1
|
||||
|
||||
VMID=$2
|
||||
DSID=$3
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
|
||||
VMWARERC=/etc/one/vmwarerc
|
||||
else
|
||||
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
|
||||
VMWARERC=$ONE_LOCATION/etc/vmwarerc
|
||||
fi
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
source $(dirname $0)/tm_vmwarerc
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# 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"
|
||||
|
||||
if [ "$SSH" == "yes" ]; then
|
||||
ssh_exec_and_log $DST_HOST "rm -rf $DST_PATH" "Error deleting $DST_PATH"
|
||||
else
|
||||
USERNAME=`echo $(cat $VMWARERC |grep ":username:"|cut -d":" -f 3)`
|
||||
PASSWORD=`echo $(cat $VMWARERC |grep ":password:"|cut -d":" -f 3)`
|
||||
exec_and_log '$VMKFSTOOLS --server $DST_HOST --username $USERNAME --password $PASSWORD -U $DST_PATH' "Cannot delelete $DST"
|
||||
fi
|
||||
|
||||
exit 0
|
@ -1 +0,0 @@
|
||||
../shared/ln
|
79
src/tm_mad/vmware/ln
Executable file
79
src/tm_mad/vmware/ln
Executable file
@ -0,0 +1,79 @@
|
||||
#!/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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# ln fe:SOURCE host:remote_system_ds/disk.i vmid dsid
|
||||
# - 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
|
||||
# - vmid is the id of the VM
|
||||
# - dsid is the target datastore (0 is the system datastore)
|
||||
|
||||
SRC=$1
|
||||
DST=$2
|
||||
|
||||
VMID=$3
|
||||
DSID=$4
|
||||
|
||||
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
|
||||
#-------------------------------------------------------------------------------
|
||||
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`
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Link (ln) SRC into DST
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
if [ "$SSH" == "yes" ]; then
|
||||
ssh_make_path $DST_HOST $DST_PATH
|
||||
|
||||
# It's a folder, make links for all elements
|
||||
SRC_FOLDER_NAME=`basename $SRC_PATH`
|
||||
SRC_WITH_NO_FOLDER=`dirname $SRC_PATH`
|
||||
SRC_DS_NAME=`basename $SRC_WITH_NO_FOLDER`
|
||||
REL_SRC_PATH="../../../$SRC_DS_NAME/$SRC_FOLDER_NAME"
|
||||
|
||||
log "Link all files in $SRC_PATH to $DST_PATH"
|
||||
|
||||
LINK_SCRIPT=$(cat <<EOF
|
||||
for file in \$(cd $DST_DIR ; find $SRC_PATH -type f); do
|
||||
FNAME=\$(basename \$file)
|
||||
(cd $DST_PATH ; ln -sf $REL_SRC_PATH/\$FNAME $DST_PATH/$FNAME)
|
||||
done
|
||||
EOF
|
||||
)
|
||||
ssh_exec_and_log $DST_HOST "$LINK_SCRIPT" "Could not link dir files from source DS to system DS"
|
||||
else
|
||||
log "Cannot link files without SSH enabled on the ESX hosts"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
@ -1 +0,0 @@
|
||||
../shared/mkimage
|
88
src/tm_mad/vmware/mkimage
Executable file
88
src/tm_mad/vmware/mkimage
Executable file
@ -0,0 +1,88 @@
|
||||
#!/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 vmid dsid
|
||||
# - 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
|
||||
# - vmid is the id of the VM
|
||||
# - dsid is the target datastore (0 is the system datastore)
|
||||
|
||||
SIZE=$1
|
||||
FSTYPE=$2
|
||||
DST=$3
|
||||
|
||||
VMID=$4
|
||||
DSID=$5
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
|
||||
VMWARERC=/etc/one/vmwarerc
|
||||
else
|
||||
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
|
||||
VMWARERC=$ONE_LOCATION/etc/vmwarerc
|
||||
fi
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
source $(dirname $0)/tm_vmwarerc
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set dst path and dir
|
||||
#-------------------------------------------------------------------------------
|
||||
DST_PATH=`arg_path $DST`
|
||||
DST_HOST=`arg_host $DST`
|
||||
DST_DIR=`dirname $DST_PATH`
|
||||
|
||||
if [ "$SSH" != "yes" ]; then
|
||||
SYSTEM_DS_NAME=`basename $(dirname $(dirname $DST_PATH))`
|
||||
USERNAME=`echo $(cat $VMWARERC |grep ":username:"|cut -d":" -f 3)`
|
||||
PASSWORD=`echo $(cat $VMWARERC |grep ":password:"|cut -d":" -f 3)`
|
||||
DST_DIR_WITHOUT_DS_PATH="[$SYSTEM_DS_NAME] ${DST_PATH##"$DS_DIR/$SYSTEM_DS_NAME/"}"
|
||||
VI_PARAMS="--server $DST_HOST --username $USERNAME --password $PASSWORD"
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Make the new image (file-based)
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
log "Making filesystem of ${SIZE}M and type $FSTYPE at $DST"
|
||||
|
||||
if [ "$SSH" == "yes" ]; then
|
||||
ssh_make_path $DST_HOST $DST_PATH
|
||||
MKFS_CMD=`mkfs_command $DST_PATH $FSTYPE $SIZE`
|
||||
|
||||
MKSCRIPT=$(cat <<EOF
|
||||
export PATH=/usr/sbin:/sbin:\$PATH
|
||||
$MKFS_CMD
|
||||
EOF
|
||||
)
|
||||
|
||||
ssh_exec_and_log $DST_HOST "$MKSCRIPT" "Could not create image $DST_PATH"
|
||||
else
|
||||
# Two calls needed since vifs cannot do a mkdir -p
|
||||
exec_and_log 'vifs $VI_PARAMS --mkdir "[$SYSTEM_DS_NAME] $VMID"' "Cannot create [$SYSTEM_DS_NAME] $VMID "
|
||||
exec_and_log 'vifs $VI_PARAMS --mkdir "$DST_DIR_WITHOUT_DS_PATH"'
|
||||
|
||||
exec_and_log "VMWARE_DISK_TYPE=`echo $FSTYPE|cut -d'_' -f 2`"
|
||||
exec_and_log "$VMKFSTOOLS $VI_PARAMS -U $DST_PATH/disk.vmdk"
|
||||
exec_and_log "$VMKFSTOOLS -c ${SIZE}M -d ${VMWARE_DISK_TYPE} $DST/disk.vmdk"
|
||||
fi
|
||||
|
||||
exit 0
|
@ -32,12 +32,22 @@ DSID=$4
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
|
||||
VMWARERC=/etc/one/vmwarerc
|
||||
else
|
||||
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
|
||||
VMWARERC=$ONE_LOCATION/etc/vmwarerc
|
||||
fi
|
||||
|
||||
. $TMCOMMON
|
||||
|
||||
source $(dirname $0)/tm_vmwarerc
|
||||
|
||||
if [ "$SSH" != "yes" ]; then
|
||||
USERNAME=`echo $(cat $VMWARERC |grep ":username:"|cut -d":" -f 3)`
|
||||
PASSWORD=`echo $(cat $VMWARERC |grep ":password:"|cut -d":" -f 3)`
|
||||
VI_PARAMS="--server $DST_HOST --username $USERNAME --password $PASSWORD"
|
||||
fi
|
||||
|
||||
set_ds_location
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -53,6 +63,9 @@ SRC_HOST=`arg_host $SRC`
|
||||
#-------------------------------------------------------------------------------
|
||||
# Move the image back to the datastore
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
if [ "$SSH" == "yes" ]; then
|
||||
|
||||
MVSCRIPT=$(cat <<EOF
|
||||
SRC_READLN=eval "$READLINK -f $SRC_PATH"
|
||||
DST_READLN=eval "$READLINK -f $DST_PATH"
|
||||
@ -77,8 +90,11 @@ fi
|
||||
EOF
|
||||
)
|
||||
|
||||
log "Moving $SRC_PATH to datastore as $DST_PATH"
|
||||
log "Moving $SRC_PATH to datastore as $DST_PATH"
|
||||
|
||||
ssh_exec_and_log $SRC_HOST "$MVSCRIPT" "Could not move image $DST_PATH"
|
||||
ssh_exec_and_log $SRC_HOST "$MVSCRIPT" "Could not move image $DST_PATH"
|
||||
else
|
||||
exec_and_log "$VMKFSTOOLS $VI_PARAMS -i $SRC_PATH -d thin $DST_PATH" "Could not move image $DST_PATH"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user