From 533b90f510e2228dbfeedcb2e4bea7cda72840f3 Mon Sep 17 00:00:00 2001 From: Matej Dujava Date: Thu, 17 Mar 2022 17:42:47 +0100 Subject: [PATCH] Calculate usage of network based on ipv4 subnets only --- osia/installer/clouds/openstack.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osia/installer/clouds/openstack.py b/osia/installer/clouds/openstack.py index 745ce4c..63efd5d 100644 --- a/osia/installer/clouds/openstack.py +++ b/osia/installer/clouds/openstack.py @@ -100,7 +100,10 @@ def _find_fit_network(osp_connection: Connection, results = {} for net_name in networks: net_avail = osp_connection.network.get_network_ip_availability(named_networks[net_name]) - results[net_name] = net_avail['total_ips'] / net_avail['used_ips'] + subnet_usage = [(subnet['total_ips'], subnet['used_ips']) + for subnet in net_avail.subnet_ip_availability if subnet['ip_version'] == 4] + total_ips, used_ips = [sum(i) for i in zip(*subnet_usage)] + results[net_name] = total_ips / used_ips result = _find_best_fit(results) return named_networks[result]['id'], result