From 9fb04d20e170481d115a2eee1a5b0043ce6c71e9 Mon Sep 17 00:00:00 2001 From: Zim Kalinowski Date: Thu, 22 Mar 2018 09:59:46 +0800 Subject: [PATCH] azure_rm_networkinterface: don't query subnet as it's not necessary (#36826) * don't query subnet as it's not necessary * fixed pep8? * another attempt to fix pep8 indentation --- .../cloud/azure/azure_rm_networkinterface.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_networkinterface.py b/lib/ansible/modules/cloud/azure/azure_rm_networkinterface.py index 453ea3a54ca..7b8f50eff64 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_networkinterface.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_networkinterface.py @@ -499,9 +499,13 @@ class AzureRMNetworkInterface(AzureRMModuleBase): if changed: if self.state == 'present': - subnet = self.get_subnet(virtual_network_resource_group, virtual_network_name, self.subnet_name) - if not subnet: - self.fail('subnet {0} is not exist'.format(self.subnet_name)) + subnet = self.network_models.SubResource( + '/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Network/virtualNetworks/{2}/subnets/{3}'.format( + self.subscription_id, + virtual_network_resource_group, + virtual_network_name, + self.subnet_name)) + nic_ip_configurations = [ self.network_models.NetworkInterfaceIPConfiguration( private_ip_allocation_method=ip_config.get('private_ip_allocation_method'), @@ -573,13 +577,6 @@ class AzureRMNetworkInterface(AzureRMModuleBase): except Exception as exc: return None - def get_subnet(self, resource_group, vnet_name, subnet_name): - self.log("Fetching subnet {0} in virtual network {1}".format(subnet_name, vnet_name)) - try: - return self.network_client.subnets.get(resource_group, vnet_name, subnet_name) - except Exception as exc: - return None - def get_security_group(self, name): self.log("Fetching security group {0}".format(name)) try: