]> git.proxmox.com Git - mirror_ifupdown2.git/commitdiff
ifupdownaddons: LinkUtils: bridge vlan show: add support for new iproute2 format
authorJulien Fortin <julien@cumulusnetworks.com>
Thu, 29 Nov 2018 08:27:02 +0000 (00:27 -0800)
committerJulien Fortin <julien@cumulusnetworks.com>
Thu, 13 Dec 2018 23:16:40 +0000 (15:16 -0800)
A newer iproute2 version changed the bridge vlan show output, ifupdown2 relies
on the previous format, we have the convert  data into old format:

{
   "vx-1002": [{
        "vlan": 1002,
        "flags": ["PVID", "Egress Untagged"]
    }],
    "vx-1004": [{
        "vlan": 1004,
        "flags": ["PVID", "Egress Untagged"]
    }]
 }

auto bridge
iface bridge
        bridge-vlan-aware yes
        bridge-ports vx-1000 vx-1001 vx-1002 vx-1003 vx-1004 hostbond3 hostbond4
        bridge-stp on
        bridge-vids 1000-1004
        bridge-pvid 1

auto vx-1002
iface vx-1002
        vxlan-id 1002
        bridge-access 1002
        vxlan-local-tunnelip 27.0.0.15
        bridge-learning off
        bridge-arp-nd-suppress on
        mstpctl-portbpdufilter yes
        mstpctl-bpduguard yes
        mtu 9152

auto hostbond4
iface hostbond4
        bond-slaves swp2 swp3
        bond-mode 802.3ad
        bond-min-links 1
        bond-lacp-rate 1
        mtu 9152
        alias Local Node/s TORS1 and Ports swp32s2 swp32s3 <==> Remote  Node/s HOSTS12 and Ports swp1 swp2
        bridge-pvid 1001

auto swp3
iface swp3
        link-speed 10000
        link-duplex full
        link-autoneg off

auto swp2
iface swp2
        link-speed 10000
        link-duplex full
        link-autoneg off

auto vx-1004
iface vx-1004
        vxlan-id 1004
        bridge-access 1004
        vxlan-local-tunnelip 27.0.0.15
        bridge-learning off
        bridge-arp-nd-suppress on
        mstpctl-portbpdufilter yes
        mstpctl-bpduguard yes
        mtu 9152

auto vx-1003
iface vx-1003
        vxlan-id 1003
        bridge-access 1003
        vxlan-local-tunnelip 27.0.0.15
        bridge-learning off
        bridge-arp-nd-suppress on
        mstpctl-portbpdufilter yes
        mstpctl-bpduguard yes
        mtu 9152

auto hostbond3
iface hostbond3
        bond-slaves swp5 swp6
        bond-mode 802.3ad
        bond-min-links 1
        bond-lacp-rate 1
        mtu 9152
        alias Local Node/s TORS1 and Ports swp32s0 swp32s1 <==> Remote  Node/s HOSTS11 and Ports swp1 swp2
        bridge-pvid 1000

auto swp6
iface swp6
        link-speed 10000
        link-duplex full
        link-autoneg off

auto swp5
iface swp5
        link-speed 10000
        link-duplex full
        link-autoneg off

auto vx-1001
iface vx-1001
        vxlan-id 1001
        bridge-access 1001
        vxlan-local-tunnelip 27.0.0.15
        bridge-learning off
        bridge-arp-nd-suppress on
        mstpctl-portbpdufilter yes
        mstpctl-bpduguard yes
        mtu 9152

auto vx-1000
iface vx-1000
        vxlan-id 1000
        bridge-access 1000
        vxlan-local-tunnelip 27.0.0.15
        bridge-learning off
        bridge-arp-nd-suppress on
        mstpctl-portbpdufilter yes
        mstpctl-bpduguard yes
        mtu 9152

Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
ifupdown2/ifupdownaddons/LinkUtils.py

index 0866b238ab434635974d26a9e3b6e03b4063f1ec..4b8bbc0e7d9740e7494067b9b03c0fd654e3ea8e 100644 (file)
@@ -1552,11 +1552,40 @@ class LinkUtils(utilsBase):
 
         if not bridgeout: return brvlaninfo
         try:
-            vlan_json_dict = json.loads(bridgeout, encoding="utf-8")
+            vlan_json = json.loads(bridgeout, encoding="utf-8")
         except Exception, e:
             self.logger.info('json loads failed with (%s)' % str(e))
             return {}
-        return vlan_json_dict
+
+        try:
+            if isinstance(vlan_json, list):
+                # newer iproute2 version changed the bridge vlan show output
+                # ifupdown2 relies on the previous format, we have the convert
+                # data into old format
+                bridge_port_vids = dict()
+
+                for intf in vlan_json:
+                    bridge_port_vids[intf["ifname"]] = intf["vlans"]
+
+                return bridge_port_vids
+            else:
+                # older iproute2 version have different ways to dump vlans
+                # ifupdown2 prefers the following syntax:
+                # {
+                #    "vx-1002": [{
+                #        "vlan": 1002,
+                #        "flags": ["PVID", "Egress Untagged"]
+                #    }
+                #    ],
+                #    "vx-1004": [{
+                #        "vlan": 1004,
+                #        "flags": ["PVID", "Egress Untagged"]
+                #    }]
+                # }
+                return vlan_json
+        except Exception as e:
+            self.logger.debug("bridge vlan show: Unknown json output: %s" % str(e))
+            return vlan_json
 
     @staticmethod
     def get_bridge_vlan_nojson():