1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

M #-: Support for NIC_ALIAS in elastic driver

This commit is contained in:
Ruben S. Montero 2021-04-01 19:52:31 +00:00
parent f5d98f6ef0
commit 3c5d407b2d
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
5 changed files with 82 additions and 10 deletions

View File

@ -974,18 +974,20 @@ class ExecDriver < VirtualMachineDriver
nic_alias = true
end
external = true if xml_data.elements["#{base_tmpl}/EXTERNAL"]
begin
source = xml_data.elements["#{base_tmpl}/BRIDGE"]
mac = xml_data.elements["#{base_tmpl}/MAC"]
target = xml_data.elements["#{base_tmpl}/TARGET"]
vn_mad = xml_data.elements["#{base_tmpl}/VN_MAD"]
external = xml_data.elements["#{base_tmpl}/EXTERNAL"]
source = source.text.strip
mac = mac.text.strip
target = target.text.strip
vn_mad = vn_mad.text.strip
external = !external.nil? || vn_mad == 'elastic'
rescue StandardError
send_message(action, RESULT[:failure], id,
'Missing VN_MAD, BRIDGE, TARGET or MAC in VM NIC')
@ -1095,11 +1097,14 @@ class ExecDriver < VirtualMachineDriver
nic_alias = true
end
external = true if xml_data.elements["#{base_tmpl}/EXTERNAL"]
begin
mac = xml_data.elements["#{base_tmpl}/MAC"]
mac = mac.text.strip
external = xml_data.elements["#{base_tmpl}/EXTERNAL"]
vn_mad = xml_data.elements["#{base_tmpl}/VN_MAD"].text.strip
external = !external.nil? || vn_mad == 'elastic'
rescue StandardError
send_message(action, RESULT[:failure], id,
"Error in #{ACTION[:detach_nic]}, MAC needed in NIC")

View File

@ -68,8 +68,9 @@ class ElasticDriver < VNMMAD::VNMDriver
provider = ElasticDriver.provider(@provider, @host)
attach_nic_id = @vm['TEMPLATE/NIC[ATTACH="YES"]/NIC_ID']
attach_nic_id ||= @vm['TEMPLATE/NIC_ALIAS[ATTACH="YES"]/NIC_ID']
process do |nic|
process_all do |nic|
next if attach_nic_id && attach_nic_id != nic[:nic_id]
cmds.add :ip, "route add #{nic[:ip]}/32 dev #{nic[:bridge]}"
@ -89,8 +90,9 @@ class ElasticDriver < VNMMAD::VNMDriver
provider = ElasticDriver.provider(@provider, @host)
attach_nic_id = @vm['TEMPLATE/NIC[ATTACH="YES"]/NIC_ID']
attach_nic_id ||= @vm['TEMPLATE/NIC_ALIAS[ATTACH="YES"]/NIC_ID']
process do |nic|
process_all do |nic|
next if attach_nic_id && attach_nic_id != nic[:nic_id]
cmds.add :ip, "route del #{nic[:ip]}/32 dev #{nic[:bridge]} | true"
@ -98,7 +100,7 @@ class ElasticDriver < VNMMAD::VNMDriver
provider.deactivate(cmds, nic) if provider.respond_to? :deactivate
next if nic[:conf][:keep_empty_bridge]
next if nic[:parent_nic] || nic[:conf][:keep_empty_bridge]
cmds.add :ip, "link delete #{nic[:bridge]} | true"
end
@ -117,7 +119,9 @@ class ElasticDriver < VNMMAD::VNMDriver
assigned = []
attach_nic_id = @vm['TEMPLATE/NIC[ATTACH="YES"]/NIC_ID']
rc = @vm.each_nic do |nic|
attach_nic_id ||= @vm['TEMPLATE/NIC_ALIAS[ATTACH="YES"]/NIC_ID']
rc = @vm.each_nic_all do |nic|
next if attach_nic_id && attach_nic_id != nic[:nic_id]
# pass aws_allocation_id if present
@ -144,7 +148,9 @@ class ElasticDriver < VNMMAD::VNMDriver
return if provider.nil?
attach_nic_id = @vm['TEMPLATE/NIC[ATTACH="YES"]/NIC_ID']
@vm.each_nic do |nic|
attach_nic_id ||= @vm['TEMPLATE/NIC_ALIAS[ATTACH="YES"]/NIC_ID']
@vm.each_nic_all do |nic|
next if attach_nic_id && attach_nic_id != nic[:nic_id]
provider.unassign(nic[:ip], nic[:external_ip])

View File

@ -41,7 +41,7 @@ module VNMMAD
########################################################################
# Hypervisor specific implementation of network interfaces. Each class
# implements the following interface:
# - get_info to populste the VM.vm_info Hash
# - get_info to populate the VM.vm_info Hash
# - get_tap to set the [:tap] attribute with the associated NIC
########################################################################

View File

@ -54,6 +54,26 @@ module VNMMAD
end
@nics = nics
nics_alias = VNMNetwork::Nics.new(hypervisor)
xpath_alias = xpath_filter.gsub('TEMPLATE/NIC',
'TEMPLATE/NIC_ALIAS')
@vm_root.elements.each(xpath_alias) do |nic_element|
nic = nics_alias.new_nic
nic_build_hash(nic_element, nic)
parent = @nics.select do |n|
n[:nic_id] == nic[:parent_id]
end
nic[:parent_nic] = parent.first
nics_alias << nic
end
@nics_alias = nics_alias
end
# Iterator on each NIC of the VM
@ -65,6 +85,31 @@ module VNMMAD
end
end
# Iterator on each NIC_ALIAS of the VM
def each_nic_alias(&block)
return if @nics_alias.nil?
@nics_alias.each do |the_nic|
block.call(the_nic)
end
end
def each_nic_all(&block)
all_nics = @nics
if all_nics
all_nics += @nics_alias
else
all_nics = @nics_alias
end
return if all_nics.nil?
all_nics.each do |the_nic|
block.call(the_nic)
end
end
# Access an XML Element of the VM
# @param element [String] element name
# @return [String] value of the element or nil if not found

View File

@ -80,6 +80,22 @@ module VNMMAD
end
end
# Executes the given block on each NIC
def process_all
@vm.each_nic do |nic|
add_nic_conf(nic)
add_bridge_conf(nic)
add_ovs_bridge_conf(nic)
add_ip_link_conf(nic)
yield(nic)
end
@vm.each_nic_alias do |nic|
yield(nic)
end
end
# Parse network configuration and add it to the nic
def add_nic_conf(nic)
return if nic[:conf] && nic[:conf].instance_of?(Hash)