Merge "Handle edges with different number of tunnels" into stable/train

This commit is contained in:
Zuul 2020-02-03 09:35:21 +00:00 committed by Gerrit Code Review
commit f570725f3b
1 changed files with 8 additions and 1 deletions

View File

@ -212,11 +212,18 @@ def clean_edge_vnic_binding(session, edge_id):
def allocate_edge_vnic(session, edge_id, network_id): def allocate_edge_vnic(session, edge_id, network_id):
"""Allocate an available edge vnic to network.""" """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): with session.begin(subtransactions=True):
bindings = (session.query(nsxv_models.NsxvEdgeVnicBinding). bindings = (session.query(nsxv_models.NsxvEdgeVnicBinding).
filter_by(edge_id=edge_id, network_id=None).all()) filter_by(edge_id=edge_id, network_id=None).all())
for binding in bindings: 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 binding['network_id'] = network_id
session.add(binding) session.add(binding)
return binding return binding