From 07a44ec3f0f70e4aaae69c17c6f6bbb3daa255c3 Mon Sep 17 00:00:00 2001 From: Jan Orel Date: Fri, 6 Sep 2019 13:19:30 +0200 Subject: [PATCH] F #3613: brctl/ip-route2 backward compatible (#3654) --- src/vnm_mad/remotes/OpenNebulaNetwork.conf | 3 +- src/vnm_mad/remotes/lib/vlan.rb | 41 ++++++++++++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/vnm_mad/remotes/OpenNebulaNetwork.conf b/src/vnm_mad/remotes/OpenNebulaNetwork.conf index 624c3549a1..d7febe1d15 100644 --- a/src/vnm_mad/remotes/OpenNebulaNetwork.conf +++ b/src/vnm_mad/remotes/OpenNebulaNetwork.conf @@ -94,10 +94,9 @@ # # ip link add name type bridge stp_state 1 # -# :bridge_conf: +# :ip_bridge_conf: # :stp_state: on - # These options are set on the OvS bridge. For example, # this command will be trigged for the following option: # diff --git a/src/vnm_mad/remotes/lib/vlan.rb b/src/vnm_mad/remotes/lib/vlan.rb index 4b8c1ca86d..ddf0177795 100644 --- a/src/vnm_mad/remotes/lib/vlan.rb +++ b/src/vnm_mad/remotes/lib/vlan.rb @@ -155,10 +155,39 @@ module VNMMAD "link set #{@nic[:bridge]} up") end - # reads bridge_conf and return str with switches + # Reads config and return str with switches + # It reads both + # * brctl options from :bridge_conf section + # * ip-route2 bridge options from ip_bridge_conf section + # + # It tries to translate the options from brctl to ip-route2 format + # for the backward compatibility def list_bridge_options - bridge_options = '' - @nic[:bridge_conf].each do |option, value| + bridge_options = @nic[:conf][:bridge_conf] || Hash.new + ip_bridge_options = Hash.new + + # options transform table from brctl to ip-route2 + brctl_to_ipbridge = { + :setageing => :ageing_time, + :sethello => :hello_time, + :setmaxage => :max_age, + :stp => :stp_state, + :setbridgeprio => :priority, + :setfd => :forward_delay + } + + # translate bridge_options to ip_bridge_options + bridge_options.each do |brctl_opt, brctl_val| + next if ! brctl_to_ipbridge.include? brctl_opt + ip_bridge_options[brctl_to_ipbridge[brctl_opt]] = brctl_val + end + + # merge, conf section `:ip_bridge_conf` has higher priority + ip_bridge_options.merge!(@nic[:conf][:ip_bridge_conf]) \ + if @nic[:conf][:ip_bridge_conf] + + bridge_options_str = "" + ip_bridge_options.each do |option, value| case value when true value = '1' @@ -166,10 +195,10 @@ module VNMMAD value = '0' end - bridge_options << "#{option} #{value} " + bridge_options_str << "#{option} #{value} " end - - bridge_options.strip + + bridge_options_str.strip end # Get hypervisor bridges