1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-23 22:50:09 +03:00

feature #1307: Add detach and attach disk actions for VMware

This commit is contained in:
Tino Vazquez 2012-06-15 17:25:26 +02:00
parent 214133ebdd
commit 1f12736fac
3 changed files with 138 additions and 0 deletions

View File

@ -0,0 +1,46 @@
#!/bin/sh
# -------------------------------------------------------------------------- #
# 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. #
#--------------------------------------------------------------------------- #
source $PWD/scripts_common_sh.sh
DEPLOYID="$1"
SOURCE="$2"
TARGET="$3"
CONTROLLER_NUMBER=0 # Only one controller at the moment (up to 16 devices)
DISK_NAME=`basename $SOURCE`
TEMP_PATH=`dirname $SOURCE`
VM_ID=`basename $TEMP_PATH`
TEMP_PATH=`dirname $TEMP_PATH`
DATASTORE=`basename $TEMP_PATH`
DISK_PATH="/vmfs/volumes/$DATASTORE/$VM_ID/$DISK_NAME/disk.vmdk"
# Get the VMware ID corresponding to the deploy_id
VMWAREID=`vim-cmd vmsvc/getallvms|grep $DEPLOYID|cut -d' ' -f 1`
TARGET_NUMBER=1
ATTACH_PARAMS="$VMWAREID $DISK_PATH $CONTROLLER_NUMBER $TARGET_NUMBER $DATASTORE"
exec_and_log "$SUDO vim-cmd vmsvc/device.diskaddexisting $ATTACH_PARAMS" \
"Could not attach $SOURCE ($TARGET) to $DOMAIN"

View File

@ -0,0 +1,33 @@
#!/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. #
#--------------------------------------------------------------------------- #
source $PWD/scripts_common_sh.sh
DEPLOYID="$1"
IMAGE_PATH="$2"
UNIT_NUMBER="$3"
CONTROLLER_NUMBER=0 # Only one controller at the moment (up to 16 devices)
# Get the VMware ID corresponding to the deploy_id
VMWAREID=`vim-cmd vmsvc/getallvms|grep $DEPLOYID|cut -d' ' -f 1`
DETACH_PARAMS="$VMWAREID $CONTROLLER_NUMBER $UNIT_NUMBER $IMAGE_PATH"
exec_and_log "$SUDO vim-cmd vmsvc/device.diskremove $DETACH_PARAMS" \
"Could not detach $TARGET from $DOMAIN"

View File

@ -0,0 +1,59 @@
# -------------------------------------------------------------------------- #
# 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. #
#--------------------------------------------------------------------------- #
error_message()
{
(
echo "ERROR MESSAGE --8<------"
echo "$1"
echo "ERROR MESSAGE ------>8--"
) 1>&2
}
log_function()
{
echo "$1: $SCRIPT_NAME: $2" 1>&2
}
log_error()
{
log_function "ERROR" "$1"
}
exec_and_log()
{
message=$2
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 "Error executing $1: $EXEC_LOG_ERR"
fi
exit $EXEC_LOG_RC
fi
}
WHICH_SUDO=`which sudo`
if [ ! -z "$WHICH_SUDO" -a -f "$WHICH_SUDO" ]; then
SUDO="sudo "
fi