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
This commit is contained in:
Zim Kalinowski 2018-03-22 09:59:46 +08:00 committed by ansibot
parent d5cd10c214
commit 9fb04d20e1

View file

@ -499,9 +499,13 @@ class AzureRMNetworkInterface(AzureRMModuleBase):
if changed: if changed:
if self.state == 'present': if self.state == 'present':
subnet = self.get_subnet(virtual_network_resource_group, virtual_network_name, self.subnet_name) subnet = self.network_models.SubResource(
if not subnet: '/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Network/virtualNetworks/{2}/subnets/{3}'.format(
self.fail('subnet {0} is not exist'.format(self.subnet_name)) self.subscription_id,
virtual_network_resource_group,
virtual_network_name,
self.subnet_name))
nic_ip_configurations = [ nic_ip_configurations = [
self.network_models.NetworkInterfaceIPConfiguration( self.network_models.NetworkInterfaceIPConfiguration(
private_ip_allocation_method=ip_config.get('private_ip_allocation_method'), private_ip_allocation_method=ip_config.get('private_ip_allocation_method'),
@ -573,13 +577,6 @@ class AzureRMNetworkInterface(AzureRMModuleBase):
except Exception as exc: except Exception as exc:
return None 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): def get_security_group(self, name):
self.log("Fetching security group {0}".format(name)) self.log("Fetching security group {0}".format(name))
try: try: