From 76b2648336f20f85c5a2c5efedc0df9dd02c27de Mon Sep 17 00:00:00 2001 From: Kobi Samoray Date: Tue, 28 Jan 2020 20:41:58 +0200 Subject: [PATCH] Handle edges with different number of tunnels Edge appliances with different number of tunnels per vnic might exit within the system. That could happen due to a change in the config file after the system has been running for a while and edge appliances already exist. The router interface allocation logic should support this edge case. Change-Id: I47b72072a44ad40225714295aabcc5b7198eb71f --- vmware_nsx/db/nsxv_db.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/vmware_nsx/db/nsxv_db.py b/vmware_nsx/db/nsxv_db.py index 5077a6f5f9..acbef1a644 100644 --- a/vmware_nsx/db/nsxv_db.py +++ b/vmware_nsx/db/nsxv_db.py @@ -212,11 +212,18 @@ def clean_edge_vnic_binding(session, edge_id): def allocate_edge_vnic(session, edge_id, network_id): """Allocate an available edge vnic to network.""" + # get vnic count of specific edge + bindings = (session.query(nsxv_models.NsxvEdgeVnicBinding). + filter_by(edge_id=edge_id, + vnic_index=1).all()) + + vnic_tunnels_per_index = len(bindings) + with session.begin(subtransactions=True): bindings = (session.query(nsxv_models.NsxvEdgeVnicBinding). filter_by(edge_id=edge_id, network_id=None).all()) for binding in bindings: - if binding['tunnel_index'] % constants.MAX_TUNNEL_NUM == 1: + if binding['tunnel_index'] % vnic_tunnels_per_index == 1: binding['network_id'] = network_id session.add(binding) return binding