Merge "Cache subnets when building nics_to_port_map" into stable/wallaby

This commit is contained in:
Zuul 2023-03-22 07:33:40 +00:00 committed by Gerrit Code Review
commit aa601a5d2e
1 changed files with 7 additions and 1 deletions

View File

@ -639,13 +639,19 @@ def get_source(instance):
checksum=image.get('checksum'))
_subnets_cache = dict()
def nics_to_port_map(nics, connection):
"""Build a port map from a metalsmith instance."""
port_map = {}
for nic in nics:
for ip in nic.fixed_ips:
net_name = getattr(nic.network, 'name', None) or nic.network.id
subnet = connection.network.get_subnet(ip['subnet_id'])
if not ip['subnet_id'] in _subnets_cache:
_subnets_cache[ip['subnet_id']] = (
connection.network.get_subnet(ip['subnet_id']))
subnet = _subnets_cache[ip['subnet_id']]
net_info = port_map.setdefault(
net_name, {'network': nic.network.to_dict(),
'fixed_ips': [], 'subnets': []})