|
1 | 1 | #
|
2 | 2 | # Project Ginger Base
|
3 | 3 | #
|
4 |
| -# Copyright IBM Corp, 2016 |
| 4 | +# Copyright IBM Corp, 2016-2017 |
5 | 5 | #
|
6 | 6 | # Code derived from Project Ginger and Kimchi
|
7 | 7 | #
|
@@ -141,7 +141,8 @@ def is_vlan(iface):
|
141 | 141 | bool: True if iface is a vlan, False otherwise.
|
142 | 142 |
|
143 | 143 | """
|
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() |
145 | 146 |
|
146 | 147 |
|
147 | 148 | def bridges():
|
@@ -295,7 +296,52 @@ def ports(bridge):
|
295 | 296 | if bridge in ovs_bridges():
|
296 | 297 | return ovs_bridge_ports(bridge)
|
297 | 298 |
|
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 |
299 | 345 |
|
300 | 346 |
|
301 | 347 | def is_brport(nic):
|
@@ -413,7 +459,13 @@ def get_vlan_device(vlan):
|
413 | 459 | if "Device:" in line:
|
414 | 460 | dummy, dev = line.split()
|
415 | 461 | 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 |
417 | 469 |
|
418 | 470 |
|
419 | 471 | def get_bridge_port_device(bridge):
|
|
0 commit comments