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

F #1371: vCenter live migration support (#1739)

This commit is contained in:
Sergio Semedi Barranco 2018-02-13 18:30:26 +01:00 committed by Tino Vázquez
parent 0543d3996d
commit 666b9da378
5 changed files with 75 additions and 75 deletions

View File

@ -1056,7 +1056,6 @@ 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 \

View File

@ -532,7 +532,7 @@ VM_MAD = [
IMPORTED_VMS_ACTIONS = "terminate, terminate-hard, hold, release, suspend,
resume, delete, reboot, reboot-hard, resched, unresched, poweroff,
poweroff-hard, disk-attach, disk-detach, nic-attach, nic-detach,
snap-create, snap-delete, migrate"
snap-create, snap-delete, migrate, live-migrate"
]
#-------------------------------------------------------------------------------

View File

@ -24,10 +24,10 @@ 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
MIGRATE_DRIVER=/var/lib/one/remotes/vmm/vcenter/migrate
else
TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
EXEC_DRIVER=$ONE_LOCATION/var/remotes/tm/vcenter/mv.rb
MIGRATE_DRIVER=$ONE_LOCATION/var/remotes/vmm/vcenter/migrate
fi
. $TMCOMMON
@ -45,6 +45,6 @@ if [ "$SRC" == "$DST" ]; then
exit 0
fi
ruby $EXEC_DRIVER $HOST_ORIG $HOST_DEST $VMID $DSID
ruby $MIGRATE_DRIVER $HOST_DEST $HOST_ORIG $VMID $DSID
exit 0

View File

@ -1,69 +0,0 @@
# ---------------------------------------------------------------------------- #
# 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

View File

@ -1 +0,0 @@
../common/not_supported.sh

View File

@ -0,0 +1,71 @@
#!/usr/bin/env ruby
# ---------------------------------------------------------------------------- #
# Copyright 2002-2018, 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'
vm_id = ARGV[-2]
src_host = ARGV[-3]
dst_host = ARGV[-4]
begin
one_client = OpenNebula::Client.new
pool = OpenNebula::HostPool.new(one_client)
pool.info
src_id = pool["/HOST_POOL/HOST[NAME='#{src_host}']/ID"].to_i
dst_id = pool["/HOST_POOL/HOST[NAME='#{dst_host}']/ID"].to_i
vi_client = VCenterDriver::VIClient.new_from_host(src_id)
# required one objects
vm = OpenNebula::VirtualMachine.new_with_id(vm_id, 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 #{vm_id}"\
"failed due to "\
"\"#{e.message}\"\n#{e.backtrace}"
STDERR.puts error_message(message)
exit -1
ensure
vi_client.close_connection if vi_client
end