Skip to content

Commit e07e51f

Browse files
alinefmdanielhb
authored andcommitted
Bug fix: Add Ubuntu support for bridged VLAN network
It is part of fix for kimchi-project/kimchi#1087 Signed-off-by: Aline Manera <[email protected]>
1 parent 564d843 commit e07e51f

File tree

1 file changed

+56
-4
lines changed

1 file changed

+56
-4
lines changed

netinfo.py

+56-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# Project Ginger Base
33
#
4-
# Copyright IBM Corp, 2016
4+
# Copyright IBM Corp, 2016-2017
55
#
66
# Code derived from Project Ginger and Kimchi
77
#
@@ -141,7 +141,8 @@ def is_vlan(iface):
141141
bool: True if iface is a vlan, False otherwise.
142142
143143
"""
144-
return encode_value(iface) in map(encode_value, vlans())
144+
return encode_value(iface) in map(encode_value, vlans()) or \
145+
'vlan_raw_device' in _parse_interfaces_file(iface).keys()
145146

146147

147148
def bridges():
@@ -295,7 +296,52 @@ def ports(bridge):
295296
if bridge in ovs_bridges():
296297
return ovs_bridge_ports(bridge)
297298

298-
return os.listdir(BRIDGE_PORTS % bridge)
299+
ports = []
300+
if os.path.exists(BRIDGE_PORTS % bridge):
301+
ports = os.listdir(BRIDGE_PORTS % bridge)
302+
303+
if len(ports) == 0:
304+
bridge_data = _parse_interfaces_file(bridge)
305+
return bridge_data.get('bridge_ports', [])
306+
else:
307+
return ports
308+
309+
310+
def _parse_interfaces_file(iface):
311+
ifaces = []
312+
313+
try:
314+
content = open('/etc/network/interfaces').readlines()
315+
for line in content:
316+
if line.startswith('iface'):
317+
ifaces.append({'iface': line.split()[1],
318+
'index': content.index(line)})
319+
except IOError:
320+
wok_log.debug("Unable to get bridge information from "
321+
"/etc/network/interfaces")
322+
return {}
323+
324+
index = next_index = None
325+
for data in ifaces:
326+
if data['iface'] == iface:
327+
index = data['index']
328+
next_elem = ifaces.index(data) + 1
329+
if next_elem > len(ifaces) - 1:
330+
next_index = len(content)
331+
else:
332+
next_index = ifaces[ifaces.index(data)+1]['index']
333+
break
334+
335+
if index is None or next_index is None:
336+
return {}
337+
338+
result = {}
339+
iface_data = content[index+1:next_index]
340+
for item in iface_data:
341+
data = item.split()
342+
result[data[0]] = data[1:]
343+
344+
return result
299345

300346

301347
def is_brport(nic):
@@ -413,7 +459,13 @@ def get_vlan_device(vlan):
413459
if "Device:" in line:
414460
dummy, dev = line.split()
415461
break
416-
return dev
462+
463+
if dev is None:
464+
dev_info = _parse_interfaces_file(vlan).get('vlan_raw_device', None)
465+
if dev_info:
466+
return dev_info[0]
467+
else:
468+
return dev
417469

418470

419471
def get_bridge_port_device(bridge):

0 commit comments

Comments
 (0)