mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
* F #1371: vm migrate to host accomplished * F #1371: vm migration works with DRS, added file to install.sh
This commit is contained in:
parent
de924cfba0
commit
b714116f64
@ -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 \
|
||||
|
@ -1 +0,0 @@
|
||||
../common/dummy.sh
|
50
src/tm_mad/vcenter/mv
Executable file
50
src/tm_mad/vcenter/mv
Executable file
@ -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
|
69
src/tm_mad/vcenter/mv.rb
Normal file
69
src/tm_mad/vcenter/mv.rb
Normal file
@ -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
|
@ -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
|
||||
############################################################################
|
||||
|
Loading…
x
Reference in New Issue
Block a user