From 949e2f06e532cd6a50197f54b87dd8f25921a147 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Wed, 17 Jan 2018 13:08:07 -0800 Subject: [PATCH] revert azure_rm model pinning (#35011) * reverts #33897/#34682 * revisit in 2.4.4/2.5.0 --- lib/ansible/module_utils/azure_rm_common.py | 42 ++----- .../cloud/azure/azure_rm_availabilityset.py | 7 +- .../cloud/azure/azure_rm_deployment.py | 16 ++- .../cloud/azure/azure_rm_loadbalancer.py | 32 ++++-- .../cloud/azure/azure_rm_managed_disk.py | 9 +- .../cloud/azure/azure_rm_networkinterface.py | 30 ++--- .../cloud/azure/azure_rm_publicipaddress.py | 9 +- .../cloud/azure/azure_rm_resourcegroup.py | 5 +- .../cloud/azure/azure_rm_securitygroup.py | 28 +++-- .../cloud/azure/azure_rm_storageaccount.py | 32 +++--- .../modules/cloud/azure/azure_rm_subnet.py | 17 +-- .../cloud/azure/azure_rm_virtualmachine.py | 103 ++++++++++-------- .../azure_rm_virtualmachine_extension.py | 5 +- .../azure/azure_rm_virtualmachine_scaleset.py | 66 +++++++---- .../cloud/azure/azure_rm_virtualnetwork.py | 13 ++- 15 files changed, 230 insertions(+), 184 deletions(-) diff --git a/lib/ansible/module_utils/azure_rm_common.py b/lib/ansible/module_utils/azure_rm_common.py index 9396c06213..d5fb4c9a34 100644 --- a/lib/ansible/module_utils/azure_rm_common.py +++ b/lib/ansible/module_utils/azure_rm_common.py @@ -98,6 +98,8 @@ try: from enum import Enum from msrestazure.azure_exceptions import CloudError from msrestazure import azure_cloud + from azure.mgmt.network.models import PublicIPAddress, NetworkSecurityGroup, SecurityRule, NetworkInterface, \ + NetworkInterfaceIPConfiguration, Subnet from azure.common.credentials import ServicePrincipalCredentials, UserPassCredentials from azure.mgmt.network.version import VERSION as network_client_version from azure.mgmt.storage.version import VERSION as storage_client_version @@ -603,7 +605,7 @@ class AzureRMModuleBase(object): self.check_provisioning_state(pip) return pip - params = self.network_models.PublicIPAddress( + params = PublicIPAddress( location=location, public_ip_allocation_method=allocation_method, ) @@ -643,7 +645,7 @@ class AzureRMModuleBase(object): self.check_provisioning_state(group) return group - parameters = self.network_models.NetworkSecurityGroup() + parameters = NetworkSecurityGroup() parameters.location = location if not open_ports: @@ -651,17 +653,17 @@ class AzureRMModuleBase(object): if os_type == 'Linux': # add an inbound SSH rule parameters.security_rules = [ - self.network_models.SecurityRule('Tcp', '*', '*', 'Allow', 'Inbound', description='Allow SSH Access', - source_port_range='*', destination_port_range='22', priority=100, name='SSH') + SecurityRule('Tcp', '*', '*', 'Allow', 'Inbound', description='Allow SSH Access', + source_port_range='*', destination_port_range='22', priority=100, name='SSH') ] parameters.location = location else: # for windows add inbound RDP and WinRM rules parameters.security_rules = [ - self.network_models.SecurityRule('Tcp', '*', '*', 'Allow', 'Inbound', description='Allow RDP port 3389', - source_port_range='*', destination_port_range='3389', priority=100, name='RDP01'), - self.network_models.SecurityRule('Tcp', '*', '*', 'Allow', 'Inbound', description='Allow WinRM HTTPS port 5986', - source_port_range='*', destination_port_range='5986', priority=101, name='WinRM01'), + SecurityRule('Tcp', '*', '*', 'Allow', 'Inbound', description='Allow RDP port 3389', + source_port_range='*', destination_port_range='3389', priority=100, name='RDP01'), + SecurityRule('Tcp', '*', '*', 'Allow', 'Inbound', description='Allow WinRM HTTPS port 5986', + source_port_range='*', destination_port_range='5986', priority=101, name='WinRM01'), ] else: # Open custom ports @@ -671,8 +673,8 @@ class AzureRMModuleBase(object): priority += 1 rule_name = "Rule_{0}".format(priority) parameters.security_rules.append( - self.network_models.SecurityRule('Tcp', '*', '*', 'Allow', 'Inbound', source_port_range='*', - destination_port_range=str(port), priority=priority, name=rule_name) + SecurityRule('Tcp', '*', '*', 'Allow', 'Inbound', source_port_range='*', + destination_port_range=str(port), priority=priority, name=rule_name) ) self.log('Creating default security group {0}'.format(security_group_name)) @@ -718,11 +720,6 @@ class AzureRMModuleBase(object): api_version='2017-10-01') return self._storage_client - @property - def storage_models(self): - self.log('Getting storage models...') - return StorageManagementClient.models("2017-10-01") - @property def network_client(self): self.log('Getting network client') @@ -732,11 +729,6 @@ class AzureRMModuleBase(object): api_version='2017-06-01') return self._network_client - @property - def network_models(self): - self.log("Getting network models...") - return NetworkManagementClient.models("2017-06-01") - @property def rm_client(self): self.log('Getting resource manager client') @@ -746,11 +738,6 @@ class AzureRMModuleBase(object): api_version='2017-05-10') return self._resource_client - @property - def rm_models(self): - self.log("Getting resource manager models") - return ResourceManagementClient.models("2017-05-10") - @property def compute_client(self): self.log('Getting compute client') @@ -760,11 +747,6 @@ class AzureRMModuleBase(object): api_version='2017-03-30') return self._compute_client - @property - def compute_models(self): - self.log("Getting compute models") - return ComputeManagementClient.models("2017-03-30") - @property def dns_client(self): self.log('Getting dns client') diff --git a/lib/ansible/modules/cloud/azure/azure_rm_availabilityset.py b/lib/ansible/modules/cloud/azure/azure_rm_availabilityset.py index 1c15106fe9..6854e6c327 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_availabilityset.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_availabilityset.py @@ -112,6 +112,9 @@ from ansible.module_utils.azure_rm_common import AzureRMModuleBase try: from msrestazure.azure_exceptions import CloudError + from azure.mgmt.compute.models import ( + AvailabilitySet, Sku + ) except ImportError: # This is handled in azure_rm_common pass @@ -260,10 +263,10 @@ class AzureRMAvailabilitySet(AzureRMModuleBase): ''' self.log("Creating availabilityset {0}".format(self.name)) try: - params_sku = self.compute_models.Sku( + params_sku = Sku( name=self.sku ) - params = self.compute_models.AvailabilitySet( + params = AvailabilitySet( location=self.location, tags=self.tags, platform_update_domain_count=self.platform_update_domain_count, diff --git a/lib/ansible/modules/cloud/azure/azure_rm_deployment.py b/lib/ansible/modules/cloud/azure/azure_rm_deployment.py index ef05bec083..00d8e0a97d 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_deployment.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_deployment.py @@ -379,6 +379,12 @@ except ImportError as exc: try: from itertools import chain from azure.common.exceptions import CloudError + from azure.mgmt.resource.resources.models import (DeploymentProperties, + ParametersLink, + TemplateLink, + Deployment, + ResourceGroup, + Dependency) from azure.mgmt.resource.resources import ResourceManagementClient from azure.mgmt.network import NetworkManagementClient @@ -476,21 +482,21 @@ class AzureRMDeploymentManager(AzureRMModuleBase): :return: """ - deploy_parameter = self.rm_models.DeploymentProperties(self.deployment_mode) + deploy_parameter = DeploymentProperties(self.deployment_mode) if not self.parameters_link: deploy_parameter.parameters = self.parameters else: - deploy_parameter.parameters_link = self.rm_models.ParametersLink( + deploy_parameter.parameters_link = ParametersLink( uri=self.parameters_link ) if not self.template_link: deploy_parameter.template = self.template else: - deploy_parameter.template_link = self.rm_models.TemplateLink( + deploy_parameter.template_link = TemplateLink( uri=self.template_link ) - params = self.rm_models.ResourceGroup(location=self.location, tags=self.tags) + params = ResourceGroup(location=self.location, tags=self.tags) try: self.rm_client.resource_groups.create_or_update(self.resource_group_name, params) @@ -621,7 +627,7 @@ class AzureRMDeploymentManager(AzureRMModuleBase): for dep in dependencies: if dep.resource_name not in tree: tree[dep.resource_name] = dict(dep=dep, children=dict()) - if isinstance(dep, self.rm_models.Dependency) and dep.depends_on is not None and len(dep.depends_on) > 0: + if isinstance(dep, Dependency) and dep.depends_on is not None and len(dep.depends_on) > 0: self._build_hierarchy(dep.depends_on, tree[dep.resource_name]['children']) if 'top' in tree: diff --git a/lib/ansible/modules/cloud/azure/azure_rm_loadbalancer.py b/lib/ansible/modules/cloud/azure/azure_rm_loadbalancer.py index deeb8fd607..0b606baa17 100755 --- a/lib/ansible/modules/cloud/azure/azure_rm_loadbalancer.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_loadbalancer.py @@ -184,6 +184,16 @@ from ansible.module_utils.azure_rm_common import AzureRMModuleBase try: from msrestazure.azure_exceptions import CloudError + from azure.mgmt.network.models import ( + LoadBalancer, + FrontendIPConfiguration, + BackendAddressPool, + Probe, + LoadBalancingRule, + SubResource, + InboundNatPool, + Subnet + ) except ImportError: # This is handled in azure_rm_common pass @@ -336,7 +346,7 @@ class AzureRMLoadBalancer(AzureRMModuleBase): if self.public_ip_address_name: pip = self.get_public_ip_address(self.public_ip_address_name) load_balancer_props['frontend_ip_configurations'] = [ - self.network_models.FrontendIPConfiguration( + FrontendIPConfiguration( name=frontend_ip_config_name, public_ip_address=pip ) @@ -386,7 +396,7 @@ class AzureRMLoadBalancer(AzureRMModuleBase): load_balancer_name=self.name, name=backend_address_pool_name ) - load_balancer_props['backend_address_pools'] = [self.network_models.BackendAddressPool(name=backend_address_pool_name)] + load_balancer_props['backend_address_pools'] = [BackendAddressPool(name=backend_address_pool_name)] probe_name = random_name('probe') prb_id = probe_id( @@ -398,7 +408,7 @@ class AzureRMLoadBalancer(AzureRMModuleBase): if self.probe_protocol: load_balancer_props['probes'] = [ - self.network_models.Probe( + Probe( name=probe_name, protocol=self.probe_protocol, port=self.probe_port, @@ -411,11 +421,11 @@ class AzureRMLoadBalancer(AzureRMModuleBase): load_balancing_rule_name = random_name('lbr') if self.protocol: load_balancer_props['load_balancing_rules'] = [ - self.network_models.LoadBalancingRule( + LoadBalancingRule( name=load_balancing_rule_name, - frontend_ip_configuration=self.network_models.SubResource(id=frontend_ip_config_id), - backend_address_pool=self.network_models.SubResource(id=backend_addr_pool_id), - probe=self.network_models.SubResource(id=prb_id), + frontend_ip_configuration=SubResource(id=frontend_ip_config_id), + backend_address_pool=SubResource(id=backend_addr_pool_id), + probe=SubResource(id=prb_id), protocol=self.protocol, load_distribution=self.load_distribution, frontend_port=self.frontend_port, @@ -428,9 +438,9 @@ class AzureRMLoadBalancer(AzureRMModuleBase): inbound_nat_pool_name = random_name('inp') if frontend_ip_config_id and self.natpool_protocol: load_balancer_props['inbound_nat_pools'] = [ - self.network_models.InboundNatPool( + InboundNatPool( name=inbound_nat_pool_name, - frontend_ip_configuration=self.network_models.Subnet(id=frontend_ip_config_id), + frontend_ip_configuration=Subnet(id=frontend_ip_config_id), protocol=self.natpool_protocol, frontend_port_range_start=self.natpool_frontend_port_start, frontend_port_range_end=self.natpool_frontend_port_end, @@ -441,7 +451,7 @@ class AzureRMLoadBalancer(AzureRMModuleBase): self.results['changed'] = changed self.results['state'] = ( results if results - else load_balancer_to_dict(self.network_models.LoadBalancer(**load_balancer_props)) + else load_balancer_to_dict(LoadBalancer(**load_balancer_props)) ) if self.check_mode: @@ -451,7 +461,7 @@ class AzureRMLoadBalancer(AzureRMModuleBase): self.network_client.load_balancers.create_or_update( resource_group_name=self.resource_group, load_balancer_name=self.name, - parameters=self.network_models.LoadBalancer(**load_balancer_props) + parameters=LoadBalancer(**load_balancer_props) ).wait() except CloudError as err: self.fail('Error creating load balancer {}'.format(err)) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_managed_disk.py b/lib/ansible/modules/cloud/azure/azure_rm_managed_disk.py index de89531f90..a22a7f2c47 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_managed_disk.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_managed_disk.py @@ -130,6 +130,7 @@ import re from ansible.module_utils.azure_rm_common import AzureRMModuleBase try: from msrestazure.azure_exceptions import CloudError + from azure.mgmt.compute.models import DiskCreateOption from azure.mgmt.compute.models import DiskSku except ImportError: # This is handled in azure_rm_common @@ -254,16 +255,16 @@ class AzureRMManagedDisk(AzureRMModuleBase): disk_params['location'] = self.location disk_params['tags'] = self.tags if self.storage_account_type: - storage_account_type = self.compute_models.DiskSku(self.storage_account_type) + storage_account_type = DiskSku(self.storage_account_type) disk_params['sku'] = storage_account_type disk_params['disk_size_gb'] = self.disk_size_gb # TODO: Add support for EncryptionSettings - creation_data['create_option'] = self.compute_models.DiskCreateOption.empty + creation_data['create_option'] = DiskCreateOption.empty if self.create_option == 'import': - creation_data['create_option'] = self.compute_models.DiskCreateOption.import_enum + creation_data['create_option'] = DiskCreateOption.import_enum creation_data['source_uri'] = self.source_uri elif self.create_option == 'copy': - creation_data['create_option'] = self.compute_models.DiskCreateOption.copy + creation_data['create_option'] = DiskCreateOption.copy creation_data['source_resource_id'] = self.source_resource_uri try: # CreationData cannot be changed after creation diff --git a/lib/ansible/modules/cloud/azure/azure_rm_networkinterface.py b/lib/ansible/modules/cloud/azure/azure_rm_networkinterface.py index fa62119cb0..9dc666a55c 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_networkinterface.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_networkinterface.py @@ -218,6 +218,8 @@ state: try: from msrestazure.azure_exceptions import CloudError + from azure.mgmt.network.models import NetworkInterface, NetworkInterfaceIPConfiguration, Subnet, \ + PublicIPAddress, NetworkSecurityGroup except ImportError: # This is handled in azure_rm_common pass @@ -442,37 +444,37 @@ class AzureRMNetworkInterface(AzureRMModuleBase): pip = self.create_default_pip(self.resource_group, self.location, self.name, self.public_ip_allocation_method) - nic = self.network_models.NetworkInterface( + nic = NetworkInterface( location=self.location, tags=self.tags, ip_configurations=[ - self.network_models.NetworkInterfaceIPConfiguration( + NetworkInterfaceIPConfiguration( private_ip_allocation_method=self.private_ip_allocation_method, ) ] ) #nic.name = self.name - nic.ip_configurations[0].subnet = self.network_models.Subnet(id=subnet.id) + nic.ip_configurations[0].subnet = Subnet(id=subnet.id) nic.ip_configurations[0].name = 'default' - nic.network_security_group = self.network_models.NetworkSecurityGroup(id=nsg.id, - location=nsg.location, - resource_guid=nsg.resource_guid) + nic.network_security_group = NetworkSecurityGroup(id=nsg.id, + location=nsg.location, + resource_guid=nsg.resource_guid) if self.private_ip_address: nic.ip_configurations[0].private_ip_address = self.private_ip_address if pip: - nic.ip_configurations[0].public_ip_address = self.network_models.PublicIPAddress( + nic.ip_configurations[0].public_ip_address = PublicIPAddress( id=pip.id, location=pip.location, resource_guid=pip.resource_guid) else: self.log("Updating network interface {0}.".format(self.name)) - nic = self.network_models.NetworkInterface( + nic = NetworkInterface( id=results['id'], location=results['location'], tags=results['tags'], ip_configurations=[ - self.network_models.NetworkInterfaceIPConfiguration( + NetworkInterfaceIPConfiguration( private_ip_allocation_method= results['ip_configuration']['private_ip_allocation_method'] ) @@ -480,7 +482,7 @@ class AzureRMNetworkInterface(AzureRMModuleBase): ) subnet = self.get_subnet(results['ip_configuration']['subnet']['virtual_network_name'], results['ip_configuration']['subnet']['name']) - nic.ip_configurations[0].subnet = self.network_models.Subnet(id=subnet.id) + nic.ip_configurations[0].subnet = Subnet(id=subnet.id) nic.ip_configurations[0].name = results['ip_configuration']['name'] #nic.name = name=results['name'], @@ -490,7 +492,7 @@ class AzureRMNetworkInterface(AzureRMModuleBase): if results['ip_configuration']['public_ip_address'].get('id'): pip = \ self.get_public_ip_address(results['ip_configuration']['public_ip_address']['name']) - nic.ip_configurations[0].public_ip_address = self.network_models.PublicIPAddress( + nic.ip_configurations[0].public_ip_address = PublicIPAddress( id=pip.id, location=pip.location, resource_guid=pip.resource_guid) @@ -498,9 +500,9 @@ class AzureRMNetworkInterface(AzureRMModuleBase): if results['network_security_group'].get('id'): nsg = self.get_security_group(results['network_security_group']['name']) - nic.network_security_group = self.network_models.NetworkSecurityGroup(id=nsg.id, - location=nsg.location, - resource_guid=nsg.resource_guid) + nic.network_security_group = NetworkSecurityGroup(id=nsg.id, + location=nsg.location, + resource_guid=nsg.resource_guid) # See what actually gets sent to the API request = self.serialize_obj(nic, 'NetworkInterface') diff --git a/lib/ansible/modules/cloud/azure/azure_rm_publicipaddress.py b/lib/ansible/modules/cloud/azure/azure_rm_publicipaddress.py index 4269f3cf79..cfaa21dea0 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_publicipaddress.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_publicipaddress.py @@ -114,6 +114,7 @@ from ansible.module_utils.azure_rm_common import AzureRMModuleBase try: from msrestazure.azure_exceptions import CloudError + from azure.mgmt.network.models import PublicIPAddress, PublicIPAddressDnsSettings except ImportError: # This is handled in azure_rm_common pass @@ -222,25 +223,25 @@ class AzureRMPublicIPAddress(AzureRMModuleBase): if self.state == 'present': if not pip: self.log("Create new Public IP {0}".format(self.name)) - pip = self.network_models.PublicIPAddress( + pip = PublicIPAddress( location=self.location, public_ip_allocation_method=self.allocation_method, ) if self.tags: pip.tags = self.tags if self.domain_name: - pip.dns_settings = self.network_models.PublicIPAddressDnsSettings( + pip.dns_settings = PublicIPAddressDnsSettings( domain_name_label=self.domain_name ) else: self.log("Update Public IP {0}".format(self.name)) - pip = self.network_models.PublicIPAddress( + pip = PublicIPAddress( location=results['location'], public_ip_allocation_method=results['public_ip_allocation_method'], tags=results['tags'] ) if self.domain_name: - pip.dns_settings = self.network_models.PublicIPAddressDnsSettings( + pip.dns_settings = PublicIPAddressDnsSettings( domain_name_label=self.domain_name ) self.results['state'] = self.create_or_update_pip(pip) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_resourcegroup.py b/lib/ansible/modules/cloud/azure/azure_rm_resourcegroup.py index d9a746851d..cd4d159365 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_resourcegroup.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_resourcegroup.py @@ -96,6 +96,7 @@ state: try: from msrestazure.azure_exceptions import CloudError + from azure.mgmt.resource.resources.models import ResourceGroup except ImportError: pass @@ -192,13 +193,13 @@ class AzureRMResourceGroup(AzureRMModuleBase): if self.name_exists(): self.fail("Error: a resource group with the name {0} already exists in your subscription." .format(self.name)) - params = self.rm_models.ResourceGroup( + params = ResourceGroup( location=self.location, tags=self.tags ) else: # Update resource group - params = self.rm_models.ResourceGroup( + params = ResourceGroup( location=results['location'], tags=results['tags'] ) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_securitygroup.py b/lib/ansible/modules/cloud/azure/azure_rm_securitygroup.py index 0f8015e687..e8252ba3bb 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_securitygroup.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_securitygroup.py @@ -328,6 +328,12 @@ state: try: from msrestazure.azure_exceptions import CloudError + from azure.mgmt.network.models import NetworkSecurityGroup, SecurityRule + from azure.mgmt.network.models import ( + SecurityRuleAccess, + SecurityRuleDirection, + SecurityRuleProtocol + ) except ImportError: # This is handled in azure_rm_common pass @@ -336,7 +342,7 @@ from ansible.module_utils.azure_rm_common import AzureRMModuleBase from ansible.module_utils.six import integer_types -def validate_rule(self, rule, rule_type=None): +def validate_rule(rule, rule_type=None): ''' Apply defaults to a rule dictionary and check that all values are valid. @@ -363,7 +369,7 @@ def validate_rule(self, rule, rule_type=None): if not rule.get('access'): rule['access'] = 'Allow' - access_names = [member.value for member in self.network_models.SecurityRuleAccess] + access_names = [member.value for member in SecurityRuleAccess] if rule['access'] not in access_names: raise Exception("Rule access must be one of [{0}]".format(', '.join(access_names))) @@ -376,14 +382,14 @@ def validate_rule(self, rule, rule_type=None): if not rule.get('protocol'): rule['protocol'] = '*' - protocol_names = [member.value for member in self.network_models.SecurityRuleProtocol] + protocol_names = [member.value for member in SecurityRuleProtocol] if rule['protocol'] not in protocol_names: raise Exception("Rule protocol must be one of [{0}]".format(', '.join(protocol_names))) if not rule.get('direction'): rule['direction'] = 'Inbound' - direction_names = [member.value for member in self.network_models.SecurityRuleDirection] + direction_names = [member.value for member in SecurityRuleDirection] if rule['direction'] not in direction_names: raise Exception("Rule direction must be one of [{0}]".format(', '.join(direction_names))) @@ -423,14 +429,14 @@ def compare_rules(r, rule): return matched, changed -def create_rule_instance(self, rule): +def create_rule_instance(rule): ''' Create an instance of SecurityRule from a dict. :param rule: dict :return: SecurityRule ''' - return self.network_models.SecurityRule( + return SecurityRule( protocol=rule['protocol'], source_address_prefix=rule['source_address_prefix'], destination_address_prefix=rule['destination_address_prefix'], @@ -551,14 +557,14 @@ class AzureRMSecurityGroup(AzureRMModuleBase): if self.rules: for rule in self.rules: try: - validate_rule(self, rule) + validate_rule(rule) except Exception as exc: self.fail("Error validating rule {0} - {1}".format(rule, str(exc))) if self.default_rules: for rule in self.default_rules: try: - validate_rule(self, rule, 'default') + validate_rule(rule, 'default') except Exception as exc: self.fail("Error validating default rule {0} - {1}".format(rule, str(exc))) @@ -672,15 +678,15 @@ class AzureRMSecurityGroup(AzureRMModuleBase): return self.results def create_or_update(self, results): - parameters = self.network_models.NetworkSecurityGroup() + parameters = NetworkSecurityGroup() if results.get('rules'): parameters.security_rules = [] for rule in results.get('rules'): - parameters.security_rules.append(create_rule_instance(self, rule)) + parameters.security_rules.append(create_rule_instance(rule)) if results.get('default_rules'): parameters.default_security_rules = [] for rule in results.get('default_rules'): - parameters.default_security_rules.append(create_rule_instance(self, rule)) + parameters.default_security_rules.append(create_rule_instance(rule)) parameters.tags = results.get('tags') parameters.location = results.get('location') diff --git a/lib/ansible/modules/cloud/azure/azure_rm_storageaccount.py b/lib/ansible/modules/cloud/azure/azure_rm_storageaccount.py index 9b705eff86..4ab2fcc25d 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_storageaccount.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_storageaccount.py @@ -153,6 +153,9 @@ try: from msrestazure.azure_exceptions import CloudError from azure.storage.cloudstorageaccount import CloudStorageAccount from azure.common import AzureMissingResourceHttpError + from azure.mgmt.storage.models import ProvisioningState, SkuName, SkuTier, Kind + from azure.mgmt.storage.models import StorageAccountUpdateParameters, CustomDomain, \ + StorageAccountCreateParameters, Sku except ImportError: # This is handled in azure_rm_common pass @@ -177,7 +180,7 @@ class AzureRMStorageAccount(AzureRMModuleBase): access_tier=dict(type='str', choices=['Hot', 'Cool']) ) - for key in self.storage_models.SkuName: + for key in SkuName: self.module_arg_spec['account_type']['choices'].append(getattr(key, 'value')) self.results = dict( @@ -319,7 +322,6 @@ class AzureRMStorageAccount(AzureRMModuleBase): if self.account_type: if self.account_type != self.account_dict['sku_name']: # change the account type - SkuName = self.storage_models.SkuName if self.account_dict['sku_name'] in [SkuName.premium_lrs, SkuName.standard_zrs]: self.fail("Storage accounts of type {0} and {1} cannot be changed.".format( SkuName.premium_lrs, SkuName.standard_zrs)) @@ -335,9 +337,9 @@ class AzureRMStorageAccount(AzureRMModuleBase): try: self.log("sku_name: %s" % self.account_dict['sku_name']) self.log("sku_tier: %s" % self.account_dict['sku_tier']) - sku = self.storage_models.Sku(SkuName(self.account_dict['sku_name'])) - sku.tier = self.storage_models.SkuTier(self.account_dict['sku_tier']) - parameters = self.storage_models.StorageAccountUpdateParameters(sku=sku) + sku = Sku(SkuName(self.account_dict['sku_name'])) + sku.tier = SkuTier(self.account_dict['sku_tier']) + parameters = StorageAccountUpdateParameters(sku=sku) self.storage_client.storage_accounts.update(self.resource_group, self.name, parameters) @@ -350,9 +352,9 @@ class AzureRMStorageAccount(AzureRMModuleBase): self.account_dict['custom_domain'] = self.custom_domain if self.results['changed'] and not self.check_mode: - new_domain = self.storage_models.CustomDomain(name=self.custom_domain['name'], - use_sub_domain=self.custom_domain['use_sub_domain']) - parameters = self.storage_models.StorageAccountUpdateParameters(custom_domain=new_domain) + new_domain = CustomDomain(name=self.custom_domain['name'], + use_sub_domain=self.custom_domain['use_sub_domain']) + parameters = StorageAccountUpdateParameters(custom_domain=new_domain) try: self.storage_client.storage_accounts.update(self.resource_group, self.name, parameters) except Exception as exc: @@ -364,7 +366,7 @@ class AzureRMStorageAccount(AzureRMModuleBase): self.account_dict['access_tier'] = self.access_tier if self.results['changed'] and not self.check_mode: - parameters = self.storage_models.StorageAccountUpdateParameters(access_tier=self.access_tier) + parameters = StorageAccountUpdateParameters(access_tier=self.access_tier) try: self.storage_client.storage_accounts.update(self.resource_group, self.name, parameters) except Exception as exc: @@ -374,7 +376,7 @@ class AzureRMStorageAccount(AzureRMModuleBase): if update_tags: self.results['changed'] = True if not self.check_mode: - parameters = self.storage_models.StorageAccountUpdateParameters(tags=self.account_dict['tags']) + parameters = StorageAccountUpdateParameters(tags=self.account_dict['tags']) try: self.storage_client.storage_accounts.update(self.resource_group, self.name, parameters) except Exception as exc: @@ -406,11 +408,9 @@ class AzureRMStorageAccount(AzureRMModuleBase): if self.tags: account_dict['tags'] = self.tags return account_dict - sku = self.storage_models.Sku(self.storage_models.SkuName(self.account_type)) - sku.tier = self.storage_models.SkuTier.standard if 'Standard' in self.account_type else \ - self.storage_models.SkuTier.premium - parameters = self.storage_models.StorageAccountCreateParameters(sku, self.kind, self.location, - tags=self.tags, access_tier=self.access_tier) + sku = Sku(SkuName(self.account_type)) + sku.tier = SkuTier.standard if 'Standard' in self.account_type else SkuTier.premium + parameters = StorageAccountCreateParameters(sku, self.kind, self.location, tags=self.tags, access_tier=self.access_tier) self.log(str(parameters)) try: poller = self.storage_client.storage_accounts.create(self.resource_group, self.name, parameters) @@ -422,7 +422,7 @@ class AzureRMStorageAccount(AzureRMModuleBase): return self.get_account() def delete_account(self): - if self.account_dict['provisioning_state'] == self.storage_models.ProvisioningState.succeeded.value and \ + if self.account_dict['provisioning_state'] == ProvisioningState.succeeded.value and \ self.account_has_blob_containers() and self.force: self.fail("Account contains blob containers. Is it in use? Use the force option to attempt deletion.") diff --git a/lib/ansible/modules/cloud/azure/azure_rm_subnet.py b/lib/ansible/modules/cloud/azure/azure_rm_subnet.py index 4d714f876a..507ba2de9f 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_subnet.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_subnet.py @@ -126,6 +126,7 @@ from ansible.module_utils.azure_rm_common import AzureRMModuleBase, CIDR_PATTERN try: from msrestazure.azure_exceptions import CloudError + from azure.mgmt.network.models import Subnet, NetworkSecurityGroup except ImportError: # This is handled in azure_rm_common pass @@ -234,25 +235,25 @@ class AzureRMSubnet(AzureRMModuleBase): if not subnet: # create new subnet self.log('Creating subnet {0}'.format(self.name)) - subnet = self.network_models.Subnet( + subnet = Subnet( address_prefix=self.address_prefix_cidr ) if nsg: - subnet.network_security_group = self.network_models.NetworkSecurityGroup(id=nsg.id, - location=nsg.location, - resource_guid=nsg.resource_guid) + subnet.network_security_group = NetworkSecurityGroup(id=nsg.id, + location=nsg.location, + resource_guid=nsg.resource_guid) else: # update subnet self.log('Updating subnet {0}'.format(self.name)) - subnet = self.network_models.Subnet( + subnet = Subnet( address_prefix=results['address_prefix'] ) if results['network_security_group'].get('id'): nsg = self.get_security_group(results['network_security_group']['name']) - subnet.network_security_group = self.network_models.NetworkSecurityGroup(id=nsg.id, - location=nsg.location, - resource_guid=nsg.resource_guid) + subnet.network_security_group = NetworkSecurityGroup(id=nsg.id, + location=nsg.location, + resource_guid=nsg.resource_guid) self.results['state'] = self.create_or_update_subnet(subnet) elif self.state == 'absent': diff --git a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py index 427adfdc2a..fb288c0209 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py @@ -538,6 +538,17 @@ import re try: from msrestazure.azure_exceptions import CloudError + from azure.mgmt.compute.models import NetworkInterfaceReference, \ + VirtualMachine, HardwareProfile, \ + StorageProfile, OSProfile, OSDisk, DataDisk, \ + VirtualHardDisk, ManagedDiskParameters, \ + ImageReference, NetworkProfile, LinuxConfiguration, \ + SshConfiguration, SshPublicKey, VirtualMachineSizeTypes, \ + DiskCreateOptionTypes + from azure.mgmt.network.models import PublicIPAddress, NetworkSecurityGroup, NetworkInterface, \ + NetworkInterfaceIPConfiguration, Subnet + from azure.mgmt.storage.models import StorageAccountCreateParameters, Sku + from azure.mgmt.storage.models import Kind, SkuTier, SkuName except ImportError: # This is handled in azure_rm_common pass @@ -828,42 +839,42 @@ class AzureRMVirtualMachine(AzureRMModuleBase): if not self.short_hostname: self.short_hostname = self.name - nics = [self.compute_models.NetworkInterfaceReference(id=id) for id in network_interfaces] + nics = [NetworkInterfaceReference(id=id) for id in network_interfaces] # os disk if not self.managed_disk_type: managed_disk = None - vhd = self.compute_models.VirtualHardDisk(uri=requested_vhd_uri) + vhd = VirtualHardDisk(uri=requested_vhd_uri) else: vhd = None - managed_disk = self.compute_models.ManagedDiskParameters(storage_account_type=self.managed_disk_type) + managed_disk = ManagedDiskParameters(storage_account_type=self.managed_disk_type) - vm_resource = self.compute_models.VirtualMachine( + vm_resource = VirtualMachine( self.location, tags=self.tags, - os_profile=self.compute_models.OSProfile( + os_profile=OSProfile( admin_username=self.admin_username, computer_name=self.short_hostname, ), - hardware_profile=self.compute_models.HardwareProfile( + hardware_profile=HardwareProfile( vm_size=self.vm_size ), - storage_profile=self.compute_models.StorageProfile( - os_disk=self.compute_models.OSDisk( + storage_profile=StorageProfile( + os_disk=OSDisk( name=self.storage_blob_name, vhd=vhd, managed_disk=managed_disk, - create_option=self.compute_models.DiskCreateOptionTypes.from_image, + create_option=DiskCreateOptionTypes.from_image, caching=self.os_disk_caching, ), - image_reference=self.compute_models.ImageReference( + image_reference=ImageReference( publisher=self.image['publisher'], offer=self.image['offer'], sku=self.image['sku'], version=self.image['version'], ), ), - network_profile=self.compute_models.NetworkProfile( + network_profile=NetworkProfile( network_interfaces=nics ), ) @@ -872,13 +883,13 @@ class AzureRMVirtualMachine(AzureRMModuleBase): vm_resource.os_profile.admin_password = self.admin_password if self.os_type == 'Linux': - vm_resource.os_profile.linux_configuration = self.compute_models.LinuxConfiguration( + vm_resource.os_profile.linux_configuration = LinuxConfiguration( disable_password_authentication=disable_ssh_password ) if self.ssh_public_keys: - ssh_config = self.compute_models.SshConfiguration() + ssh_config = SshConfiguration() ssh_config.public_keys = \ - [self.compute_models.SshPublicKey(path=key['path'], key_data=key['key_data']) for key in self.ssh_public_keys] + [SshPublicKey(path=key['path'], key_data=key['key_data']) for key in self.ssh_public_keys] vm_resource.os_profile.linux_configuration.ssh = ssh_config # data disk @@ -916,10 +927,10 @@ class AzureRMVirtualMachine(AzureRMModuleBase): if not data_disk.get('managed_disk_type'): data_disk_managed_disk = None disk_name = data_disk['storage_blob_name'] - data_disk_vhd = self.compute_models.VirtualHardDisk(uri=data_disk_requested_vhd_uri) + data_disk_vhd = VirtualHardDisk(uri=data_disk_requested_vhd_uri) else: data_disk_vhd = None - data_disk_managed_disk = self.compute_models.ManagedDiskParameters(storage_account_type=data_disk['managed_disk_type']) + data_disk_managed_disk = ManagedDiskParameters(storage_account_type=data_disk['managed_disk_type']) disk_name = self.name + "-datadisk-" + str(count) count += 1 @@ -927,12 +938,12 @@ class AzureRMVirtualMachine(AzureRMModuleBase): 'caching', 'ReadOnly' ) - data_disks.append(self.compute_models.DataDisk( + data_disks.append(DataDisk( lun=data_disk['lun'], name=disk_name, vhd=data_disk_vhd, caching=data_disk['caching'], - create_option=self.compute_models.DiskCreateOptionTypes.empty, + create_option=DiskCreateOptionTypes.empty, disk_size_gb=data_disk['disk_size_gb'], managed_disk=data_disk_managed_disk, )) @@ -948,30 +959,30 @@ class AzureRMVirtualMachine(AzureRMModuleBase): self.log("Update virtual machine {0}".format(self.name)) self.results['actions'].append('Updated VM {0}'.format(self.name)) - nics = [self.compute_models.NetworkInterfaceReference(id=interface['id']) + nics = [NetworkInterfaceReference(id=interface['id']) for interface in vm_dict['properties']['networkProfile']['networkInterfaces']] # os disk if not vm_dict['properties']['storageProfile']['osDisk'].get('managedDisk'): managed_disk = None - vhd = self.compute_models.VirtualHardDisk(uri=vm_dict['properties']['storageProfile']['osDisk']['vhd']['uri']) + vhd = VirtualHardDisk(uri=vm_dict['properties']['storageProfile']['osDisk']['vhd']['uri']) else: vhd = None - managed_disk = self.compute_models.ManagedDiskParameters( + managed_disk = ManagedDiskParameters( storage_account_type=vm_dict['properties']['storageProfile']['osDisk']['managedDisk']['storageAccountType'] ) - vm_resource = self.compute_models.VirtualMachine( + vm_resource = VirtualMachine( vm_dict['location'], - os_profile=self.compute_models.OSProfile( + os_profile=OSProfile( admin_username=vm_dict['properties']['osProfile']['adminUsername'], computer_name=vm_dict['properties']['osProfile']['computerName'] ), - hardware_profile=self.compute_models.HardwareProfile( + hardware_profile=HardwareProfile( vm_size=vm_dict['properties']['hardwareProfile']['vmSize'] ), - storage_profile=self.compute_models.StorageProfile( - os_disk=self.compute_models.OSDisk( + storage_profile=StorageProfile( + os_disk=OSDisk( name=vm_dict['properties']['storageProfile']['osDisk']['name'], vhd=vhd, managed_disk=managed_disk, @@ -979,14 +990,14 @@ class AzureRMVirtualMachine(AzureRMModuleBase): os_type=vm_dict['properties']['storageProfile']['osDisk']['osType'], caching=vm_dict['properties']['storageProfile']['osDisk']['caching'], ), - image_reference=self.compute_models.ImageReference( + image_reference=ImageReference( publisher=vm_dict['properties']['storageProfile']['imageReference']['publisher'], offer=vm_dict['properties']['storageProfile']['imageReference']['offer'], sku=vm_dict['properties']['storageProfile']['imageReference']['sku'], version=vm_dict['properties']['storageProfile']['imageReference']['version'] ), ), - network_profile=self.compute_models.NetworkProfile( + network_profile=NetworkProfile( network_interfaces=nics ), ) @@ -1002,16 +1013,16 @@ class AzureRMVirtualMachine(AzureRMModuleBase): linux_config = vm_dict['properties']['osProfile'].get('linuxConfiguration') if linux_config: ssh_config = linux_config.get('ssh', None) - vm_resource.os_profile.linux_configuration = self.compute_models.LinuxConfiguration( + vm_resource.os_profile.linux_configuration = LinuxConfiguration( disable_password_authentication=linux_config.get('disablePasswordAuthentication', False) ) if ssh_config: public_keys = ssh_config.get('publicKeys') if public_keys: - vm_resource.os_profile.linux_configuration.ssh = self.compute_models.SshConfiguration(public_keys=[]) + vm_resource.os_profile.linux_configuration.ssh = SshConfiguration(public_keys=[]) for key in public_keys: vm_resource.os_profile.linux_configuration.ssh.public_keys.append( - self.compute_models.SshPublicKey(path=key['path'], key_data=key['keyData']) + SshPublicKey(path=key['path'], key_data=key['keyData']) ) # data disk @@ -1021,13 +1032,13 @@ class AzureRMVirtualMachine(AzureRMModuleBase): for data_disk in vm_dict['properties']['storageProfile']['dataDisks']: if data_disk.get('managedDisk'): managed_disk_type = data_disk['managedDisk']['storageAccountType'] - data_disk_managed_disk = self.compute_models.ManagedDiskParameters(storage_account_type=managed_disk_type) + data_disk_managed_disk = ManagedDiskParameters(storage_account_type=managed_disk_type) data_disk_vhd = None else: data_disk_vhd = data_disk['vhd']['uri'] data_disk_managed_disk = None - data_disks.append(self.compute_models.DataDisk( + data_disks.append(DataDisk( lun=int(data_disk['lun']), name=data_disk.get('name'), vhd=data_disk_vhd, @@ -1390,10 +1401,10 @@ class AzureRMVirtualMachine(AzureRMModuleBase): self.log("Storage account {0} found.".format(storage_account_name)) self.check_provisioning_state(account) return account - sku = self.storage_models.Sku(self.storage_models.SkuName.standard_lrs) - sku.tier = self.storage_models.SkuTier.standard - kind = self.storage_models.Kind.storage - parameters = self.storage_models.StorageAccountCreateParameters(sku, kind, self.location) + sku = Sku(SkuName.standard_lrs) + Sku.tier = SkuTier.standard + kind = Kind.storage + parameters = StorageAccountCreateParameters(sku, kind, self.location) self.log("Creating storage account {0} in location {1}".format(storage_account_name, self.location)) self.results['actions'].append("Created storage account {0}".format(storage_account_name)) try: @@ -1505,22 +1516,22 @@ class AzureRMVirtualMachine(AzureRMModuleBase): group = self.create_default_securitygroup(self.resource_group, self.location, self.name, self.os_type, self.open_ports) - parameters = self.network_models.NetworkInterface( + parameters = NetworkInterface( location=self.location, ip_configurations=[ - self.network_models.NetworkInterfaceIPConfiguration( + NetworkInterfaceIPConfiguration( private_ip_allocation_method='Dynamic', ) ] ) - parameters.ip_configurations[0].subnet = self.network_models.Subnet(id=subnet_id) + parameters.ip_configurations[0].subnet = Subnet(id=subnet_id) parameters.ip_configurations[0].name = 'default' - parameters.network_security_group = self.network_models.NetworkSecurityGroup(id=group.id, - location=group.location, - resource_guid=group.resource_guid) - parameters.ip_configurations[0].public_ip_address = self.network_models.PublicIPAddress(id=pip.id, - location=pip.location, - resource_guid=pip.resource_guid) + parameters.network_security_group = NetworkSecurityGroup(id=group.id, + location=group.location, + resource_guid=group.resource_guid) + parameters.ip_configurations[0].public_ip_address = PublicIPAddress(id=pip.id, + location=pip.location, + resource_guid=pip.resource_guid) self.log("Creating NIC {0}".format(network_interface_name)) self.log(self.serialize_obj(parameters, 'NetworkInterface'), pretty_print=True) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_extension.py b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_extension.py index 5735477675..c00f53d9af 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_extension.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_extension.py @@ -121,6 +121,9 @@ from ansible.module_utils.azure_rm_common import AzureRMModuleBase try: from msrestazure.azure_exceptions import CloudError + from azure.mgmt.compute.models import ( + VirtualMachineExtension + ) except ImportError: # This is handled in azure_rm_common pass @@ -260,7 +263,7 @@ class AzureRMVMExtension(AzureRMModuleBase): ''' self.log("Creating VM extension {0}".format(self.name)) try: - params = self.compute_models.VirtualMachineExtension( + params = VirtualMachineExtension( location=self.location, publisher=self.publisher, virtual_machine_extension_type=self.virtual_machine_extension_type, diff --git a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_scaleset.py b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_scaleset.py index 5881281bbe..776c7340dd 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_scaleset.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_scaleset.py @@ -296,6 +296,24 @@ import re try: from msrestazure.azure_exceptions import CloudError + from azure.mgmt.compute.models import VirtualMachineScaleSet, \ + VirtualMachineScaleSetStorageProfile, \ + VirtualMachineScaleSetOSProfile, \ + VirtualMachineScaleSetOSDisk, VirtualMachineScaleSetDataDisk, \ + VirtualMachineScaleSetManagedDiskParameters, \ + VirtualMachineScaleSetNetworkProfile, LinuxConfiguration, \ + SshConfiguration, SshPublicKey, VirtualMachineSizeTypes, \ + DiskCreateOptionTypes, CachingTypes, \ + VirtualMachineScaleSetVMProfile, VirtualMachineScaleSetIdentity, \ + VirtualMachineScaleSetIPConfiguration, \ + VirtualMachineScaleSetPublicIPAddressConfigurationDnsSettings, \ + VirtualMachineScaleSetPublicIPAddressConfiguration, Sku, \ + UpgradePolicy, VirtualMachineScaleSetNetworkConfiguration, \ + ApiEntityReference, ImageReference + + from azure.mgmt.network.models import PublicIPAddress, \ + NetworkSecurityGroup, NetworkInterface, \ + NetworkInterfaceIPConfiguration, Subnet, VirtualNetwork except ImportError: # This is handled in azure_rm_common @@ -503,46 +521,46 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase): if not self.short_hostname: self.short_hostname = self.name - managed_disk = self.compute_models.VirtualMachineScaleSetManagedDiskParameters(storage_account_type=self.managed_disk_type) + managed_disk = VirtualMachineScaleSetManagedDiskParameters(storage_account_type=self.managed_disk_type) - vmss_resource = self.compute_models.VirtualMachineScaleSet( + vmss_resource = VirtualMachineScaleSet( self.location, tags=self.tags, - upgrade_policy=self.compute_models.UpgradePolicy( + upgrade_policy=UpgradePolicy( mode=self.upgrade_policy ), - sku=self.compute_models.Sku( + sku=Sku( name=self.vm_size, capacity=self.capacity, tier=self.tier, ), - virtual_machine_profile=self.compute_models.VirtualMachineScaleSetVMProfile( - os_profile=self.compute_models.VirtualMachineScaleSetOSProfile( + virtual_machine_profile=VirtualMachineScaleSetVMProfile( + os_profile=VirtualMachineScaleSetOSProfile( admin_username=self.admin_username, computer_name_prefix=self.short_hostname, ), - storage_profile=self.compute_models.VirtualMachineScaleSetStorageProfile( - os_disk=self.compute_models.VirtualMachineScaleSetOSDisk( + storage_profile=VirtualMachineScaleSetStorageProfile( + os_disk=VirtualMachineScaleSetOSDisk( managed_disk=managed_disk, - create_option=self.compute_models.DiskCreateOptionTypes.from_image, + create_option=DiskCreateOptionTypes.from_image, caching=self.os_disk_caching, ), - image_reference=self.compute_models.ImageReference( + image_reference=ImageReference( publisher=self.image['publisher'], offer=self.image['offer'], sku=self.image['sku'], version=self.image['version'], ), ), - network_profile=self.compute_models.VirtualMachineScaleSetNetworkProfile( + network_profile=VirtualMachineScaleSetNetworkProfile( network_interface_configurations=[ - self.compute_models.VirtualMachineScaleSetNetworkConfiguration( + VirtualMachineScaleSetNetworkConfiguration( name=self.name, primary=True, ip_configurations=[ - self.compute_models.VirtualMachineScaleSetIPConfiguration( + VirtualMachineScaleSetIPConfiguration( name='default', - subnet=self.compute_models.ApiEntityReference( + subnet=ApiEntityReference( id=subnet.id ) ) @@ -557,33 +575,33 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase): vmss_resource.virtual_machine_profile.os_profile.admin_password = self.admin_password if self.os_type == 'Linux': - vmss_resource.virtual_machine_profile.os_profile.linux_configuration = self.compute_models.LinuxConfiguration( + vmss_resource.virtual_machine_profile.os_profile.linux_configuration = LinuxConfiguration( disable_password_authentication=disable_ssh_password ) if self.ssh_public_keys: - ssh_config = self.compute_models.SshConfiguration() + ssh_config = SshConfiguration() ssh_config.public_keys = \ - [self.compute_models.SshPublicKey(path=key['path'], key_data=key['key_data']) for key in self.ssh_public_keys] + [SshPublicKey(path=key['path'], key_data=key['key_data']) for key in self.ssh_public_keys] vmss_resource.virtual_machine_profile.os_profile.linux_configuration.ssh = ssh_config if self.data_disks: data_disks = [] for data_disk in self.data_disks: - data_disk_managed_disk = self.compute_models.VirtualMachineScaleSetManagedDiskParameters( + data_disk_managed_disk = VirtualMachineScaleSetManagedDiskParameters( storage_account_type=data_disk['managed_disk_type'] ) data_disk['caching'] = data_disk.get( 'caching', - self.compute_models.CachingTypes.read_only + CachingTypes.read_only ) - data_disks.append(self.compute_models.VirtualMachineScaleSetDataDisk( + data_disks.append(VirtualMachineScaleSetDataDisk( lun=data_disk['lun'], caching=data_disk['caching'], - create_option=self.compute_models.DiskCreateOptionTypes.empty, + create_option=DiskCreateOptionTypes.empty, disk_size_gb=data_disk['disk_size_gb'], managed_disk=data_disk_managed_disk, )) @@ -603,12 +621,12 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase): data_disks = [] for data_disk in self.data_disks: - data_disks.append(self.compute_models.VirtualMachineScaleSetDataDisk( + data_disks.append(VirtualMachineScaleSetDataDisk( lun=data_disk['lun'], caching=data_disk['caching'], - create_option=self.compute_models.DiskCreateOptionTypes.empty, + create_option=DiskCreateOptionTypes.empty, disk_size_gb=data_disk['disk_size_gb'], - managed_disk=self.compute_models.VirtualMachineScaleSetManagedDiskParameters( + managed_disk=VirtualMachineScaleSetManagedDiskParameters( storage_account_type=data_disk['managed_disk_type'] ), )) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_virtualnetwork.py b/lib/ansible/modules/cloud/azure/azure_rm_virtualnetwork.py index f519f25e9d..674743d222 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_virtualnetwork.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_virtualnetwork.py @@ -129,6 +129,7 @@ state: try: from msrestazure.azure_exceptions import CloudError + from azure.mgmt.network.models import VirtualNetwork, AddressSpace, DhcpOptions except ImportError: # This is handled in azure_rm_common pass @@ -294,14 +295,14 @@ class AzureRMVirtualNetwork(AzureRMModuleBase): self.log("Create virtual network {0}".format(self.name)) if not self.address_prefixes_cidr: self.fail('Parameter error: address_prefixes_cidr required when creating a virtual network') - vnet = self.network_models.VirtualNetwork( + vnet = VirtualNetwork( location=self.location, - address_space=self.network_models.AddressSpace( + address_space=AddressSpace( address_prefixes=self.address_prefixes_cidr ) ) if self.dns_servers: - vnet.dhcp_options = self.network_models.DhcpOptions( + vnet.dhcp_options = DhcpOptions( dns_servers=self.dns_servers ) if self.tags: @@ -310,15 +311,15 @@ class AzureRMVirtualNetwork(AzureRMModuleBase): else: # update existing virtual network self.log("Update virtual network {0}".format(self.name)) - vnet = self.network_models.VirtualNetwork( + vnet = VirtualNetwork( location=results['location'], - address_space=self.network_models.AddressSpace( + address_space=AddressSpace( address_prefixes=results['address_prefixes'] ), tags=results['tags'] ) if results.get('dns_servers'): - vnet.dhcp_options = self.network_models.DhcpOptions( + vnet.dhcp_options = DhcpOptions( dns_servers=results['dns_servers'] ) self.results['state'] = self.create_or_update_vnet(vnet)