diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 669307e776..a83f34faa0 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -154,7 +154,7 @@ IM_MAD = [ #IM_MAD = [ # name = "im_vmware", # executable = "one_im_sh", -# arguments = "-t 15 -r 0 vmware" ] +# arguments = "-c -t 15 -r 0 vmware" ] #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index fb3f1aa7f0..a8e132bc77 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -516,6 +516,8 @@ class ExecDriver < VirtualMachineDriver disk_xpath = "VM/TEMPLATE/DISK[DISK_ID='#{disk_id}']/TARGET" target = ensure_xpath(xml_data, id, action, disk_xpath) || return + target_index = target.downcase[-1..-1].unpack('c').first - 97 + action = VmmAction.new(self, id, :attach_disk, drv_message) steps = [ @@ -529,7 +531,12 @@ class ExecDriver < VirtualMachineDriver { :driver => :vmm, :action => :attach_disk, - :parameters => [:deploy_id, :disk_target_path, target] + :parameters => [ + :deploy_id, + :disk_target_path, + target, + target_index + ] } ] @@ -549,6 +556,8 @@ class ExecDriver < VirtualMachineDriver disk_xpath = "VM/TEMPLATE/DISK[DISK_ID='#{disk_id}']/TARGET" target = ensure_xpath(xml_data, id, action, disk_xpath) || return + target_index = target.downcase[-1..-1].unpack('c').first - 97 + action = VmmAction.new(self, id, :detach_disk, drv_message) steps = [ @@ -556,7 +565,12 @@ class ExecDriver < VirtualMachineDriver { :driver => :vmm, :action => :attach_disk, - :parameters => [:deploy_id, target] + :parameters => [ + :deploy_id, + :disk_target_path, + target, + target_index + ] }, # Perform an EPILOG on the disk { diff --git a/src/vmm_mad/remotes/kvm/attach_disk b/src/vmm_mad/remotes/kvm/attach_disk index 995c63c47b..99f63f8709 100755 --- a/src/vmm_mad/remotes/kvm/attach_disk +++ b/src/vmm_mad/remotes/kvm/attach_disk @@ -22,6 +22,7 @@ source $(dirname $0)/../../scripts_common.sh DOMAIN="$1" SOURCE="$2" TARGET="$3" +TARGET_INDEX="$4" ATTACH_PARAMS="--domain $DOMAIN --source $SOURCE --target $TARGET" diff --git a/src/vmm_mad/remotes/kvm/detach_disk b/src/vmm_mad/remotes/kvm/detach_disk index b270dfcd1a..9eac2eddb7 100755 --- a/src/vmm_mad/remotes/kvm/detach_disk +++ b/src/vmm_mad/remotes/kvm/detach_disk @@ -20,7 +20,9 @@ source $(dirname $0)/kvmrc source $(dirname $0)/../../scripts_common.sh DOMAIN="$1" -TARGET="$2" +SOURCE="$2" +TARGET="$3" +TARGET_INDEX="$4" DETACH_PARAMS="--domain $DOMAIN --target $TARGET" diff --git a/src/vmm_mad/remotes/vmware/attach_disk b/src/vmm_mad/remotes/vmware/attach_disk new file mode 100644 index 0000000000..ef8d722bc5 --- /dev/null +++ b/src/vmm_mad/remotes/vmware/attach_disk @@ -0,0 +1,45 @@ +#!/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" +TARGET_NUMBER="$4" +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` + +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" + + + diff --git a/src/vmm_mad/remotes/vmware/detach_disk b/src/vmm_mad/remotes/vmware/detach_disk new file mode 100644 index 0000000000..bd084e54d3 --- /dev/null +++ b/src/vmm_mad/remotes/vmware/detach_disk @@ -0,0 +1,34 @@ +#!/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="$3" +UNIT_NUMBER="$4" + +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" \ No newline at end of file diff --git a/src/vmm_mad/remotes/vmware/scripts_common_sh.sh b/src/vmm_mad/remotes/vmware/scripts_common_sh.sh new file mode 100644 index 0000000000..815bf3f479 --- /dev/null +++ b/src/vmm_mad/remotes/vmware/scripts_common_sh.sh @@ -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 \ No newline at end of file