mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
feature #863: the post scripts require the deploy_id
This commit is contained in:
parent
7e86e29e98
commit
d9d82dca99
@ -72,14 +72,16 @@ class VmmAction
|
||||
@vnm_src = VirtualNetworkDriver.new(@data[:net_drv],
|
||||
:local_actions => @vmm.options[:local_actions],
|
||||
:message => @xml_data,
|
||||
:ssh_stream => @ssh_src)
|
||||
:ssh_stream => @ssh_src,
|
||||
:extra_data => @data)
|
||||
|
||||
if @data[:dest_host] and !@data[:dest_host].empty?
|
||||
@ssh_dst = @vmm.get_ssh_stream(@data[:dest_host], @id)
|
||||
@vnm_dst = VirtualNetworkDriver.new(@data[:dest_driver],
|
||||
:local_actions => @vmm.options[:local_actions],
|
||||
:message => @xml_data,
|
||||
:ssh_stream => @ssh_dst)
|
||||
:ssh_stream => @ssh_dst,
|
||||
:extra_data => @data)
|
||||
end
|
||||
end
|
||||
|
||||
@ -115,7 +117,7 @@ class VmmAction
|
||||
# Executes a set of steps. If one step fails any recover action is performed
|
||||
# and the step execution breaks.
|
||||
# @param [Array] array of steps to be executed
|
||||
# @return [String, Hash] "SUCCESS/FAILURE" for the step set, and
|
||||
# @return [String, Hash] "SUCCESS/FAILURE" for the step set, and
|
||||
# information associated to each step (by :<action>_info). In case of
|
||||
# failure information is also in [:failed_info]
|
||||
def execute_steps(steps)
|
||||
@ -124,7 +126,7 @@ class VmmAction
|
||||
steps.each do |step|
|
||||
# Execute Step
|
||||
case step[:driver]
|
||||
when :vmm
|
||||
when :vmm
|
||||
if step[:destination]
|
||||
host = @data[:dest_host]
|
||||
ssh = @ssh_dst
|
||||
@ -134,7 +136,7 @@ class VmmAction
|
||||
end
|
||||
|
||||
result, info = @vmm.do_action(get_parameters(step[:parameters]),
|
||||
@id,
|
||||
@id,
|
||||
host,
|
||||
step[:action],
|
||||
:ssh_stream => ssh,
|
||||
@ -153,20 +155,21 @@ class VmmAction
|
||||
info = "No driver in #{step[:action]}"
|
||||
end
|
||||
|
||||
# Save the step info
|
||||
# Save the step info
|
||||
@data["#{step[:action]}_info".to_sym] = info
|
||||
@data[step[:save_info_as]] = info if step[:save_info_as]
|
||||
|
||||
# Roll back steps, store failed info and break steps
|
||||
if DriverExecHelper.failed?(result)
|
||||
if DriverExecHelper.failed?(result)
|
||||
execute_steps(@data[:fail_actions]) if @data[:fail_actions]
|
||||
@data[:failed_info] = info
|
||||
|
||||
@vmm.log(@id,
|
||||
@vmm.log(@id,
|
||||
"Failed to execute #{DRIVER_NAMES[step[:driver]]} " \
|
||||
"operation: #{step[:action]}.")
|
||||
break
|
||||
else
|
||||
@vmm.log(@id,
|
||||
@vmm.log(@id,
|
||||
"Sussecfully execute #{DRIVER_NAMES[step[:driver]]} " \
|
||||
"operation: #{step[:action]}.")
|
||||
end
|
||||
@ -217,7 +220,7 @@ class ExecDriver < VirtualMachineDriver
|
||||
@options={
|
||||
:threaded => true
|
||||
}.merge!(options)
|
||||
|
||||
|
||||
super("vmm/#{hypervisor}", @options)
|
||||
|
||||
@hypervisor = hypervisor
|
||||
@ -273,11 +276,12 @@ class ExecDriver < VirtualMachineDriver
|
||||
},
|
||||
# Boot the Virtual Machine
|
||||
{
|
||||
:driver => :vmm,
|
||||
:action => :deploy,
|
||||
:parameters => [dfile, :host],
|
||||
:stdin => domain
|
||||
},
|
||||
:driver => :vmm,
|
||||
:action => :deploy,
|
||||
:parameters => [dfile, :host],
|
||||
:stdin => domain,
|
||||
:save_info_as => :deploy_id
|
||||
},
|
||||
# Execute post-boot networking setup
|
||||
{
|
||||
:driver => :vnm,
|
||||
|
@ -31,6 +31,7 @@ class VirtualNetworkDriver
|
||||
@options = options
|
||||
@ssh_stream = options[:ssh_stream]
|
||||
@message = options[:message]
|
||||
@extra_data = options[:extra_data]
|
||||
|
||||
@vm_encoded = Base64.encode64(@message.elements['VM'].to_s).delete("\n")
|
||||
|
||||
@ -49,7 +50,9 @@ class VirtualNetworkDriver
|
||||
:stdin => nil,
|
||||
}.merge(ops)
|
||||
|
||||
cmd = action_command_line(aname, @vm_encoded)
|
||||
deploy_id=@extra_data[:deploy_id] || '-'
|
||||
|
||||
cmd = action_command_line(aname, "#{@vm_encoded} #{deploy_id}")
|
||||
|
||||
if action_is_local?(aname)
|
||||
execution = LocalCommand.run(cmd, log_method(id))
|
||||
@ -67,4 +70,4 @@ class VirtualNetworkDriver
|
||||
|
||||
result, info = get_info_from_execution(execution)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -18,8 +18,9 @@ require 'OpenNebulaNetwork'
|
||||
|
||||
class OpenNebulaHM < OpenNebulaNetwork
|
||||
XPATH_FILTER = "TEMPLATE/NIC[VLAN='YES']"
|
||||
def initialize(vm, hypervisor = nil)
|
||||
super(vm,XPATH_FILTER,hypervisor)
|
||||
|
||||
def initialize(vm, deploy_id = nil, hypervisor = nil)
|
||||
super(vm,XPATH_FILTER,deploy_id,hypervisor)
|
||||
@bridges = get_interfaces
|
||||
end
|
||||
|
||||
|
@ -22,6 +22,9 @@ $: << File.join(File.dirname(__FILE__), "..")
|
||||
require 'OpenNebulaNetwork'
|
||||
require 'Firewall'
|
||||
|
||||
fw = OpenNebulaFirewall.from_base64(ARGV[0])
|
||||
template64 = ARGV[0]
|
||||
deploy_id = ARGV[1]
|
||||
|
||||
fw = OpenNebulaFirewall.from_base64(template64, deploy_id)
|
||||
|
||||
fw.activate
|
||||
|
@ -17,9 +17,11 @@
|
||||
class OpenNebulaFirewall < OpenNebulaNetwork
|
||||
XPATH_FILTER = "TEMPLATE/NIC[ICMP|WHITE_PORTS_TCP|WHITE_PORTS_UDP|" <<
|
||||
"BLACK_PORTS_TCP|BLACK_PORTS_UDP]"
|
||||
def initialize(vm, hypervisor = nil)
|
||||
super(vm,XPATH_FILTER,hypervisor)
|
||||
|
||||
def initialize(vm, deploy_id = nil, hypervisor = nil)
|
||||
super(vm,XPATH_FILTER,deploy_id,hypervisor)
|
||||
end
|
||||
|
||||
def activate
|
||||
vm_id = @vm['ID']
|
||||
process do |nic|
|
||||
|
@ -43,14 +43,17 @@ COMMANDS = {
|
||||
}
|
||||
|
||||
class VM
|
||||
attr_accessor :nics, :vm_info
|
||||
attr_accessor :nics, :vm_info, :deploy_id
|
||||
|
||||
def initialize(vm_root, xpath_filter, hypervisor)
|
||||
def initialize(vm_root, xpath_filter, deploy_id, hypervisor)
|
||||
@vm_root = vm_root
|
||||
@xpath_filter = xpath_filter
|
||||
@deploy_id = deploy_id
|
||||
@hypervisor = hypervisor
|
||||
@vm_info = Hash.new
|
||||
|
||||
@deploy_id = nil if deploy_id == "-"
|
||||
|
||||
nics = Nics.new(@hypervisor)
|
||||
|
||||
@vm_root.elements.each(@xpath_filter) do |nic_element|
|
||||
@ -92,19 +95,19 @@ end
|
||||
class OpenNebulaNetwork
|
||||
attr_reader :hypervisor, :vm
|
||||
|
||||
def self.from_base64(vm_64, hypervisor=nil)
|
||||
def self.from_base64(vm_64, deploy_id = nil, hypervisor = nil)
|
||||
vm_xml = Base64::decode64(vm_64)
|
||||
self.new(vm_xml, hypervisor)
|
||||
self.new(vm_xml, deploy_id, hypervisor)
|
||||
end
|
||||
|
||||
def initialize(vm_tpl, xpath_filter, hypervisor=nil)
|
||||
def initialize(vm_tpl, xpath_filter, deploy_id = nil, hypervisor = nil)
|
||||
if !hypervisor
|
||||
@hypervisor = detect_hypervisor
|
||||
else
|
||||
@hypervisor = hypervisor
|
||||
end
|
||||
|
||||
@vm = VM.new(REXML::Document.new(vm_tpl).root, xpath_filter, @hypervisor)
|
||||
|
||||
@vm = VM.new(REXML::Document.new(vm_tpl).root, xpath_filter, deploy_id, @hypervisor)
|
||||
end
|
||||
|
||||
def process(&block)
|
||||
|
@ -39,7 +39,11 @@ class NicKVM < Hash
|
||||
end
|
||||
|
||||
def get_info(vm)
|
||||
deploy_id = vm['DEPLOY_ID']
|
||||
if vm.deploy_id
|
||||
deploy_id = vm.deploy_id
|
||||
else
|
||||
deploy_id = vm['DEPLOY_ID']
|
||||
end
|
||||
|
||||
if deploy_id and vm.vm_info[:dumpxml].nil?
|
||||
vm.vm_info[:dumpxml] = `#{COMMANDS[:virsh]} dumpxml #{deploy_id} \
|
||||
|
@ -18,8 +18,9 @@ require 'OpenNebulaNetwork'
|
||||
|
||||
class EbtablesVLAN < OpenNebulaNetwork
|
||||
XPATH_FILTER = "TEMPLATE/NIC[VLAN='YES']"
|
||||
def initialize(vm, hypervisor = nil)
|
||||
super(vm,XPATH_FILTER,hypervisor)
|
||||
|
||||
def initialize(vm, deploy_id = nil, hypervisor = nil)
|
||||
super(vm,XPATH_FILTER,deploy_id,hypervisor)
|
||||
end
|
||||
|
||||
def ebtables(rule)
|
||||
|
@ -22,10 +22,13 @@ $: << File.join(File.dirname(__FILE__), "..")
|
||||
require 'Ebtables'
|
||||
require 'Firewall'
|
||||
|
||||
onevlan = EbtablesVLAN.from_base64(ARGV[0])
|
||||
template64 = ARGV[0]
|
||||
deploy_id = ARGV[1]
|
||||
|
||||
onevlan = EbtablesVLAN.from_base64(template64, deploy_id)
|
||||
|
||||
onevlan.activate
|
||||
|
||||
fw = OpenNebulaFirewall.from_base64(ARGV[0])
|
||||
fw = OpenNebulaFirewall.from_base64(template64, deploy_id)
|
||||
|
||||
fw.activate
|
||||
|
@ -22,6 +22,9 @@ $: << File.join(File.dirname(__FILE__), "..")
|
||||
require 'OpenNebulaNetwork'
|
||||
require 'Firewall'
|
||||
|
||||
fw = OpenNebulaFirewall.from_base64(ARGV[0])
|
||||
template64 = ARGV[0]
|
||||
deploy_id = ARGV[1]
|
||||
|
||||
fw = OpenNebulaFirewall.from_base64(template64, deploy_id)
|
||||
|
||||
fw.activate
|
||||
|
@ -18,8 +18,9 @@ require 'OpenNebulaNetwork'
|
||||
|
||||
class OpenvSwitchVLAN < OpenNebulaNetwork
|
||||
XPATH_FILTER = "TEMPLATE/NIC[VLAN='YES']"
|
||||
def initialize(vm, hypervisor = nil)
|
||||
super(vm,XPATH_FILTER,hypervisor)
|
||||
|
||||
def initialize(vm, deploy_id = nil, hypervisor = nil)
|
||||
super(vm,XPATH_FILTER,deploy_id,hypervisor)
|
||||
end
|
||||
|
||||
def activate
|
||||
|
@ -22,11 +22,13 @@ $: << File.join(File.dirname(__FILE__), "..")
|
||||
require 'OpenvSwitch'
|
||||
require 'Firewall'
|
||||
|
||||
template64 = ARGV[0]
|
||||
deploy_id = ARGV[1]
|
||||
|
||||
onevlan = OpenvSwitchVLAN.from_base64(ARGV[0])
|
||||
onevlan = OpenvSwitchVLAN.from_base64(template64, deploy_id)
|
||||
|
||||
onevlan.activate
|
||||
|
||||
fw = OpenNebulaFirewall.from_base64(ARGV[0])
|
||||
fw = OpenNebulaFirewall.from_base64(template64, deploy_id)
|
||||
|
||||
fw.activate
|
||||
|
Loading…
x
Reference in New Issue
Block a user