From cb707861c04f9ef24b1a9bd6c88e769f3bb33b7d Mon Sep 17 00:00:00 2001 From: micafer Date: Thu, 24 Mar 2022 08:34:06 +0100 Subject: [PATCH] Use PRIVATE_NET_MASKS in Azure conn --- IM/connectors/Azure.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/IM/connectors/Azure.py b/IM/connectors/Azure.py index 0eeda6cf2..0babbd9a6 100644 --- a/IM/connectors/Azure.py +++ b/IM/connectors/Azure.py @@ -25,6 +25,8 @@ from IM.VirtualMachine import VirtualMachine from .CloudConnector import CloudConnector from radl.radl import Feature +from netaddr import IPNetwork, IPAddress +from IM.config import Config try: from azure.mgmt.resource import ResourceManagementClient @@ -988,7 +990,12 @@ def setIPs(vm, network_profile, credentials, subscription_id): for ip in ip_conf: if ip.private_ip_address: - private_ips.append(ip.private_ip_address) + is_private = any([IPAddress(ip.private_ip_address) in IPNetwork(mask) + for mask in Config.PRIVATE_NET_MASKS]) + if is_private: + private_ips.append(ip.private_ip_address) + else: + public_ips.append(ip.private_ip_address) if ip.public_ip_address: name = " ".join(ip.public_ip_address.id.split('/')[-1:]) sub = "".join(ip.public_ip_address.id.split('/')[4])