B #1865: Allow vlan range notation in ovs (#1879)

(cherry picked from commit 23ebb7c2ee)
This commit is contained in:
Edouard Bourguignon authored and Ruben S. Montero committed 2018-04-13 16:34:01 +02:00
1 parent ace9a952a3
commit 87cc3396ef
1 file changed
+24 -2
+24 -2
View File
@@ -107,7 +107,11 @@ class OpenvSwitchVLAN < VNMMAD::VNMDriver
if range? range
ovs_vsctl_cmd = "#{command(:ovs_vsctl)} set Port #{@nic[:tap]}"
cmd = "#{ovs_vsctl_cmd} trunks=#{range}"
# Open vSwitch 2.7.0+ allows range intervals (x-y), but
# we need to support even older versions. We expand the
# intervals into the list of values [x,x+1,...,y-1,y],
# which should work for all.
cmd = "#{ovs_vsctl_cmd} trunks=#{expand_range(range)}"
run cmd
cmd = "#{ovs_vsctl_cmd} vlan_mode=native-untagged"
@@ -216,6 +220,24 @@ class OpenvSwitchVLAN < VNMMAD::VNMDriver
end
def range?(range)
!range.to_s.match(/^\d+(,\d+)*$/).nil?
!range.to_s.match(/^\d+([,-]\d+)*$/).nil?
end
def expand_range(range)
items = []
range.split(',').each do |i|
l, r = i.split('-')
if r.nil?
items << i
elsif r >= l
items.concat((l..r).to_a)
else
items.concat((r..l).to_a)
end
end
items.uniq.join(',')
end
end