mirror of
https://github.com/OpenNebula/one.git
synced 2025-04-01 06:50:25 +03:00
feature #4215: add reconfigure action to vcenter
This commit is contained in:
parent
70e5c9d652
commit
e10d705ff1
@ -779,7 +779,9 @@ VMM_EXEC_VCENTER_SCRIPTS="src/vmm_mad/remotes/vcenter/cancel \
|
||||
src/vmm_mad/remotes/vcenter/reset \
|
||||
src/vmm_mad/remotes/vcenter/save \
|
||||
src/vmm_mad/remotes/vcenter/poll \
|
||||
src/vmm_mad/remotes/vcenter/shutdown"
|
||||
src/vmm_mad/remotes/vcenter/shutdown \
|
||||
src/vmm_mad/remotes/vcenter/reconfigure \
|
||||
src/vmm_mad/remotes/vcenter/prereconfigure"
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# VMM Driver EC2 scripts, to be installed under $REMOTES_LOCATION/vmm/ec2
|
||||
|
@ -26,5 +26,6 @@ LOCAL_ACTIONS="deploy,shutdown,reboot,cancel,save,restore,migrate,poll,pre"
|
||||
LOCAL_ACTIONS="${LOCAL_ACTIONS},post,clean"
|
||||
LOCAL_ACTIONS="${LOCAL_ACTIONS},snapshotcreate,snapshotrevert,snapshotdelete"
|
||||
LOCAL_ACTIONS="${LOCAL_ACTIONS},attach_nic,detach_nic,reset"
|
||||
LOCAL_ACTIONS="${LOCAL_ACTIONS},prereconfigure,reconfigure"
|
||||
|
||||
exec $MAD_LOCATION/one_vmm_exec -l $LOCAL_ACTIONS $*
|
||||
|
20
src/vmm_mad/remotes/vcenter/prereconfigure
Executable file
20
src/vmm_mad/remotes/vcenter/prereconfigure
Executable file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2016, 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. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
exit(0)
|
||||
|
48
src/vmm_mad/remotes/vcenter/reconfigure
Executable file
48
src/vmm_mad/remotes/vcenter/reconfigure
Executable file
@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2016, 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'
|
||||
|
||||
deploy_id = ARGV[0]
|
||||
host = ARGV[-1]
|
||||
vm_id = ARGV[-2]
|
||||
|
||||
vm = OpenNebula::VirtualMachine.new_with_id(vm_id, OpenNebula::Client.new)
|
||||
vm.info
|
||||
|
||||
vm_xml = vm.to_xml
|
||||
|
||||
begin
|
||||
VCenterDriver::VCenterVm.reconfigure(deploy_id, host, vm_xml)
|
||||
rescue Exception => e
|
||||
STDERR.puts "Reconfiguration of VM #{deploy_id} on host #{host} failed " +
|
||||
"due to \"#{e.message}\""
|
||||
exit -1
|
||||
end
|
||||
|
@ -1105,6 +1105,34 @@ class VCenterVm
|
||||
vm.ReconfigVM_Task(:spec => spec).wait_for_completion
|
||||
end
|
||||
|
||||
############################################################################
|
||||
# Reconfigures a VM (context data)
|
||||
# @param deploy_id vcenter identifier of the VM
|
||||
# @param hostname name of the host (equals the vCenter cluster)
|
||||
# @param xml_text XML repsentation of the VM
|
||||
############################################################################
|
||||
def self.reconfigure(deploy_id, hostname, xml_text)
|
||||
hid = VIClient::translate_hostname(hostname)
|
||||
connection = VIClient.new(hid)
|
||||
vm = connection.find_vm_template(deploy_id)
|
||||
|
||||
xml = REXML::Document.new xml_text
|
||||
context = xml.root.elements["//TEMPLATE/CONTEXT"]
|
||||
|
||||
if context
|
||||
context_text = create_context(context)
|
||||
context_spec = {
|
||||
:extraConfig => [
|
||||
{ :key=>"guestinfo.opennebula.context",
|
||||
:value=> Base64.encode64(context_text) }
|
||||
]
|
||||
}
|
||||
|
||||
spec = RbVmomi::VIM.VirtualMachineConfigSpec(context_spec)
|
||||
vm.ReconfigVM_Task(:spec => spec).wait_for_completion
|
||||
end
|
||||
end
|
||||
|
||||
########################################################################
|
||||
# Initialize the vm monitor information
|
||||
########################################################################
|
||||
@ -1520,12 +1548,7 @@ private
|
||||
# Context section
|
||||
|
||||
if context
|
||||
# Remove <CONTEXT> (9) and </CONTEXT>\n (11)
|
||||
context_text = "# Context variables generated by OpenNebula\n"
|
||||
context.elements.each{|context_element|
|
||||
context_text += context_element.name + "='" +
|
||||
context_element.text.gsub("'", "\\'") + "'\n"
|
||||
}
|
||||
context_text = create_context(context)
|
||||
|
||||
# OneGate
|
||||
onegate_token_flag = xml.root.elements["/VM/TEMPLATE/CONTEXT/TOKEN"]
|
||||
@ -1636,5 +1659,16 @@ private
|
||||
|
||||
vm.ReconfigVM_Task(:spec => spec).wait_for_completion
|
||||
end
|
||||
|
||||
def self.create_context(context)
|
||||
# Remove <CONTEXT> (9) and </CONTEXT>\n (11)
|
||||
context_text = "# Context variables generated by OpenNebula\n"
|
||||
context.elements.each{|context_element|
|
||||
next if !context_element.text
|
||||
context_text += context_element.name + "='" +
|
||||
context_element.text.gsub("'", "\\'") + "'\n"
|
||||
}
|
||||
context_text
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user