diff --git a/install.sh b/install.sh index dd8d738412..b080fc0579 100755 --- a/install.sh +++ b/install.sh @@ -1027,6 +1027,7 @@ TM_DEV_FILES="src/tm_mad/dev/clone \ TM_VCENTER_FILES="src/tm_mad/vcenter/clone \ src/tm_mad/vcenter/ln \ src/tm_mad/vcenter/mv \ + src/tm_mad/vcenter/mv.rb \ src/tm_mad/vcenter/mvds \ src/tm_mad/vcenter/cpds \ src/tm_mad/vcenter/premigrate \ diff --git a/src/tm_mad/vcenter/mv b/src/tm_mad/vcenter/mv deleted file mode 120000 index 300563f2ad..0000000000 --- a/src/tm_mad/vcenter/mv +++ /dev/null @@ -1 +0,0 @@ -../common/dummy.sh \ No newline at end of file diff --git a/src/tm_mad/vcenter/mv b/src/tm_mad/vcenter/mv new file mode 100755 index 0000000000..f94528d574 --- /dev/null +++ b/src/tm_mad/vcenter/mv @@ -0,0 +1,50 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2017, OpenNebula Project, OpenNebula Systems # +# # +# 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 + +VMID=$3 +DSID=$4 + +if [ -z "${ONE_LOCATION}" ]; then + TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh + EXEC_DRIVER=/var/lib/one/remotes/tm/vcenter/mv.rb +else + TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh + EXEC_DRIVER=$ONE_LOCATION/var/remotes/tm/vcenter/mv.rb +fi + +. $TMCOMMON + +DST_PATH=`arg_path $DST` + +HOST_ORIG=`arg_host $SRC` +HOST_DEST=`arg_host $DST` + +if [ `is_disk $DST_PATH` -eq 1 ]; then + exit 0 +fi + +if [ "$SRC" == "$DST" ]; then + exit 0 +fi + +ruby $EXEC_DRIVER $HOST_ORIG $HOST_DEST $VMID $DSID + +exit 0 diff --git a/src/tm_mad/vcenter/mv.rb b/src/tm_mad/vcenter/mv.rb new file mode 100644 index 0000000000..057ba7c334 --- /dev/null +++ b/src/tm_mad/vcenter/mv.rb @@ -0,0 +1,69 @@ +# ---------------------------------------------------------------------------- # +# Copyright 2002-2017, OpenNebula Project, OpenNebula Systems # +# # +# 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. # +# ---------------------------------------------------------------------------- # + +ONE_LOCATION = ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION) + +if !ONE_LOCATION + RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION) +else + RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION) +end + +$: << RUBY_LIB_LOCATION +$: << File.dirname(__FILE__) + +require 'vcenter_driver' + +SRC = ARGV[0] +DST = ARGV[1] +WMID = ARGV[2] +DSID = ARGV[3] + +begin + one_client = OpenNebula::Client.new + + pool = OpenNebula::HostPool.new(one_client) + pool.info + + src_id = pool["/HOST_POOL/HOST[NAME='#{SRC}']/ID"].to_i + dst_id = pool["/HOST_POOL/HOST[NAME='#{DST}']/ID"].to_i + + vi_client = VCenterDriver::VIClient.new_from_host(src_id) + + # required one objects + vm = OpenNebula::VirtualMachine.new_with_id(WMID, one_client) + dst_host = OpenNebula::Host.new_with_id(dst_id, one_client) + + # get info + vm.info + dst_host.info + + # required vcenter objects + vc_vm = VCenterDriver::VirtualMachine.new_from_ref(vm["/VM/DEPLOY_ID"], vi_client) + dst_host = VCenterDriver::ClusterComputeResource.new_from_ref(dst_host["/HOST/TEMPLATE/VCENTER_CCR_REF"],vi_client).item + + config = {:cluster => dst_host } + vc_vm.migrate(config) + +rescue Exception => e + message = "Cannot migrate for VM #{WMID}"\ + "failed due to "\ + "\"#{e.message}\"\n#{e.backtrace}" + STDERR.puts error_message(message) + exit -1 +ensure + vi_client.close_connection if vi_client +end diff --git a/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb b/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb index 54a1f6a2db..77929c4228 100644 --- a/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb +++ b/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb @@ -2670,6 +2670,19 @@ class VirtualMachine < Template nil end + def migrate(config = {}) + raise "You need at least 1 parameter" if config.size == 0 + + begin + # retrieve host from DRS + resourcepool = config[:cluster].resourcePool + + @item.MigrateVM_Task(:pool=> resourcepool, :priority => "defaultPriority").wait_for_completion + rescue Exception => e + raise "Cannot migrate VM #{e.message}\n#{e.backtrace}" + end + end + ############################################################################ # actions ############################################################################