summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Davis <nitzmahone@users.noreply.github.com>2018-01-09 23:25:50 -0800
committerGitHub <noreply@github.com>2018-01-09 23:25:50 -0800
commitbb9577418ef4200d51508c38cb217c170ed1d900 (patch)
treea7fe5fc1e028eca6ccfef9c4717031fd702e1c62
parent85a181e715cec46cf0062f598648f77728f9f9cc (diff)
downloadansible-bb9577418ef4200d51508c38cb217c170ed1d900.tar.gz
cherry-pick #33897 (#34682)
* resolved a number of conflicts
-rw-r--r--lib/ansible/module_utils/azure_rm_common.py43
-rw-r--r--lib/ansible/modules/cloud/azure/azure_rm_availabilityset.py7
-rw-r--r--lib/ansible/modules/cloud/azure/azure_rm_deployment.py16
-rwxr-xr-xlib/ansible/modules/cloud/azure/azure_rm_loadbalancer.py32
-rw-r--r--lib/ansible/modules/cloud/azure/azure_rm_managed_disk.py9
-rw-r--r--lib/ansible/modules/cloud/azure/azure_rm_networkinterface.py30
-rw-r--r--lib/ansible/modules/cloud/azure/azure_rm_publicipaddress.py9
-rw-r--r--lib/ansible/modules/cloud/azure/azure_rm_resourcegroup.py5
-rw-r--r--lib/ansible/modules/cloud/azure/azure_rm_securitygroup.py28
-rw-r--r--lib/ansible/modules/cloud/azure/azure_rm_storageaccount.py32
-rw-r--r--lib/ansible/modules/cloud/azure/azure_rm_subnet.py17
-rw-r--r--lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py103
-rw-r--r--lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_extension.py5
-rw-r--r--lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_scaleset.py66
-rw-r--r--lib/ansible/modules/cloud/azure/azure_rm_virtualnetwork.py13
-rw-r--r--packaging/requirements/requirements-azure.txt2
16 files changed, 186 insertions, 231 deletions
diff --git a/lib/ansible/module_utils/azure_rm_common.py b/lib/ansible/module_utils/azure_rm_common.py
index 0bbfe08be6..127655583b 100644
--- a/lib/ansible/module_utils/azure_rm_common.py
+++ b/lib/ansible/module_utils/azure_rm_common.py
@@ -98,8 +98,6 @@ 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
@@ -605,7 +603,7 @@ class AzureRMModuleBase(object):
self.check_provisioning_state(pip)
return pip
- params = PublicIPAddress(
+ params = self.network_models.PublicIPAddress(
location=location,
public_ip_allocation_method=allocation_method,
)
@@ -645,7 +643,7 @@ class AzureRMModuleBase(object):
self.check_provisioning_state(group)
return group
- parameters = NetworkSecurityGroup()
+ parameters = self.network_models.NetworkSecurityGroup()
parameters.location = location
if not open_ports:
@@ -653,17 +651,17 @@ class AzureRMModuleBase(object):
if os_type == 'Linux':
# add an inbound SSH rule
parameters.security_rules = [
- SecurityRule('Tcp', '*', '*', 'Allow', 'Inbound', description='Allow SSH Access',
- source_port_range='*', destination_port_range='22', priority=100, name='SSH')
+ self.network_models.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 = [
- 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'),
+ 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'),
]
else:
# Open custom ports
@@ -673,8 +671,8 @@ class AzureRMModuleBase(object):
priority += 1
rule_name = "Rule_{0}".format(priority)
parameters.security_rules.append(
- SecurityRule('Tcp', '*', '*', 'Allow', 'Inbound', source_port_range='*',
- destination_port_range=str(port), priority=priority, name=rule_name)
+ self.network_models.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))
@@ -721,6 +719,11 @@ class AzureRMModuleBase(object):
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')
if not self._network_client:
@@ -730,6 +733,11 @@ class AzureRMModuleBase(object):
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')
if not self._resource_client:
@@ -739,6 +747,11 @@ class AzureRMModuleBase(object):
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')
if not self._compute_client:
@@ -748,6 +761,11 @@ class AzureRMModuleBase(object):
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')
if not self._dns_client:
@@ -768,3 +786,4 @@ class AzureRMModuleBase(object):
if not self._containerservice_client:
self._containerservice_client = self.get_mgmt_svc_client(ContainerServiceClient)
return self._containerservice_client
+
diff --git a/lib/ansible/modules/cloud/azure/azure_rm_availabilityset.py b/lib/ansible/modules/cloud/azure/azure_rm_availabilityset.py
index 6854e6c327..1c15106fe9 100644
--- a/lib/ansible/modules/cloud/azure/azure_rm_availabilityset.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_availabilityset.py
@@ -112,9 +112,6 @@ 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
@@ -263,10 +260,10 @@ class AzureRMAvailabilitySet(AzureRMModuleBase):
'''
self.log("Creating availabilityset {0}".format(self.name))
try:
- params_sku = Sku(
+ params_sku = self.compute_models.Sku(
name=self.sku
)
- params = AvailabilitySet(
+ params = self.compute_models.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 00d8e0a97d..ef05bec083 100644
--- a/lib/ansible/modules/cloud/azure/azure_rm_deployment.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_deployment.py
@@ -379,12 +379,6 @@ 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
@@ -482,21 +476,21 @@ class AzureRMDeploymentManager(AzureRMModuleBase):
:return:
"""
- deploy_parameter = DeploymentProperties(self.deployment_mode)
+ deploy_parameter = self.rm_models.DeploymentProperties(self.deployment_mode)
if not self.parameters_link:
deploy_parameter.parameters = self.parameters
else:
- deploy_parameter.parameters_link = ParametersLink(
+ deploy_parameter.parameters_link = self.rm_models.ParametersLink(
uri=self.parameters_link
)
if not self.template_link:
deploy_parameter.template = self.template
else:
- deploy_parameter.template_link = TemplateLink(
+ deploy_parameter.template_link = self.rm_models.TemplateLink(
uri=self.template_link
)
- params = ResourceGroup(location=self.location, tags=self.tags)
+ params = self.rm_models.ResourceGroup(location=self.location, tags=self.tags)
try:
self.rm_client.resource_groups.create_or_update(self.resource_group_name, params)
@@ -627,7 +621,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, Dependency) and dep.depends_on is not None and len(dep.depends_on) > 0:
+ if isinstance(dep, self.rm_models.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 0b606baa17..deeb8fd607 100755
--- a/lib/ansible/modules/cloud/azure/azure_rm_loadbalancer.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_loadbalancer.py
@@ -184,16 +184,6 @@ 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
@@ -346,7 +336,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'] = [
- FrontendIPConfiguration(
+ self.network_models.FrontendIPConfiguration(
name=frontend_ip_config_name,
public_ip_address=pip
)
@@ -396,7 +386,7 @@ class AzureRMLoadBalancer(AzureRMModuleBase):
load_balancer_name=self.name,
name=backend_address_pool_name
)
- load_balancer_props['backend_address_pools'] = [BackendAddressPool(name=backend_address_pool_name)]
+ load_balancer_props['backend_address_pools'] = [self.network_models.BackendAddressPool(name=backend_address_pool_name)]
probe_name = random_name('probe')
prb_id = probe_id(
@@ -408,7 +398,7 @@ class AzureRMLoadBalancer(AzureRMModuleBase):
if self.probe_protocol:
load_balancer_props['probes'] = [
- Probe(
+ self.network_models.Probe(
name=probe_name,
protocol=self.probe_protocol,
port=self.probe_port,
@@ -421,11 +411,11 @@ class AzureRMLoadBalancer(AzureRMModuleBase):
load_balancing_rule_name = random_name('lbr')
if self.protocol:
load_balancer_props['load_balancing_rules'] = [
- LoadBalancingRule(
+ self.network_models.LoadBalancingRule(
name=load_balancing_rule_name,
- frontend_ip_configuration=SubResource(id=frontend_ip_config_id),
- backend_address_pool=SubResource(id=backend_addr_pool_id),
- probe=SubResource(id=prb_id),
+ 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),
protocol=self.protocol,
load_distribution=self.load_distribution,
frontend_port=self.frontend_port,
@@ -438,9 +428,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'] = [
- InboundNatPool(
+ self.network_models.InboundNatPool(
name=inbound_nat_pool_name,
- frontend_ip_configuration=Subnet(id=frontend_ip_config_id),
+ frontend_ip_configuration=self.network_models.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,
@@ -451,7 +441,7 @@ class AzureRMLoadBalancer(AzureRMModuleBase):
self.results['changed'] = changed
self.results['state'] = (
results if results
- else load_balancer_to_dict(LoadBalancer(**load_balancer_props))
+ else load_balancer_to_dict(self.network_models.LoadBalancer(**load_balancer_props))
)
if self.check_mode:
@@ -461,7 +451,7 @@ class AzureRMLoadBalancer(AzureRMModuleBase):
self.network_client.load_balancers.create_or_update(
resource_group_name=self.resource_group,
load_balancer_name=self.name,
- parameters=LoadBalancer(**load_balancer_props)
+ parameters=self.network_models.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 a22a7f2c47..de89531f90 100644
--- a/lib/ansible/modules/cloud/azure/azure_rm_managed_disk.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_managed_disk.py
@@ -130,7 +130,6 @@ 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
@@ -255,16 +254,16 @@ class AzureRMManagedDisk(AzureRMModuleBase):
disk_params['location'] = self.location
disk_params['tags'] = self.tags
if self.storage_account_type:
- storage_account_type = DiskSku(self.storage_account_type)
+ storage_account_type = self.compute_models.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'] = DiskCreateOption.empty
+ creation_data['create_option'] = self.compute_models.DiskCreateOption.empty
if self.create_option == 'import':
- creation_data['create_option'] = DiskCreateOption.import_enum
+ creation_data['create_option'] = self.compute_models.DiskCreateOption.import_enum
creation_data['source_uri'] = self.source_uri
elif self.create_option == 'copy':
- creation_data['create_option'] = DiskCreateOption.copy
+ creation_data['create_option'] = self.compute_models.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 9dc666a55c..fa62119cb0 100644
--- a/lib/ansible/modules/cloud/azure/azure_rm_networkinterface.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_networkinterface.py
@@ -218,8 +218,6 @@ 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
@@ -444,37 +442,37 @@ class AzureRMNetworkInterface(AzureRMModuleBase):
pip = self.create_default_pip(self.resource_group, self.location, self.name,
self.public_ip_allocation_method)
- nic = NetworkInterface(
+ nic = self.network_models.NetworkInterface(
location=self.location,
tags=self.tags,
ip_configurations=[
- NetworkInterfaceIPConfiguration(
+ self.network_models.NetworkInterfaceIPConfiguration(
private_ip_allocation_method=self.private_ip_allocation_method,
)
]
)
#nic.name = self.name
- nic.ip_configurations[0].subnet = Subnet(id=subnet.id)
+ nic.ip_configurations[0].subnet = self.network_models.Subnet(id=subnet.id)
nic.ip_configurations[0].name = 'default'
- nic.network_security_group = NetworkSecurityGroup(id=nsg.id,
- location=nsg.location,
- resource_guid=nsg.resource_guid)
+ nic.network_security_group = self.network_models.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 = PublicIPAddress(
+ nic.ip_configurations[0].public_ip_address = self.network_models.PublicIPAddress(
id=pip.id,
location=pip.location,
resource_guid=pip.resource_guid)
else:
self.log("Updating network interface {0}.".format(self.name))
- nic = NetworkInterface(
+ nic = self.network_models.NetworkInterface(
id=results['id'],
location=results['location'],
tags=results['tags'],
ip_configurations=[
- NetworkInterfaceIPConfiguration(
+ self.network_models.NetworkInterfaceIPConfiguration(
private_ip_allocation_method=
results['ip_configuration']['private_ip_allocation_method']
)
@@ -482,7 +480,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 = Subnet(id=subnet.id)
+ nic.ip_configurations[0].subnet = self.network_models.Subnet(id=subnet.id)
nic.ip_configurations[0].name = results['ip_configuration']['name']
#nic.name = name=results['name'],
@@ -492,7 +490,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 = PublicIPAddress(
+ nic.ip_configurations[0].public_ip_address = self.network_models.PublicIPAddress(
id=pip.id,
location=pip.location,
resource_guid=pip.resource_guid)
@@ -500,9 +498,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 = NetworkSecurityGroup(id=nsg.id,
- location=nsg.location,
- resource_guid=nsg.resource_guid)
+ nic.network_security_group = self.network_models.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 cfaa21dea0..4269f3cf79 100644
--- a/lib/ansible/modules/cloud/azure/azure_rm_publicipaddress.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_publicipaddress.py
@@ -114,7 +114,6 @@ 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
@@ -223,25 +222,25 @@ class AzureRMPublicIPAddress(AzureRMModuleBase):
if self.state == 'present':
if not pip:
self.log("Create new Public IP {0}".format(self.name))
- pip = PublicIPAddress(
+ pip = self.network_models.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 = PublicIPAddressDnsSettings(
+ pip.dns_settings = self.network_models.PublicIPAddressDnsSettings(
domain_name_label=self.domain_name
)
else:
self.log("Update Public IP {0}".format(self.name))
- pip = PublicIPAddress(
+ pip = self.network_models.PublicIPAddress(
location=results['location'],
public_ip_allocation_method=results['public_ip_allocation_method'],
tags=results['tags']
)
if self.domain_name:
- pip.dns_settings = PublicIPAddressDnsSettings(
+ pip.dns_settings = self.network_models.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 cd4d159365..d9a746851d 100644
--- a/lib/ansible/modules/cloud/azure/azure_rm_resourcegroup.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_resourcegroup.py
@@ -96,7 +96,6 @@ state:
try:
from msrestazure.azure_exceptions import CloudError
- from azure.mgmt.resource.resources.models import ResourceGroup
except ImportError:
pass
@@ -193,13 +192,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 = ResourceGroup(
+ params = self.rm_models.ResourceGroup(
location=self.location,
tags=self.tags
)
else:
# Update resource group
- params = ResourceGroup(
+ params = self.rm_models.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 c934eddb27..a618d92670 100644
--- a/lib/ansible/modules/cloud/azure/azure_rm_securitygroup.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_securitygroup.py
@@ -328,12 +328,6 @@ 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
@@ -342,7 +336,7 @@ from ansible.module_utils.azure_rm_common import AzureRMModuleBase
from ansible.module_utils.six import integer_types
-def validate_rule(rule, rule_type=None):
+def validate_rule(self, rule, rule_type=None):
'''
Apply defaults to a rule dictionary and check that all values are valid.
@@ -369,7 +363,7 @@ def validate_rule(rule, rule_type=None):
if not rule.get('access'):
rule['access'] = 'Allow'
- access_names = [member.value for member in SecurityRuleAccess]
+ access_names = [member.value for member in self.network_models.SecurityRuleAccess]
if rule['access'] not in access_names:
raise Exception("Rule access must be one of [{0}]".format(', '.join(access_names)))
@@ -382,14 +376,14 @@ def validate_rule(rule, rule_type=None):
if not rule.get('protocol'):
rule['protocol'] = '*'
- protocol_names = [member.value for member in SecurityRuleProtocol]
+ protocol_names = [member.value for member in self.network_models.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 SecurityRuleDirection]
+ direction_names = [member.value for member in self.network_models.SecurityRuleDirection]
if rule['direction'] not in direction_names:
raise Exception("Rule direction must be one of [{0}]".format(', '.join(direction_names)))
@@ -429,14 +423,14 @@ def compare_rules(r, rule):
return matched, changed
-def create_rule_instance(rule):
+def create_rule_instance(self, rule):
'''
Create an instance of SecurityRule from a dict.
:param rule: dict
:return: SecurityRule
'''
- return SecurityRule(
+ return self.network_models.SecurityRule(
rule['protocol'],
rule['source_address_prefix'],
rule['destination_address_prefix'],
@@ -557,14 +551,14 @@ class AzureRMSecurityGroup(AzureRMModuleBase):
if self.rules:
for rule in self.rules:
try:
- validate_rule(rule)
+ validate_rule(self, 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(rule, 'default')
+ validate_rule(self, rule, 'default')
except Exception as exc:
self.fail("Error validating default rule {0} - {1}".format(rule, str(exc)))
@@ -678,15 +672,15 @@ class AzureRMSecurityGroup(AzureRMModuleBase):
return self.results
def create_or_update(self, results):
- parameters = NetworkSecurityGroup()
+ parameters = self.network_models.NetworkSecurityGroup()
if results.get('rules'):
parameters.security_rules = []
for rule in results.get('rules'):
- parameters.security_rules.append(create_rule_instance(rule))
+ parameters.security_rules.append(create_rule_instance(self, 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(rule))
+ parameters.default_security_rules.append(create_rule_instance(self, 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 4ab2fcc25d..9b705eff86 100644
--- a/lib/ansible/modules/cloud/azure/azure_rm_storageaccount.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_storageaccount.py
@@ -153,9 +153,6 @@ 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
@@ -180,7 +177,7 @@ class AzureRMStorageAccount(AzureRMModuleBase):
access_tier=dict(type='str', choices=['Hot', 'Cool'])
)
- for key in SkuName:
+ for key in self.storage_models.SkuName:
self.module_arg_spec['account_type']['choices'].append(getattr(key, 'value'))
self.results = dict(
@@ -322,6 +319,7 @@ 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))
@@ -337,9 +335,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 = Sku(SkuName(self.account_dict['sku_name']))
- sku.tier = SkuTier(self.account_dict['sku_tier'])
- parameters = StorageAccountUpdateParameters(sku=sku)
+ 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)
self.storage_client.storage_accounts.update(self.resource_group,
self.name,
parameters)
@@ -352,9 +350,9 @@ class AzureRMStorageAccount(AzureRMModuleBase):
self.account_dict['custom_domain'] = self.custom_domain
if self.results['changed'] and not self.check_mode:
- new_domain = CustomDomain(name=self.custom_domain['name'],
- use_sub_domain=self.custom_domain['use_sub_domain'])
- parameters = StorageAccountUpdateParameters(custom_domain=new_domain)
+ 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)
try:
self.storage_client.storage_accounts.update(self.resource_group, self.name, parameters)
except Exception as exc:
@@ -366,7 +364,7 @@ class AzureRMStorageAccount(AzureRMModuleBase):
self.account_dict['access_tier'] = self.access_tier
if self.results['changed'] and not self.check_mode:
- parameters = StorageAccountUpdateParameters(access_tier=self.access_tier)
+ parameters = self.storage_models.StorageAccountUpdateParameters(access_tier=self.access_tier)
try:
self.storage_client.storage_accounts.update(self.resource_group, self.name, parameters)
except Exception as exc:
@@ -376,7 +374,7 @@ class AzureRMStorageAccount(AzureRMModuleBase):
if update_tags:
self.results['changed'] = True
if not self.check_mode:
- parameters = StorageAccountUpdateParameters(tags=self.account_dict['tags'])
+ parameters = self.storage_models.StorageAccountUpdateParameters(tags=self.account_dict['tags'])
try:
self.storage_client.storage_accounts.update(self.resource_group, self.name, parameters)
except Exception as exc:
@@ -408,9 +406,11 @@ class AzureRMStorageAccount(AzureRMModuleBase):
if self.tags:
account_dict['tags'] = self.tags
return account_dict
- 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)
+ 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)
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'] == ProvisioningState.succeeded.value and \
+ if self.account_dict['provisioning_state'] == self.storage_models.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 507ba2de9f..4d714f876a 100644
--- a/lib/ansible/modules/cloud/azure/azure_rm_subnet.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_subnet.py
@@ -126,7 +126,6 @@ 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
@@ -235,25 +234,25 @@ class AzureRMSubnet(AzureRMModuleBase):
if not subnet:
# create new subnet
self.log('Creating subnet {0}'.format(self.name))
- subnet = Subnet(
+ subnet = self.network_models.Subnet(
address_prefix=self.address_prefix_cidr
)
if nsg:
- subnet.network_security_group = NetworkSecurityGroup(id=nsg.id,
- location=nsg.location,
- resource_guid=nsg.resource_guid)
+ subnet.network_security_group = self.network_models.NetworkSecurityGroup(id=nsg.id,
+ location=nsg.location,
+ resource_guid=nsg.resource_guid)
else:
# update subnet
self.log('Updating subnet {0}'.format(self.name))
- subnet = Subnet(
+ subnet = self.network_models.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 = NetworkSecurityGroup(id=nsg.id,
- location=nsg.location,
- resource_guid=nsg.resource_guid)
+ subnet.network_security_group = self.network_models.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 3a91e9ccde..07c9dd281e 100644
--- a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py
@@ -538,17 +538,6 @@ 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
@@ -840,42 +829,42 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
if not self.short_hostname:
self.short_hostname = self.name
- nics = [NetworkInterfaceReference(id=id) for id in network_interfaces]
+ nics = [self.compute_models.NetworkInterfaceReference(id=id) for id in network_interfaces]
# os disk
if not self.managed_disk_type:
managed_disk = None
- vhd = VirtualHardDisk(uri=requested_vhd_uri)
+ vhd = self.compute_models.VirtualHardDisk(uri=requested_vhd_uri)
else:
vhd = None
- managed_disk = ManagedDiskParameters(storage_account_type=self.managed_disk_type)
+ managed_disk = self.compute_models.ManagedDiskParameters(storage_account_type=self.managed_disk_type)
- vm_resource = VirtualMachine(
+ vm_resource = self.compute_models.VirtualMachine(
self.location,
tags=self.tags,
- os_profile=OSProfile(
+ os_profile=self.compute_models.OSProfile(
admin_username=self.admin_username,
computer_name=self.short_hostname,
),
- hardware_profile=HardwareProfile(
+ hardware_profile=self.compute_models.HardwareProfile(
vm_size=self.vm_size
),
- storage_profile=StorageProfile(
- os_disk=OSDisk(
+ storage_profile=self.compute_models.StorageProfile(
+ os_disk=self.compute_models.OSDisk(
name=self.storage_blob_name,
vhd=vhd,
managed_disk=managed_disk,
- create_option=DiskCreateOptionTypes.from_image,
+ create_option=self.compute_models.DiskCreateOptionTypes.from_image,
caching=self.os_disk_caching,
),
- image_reference=ImageReference(
+ image_reference=self.compute_models.ImageReference(
publisher=self.image['publisher'],
offer=self.image['offer'],
sku=self.image['sku'],
version=self.image['version'],
),
),
- network_profile=NetworkProfile(
+ network_profile=self.compute_models.NetworkProfile(
network_interfaces=nics
),
)
@@ -884,13 +873,13 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
vm_resource.os_profile.admin_password = self.admin_password
if self.os_type == 'Linux':
- vm_resource.os_profile.linux_configuration = LinuxConfiguration(
+ vm_resource.os_profile.linux_configuration = self.compute_models.LinuxConfiguration(
disable_password_authentication=disable_ssh_password
)
if self.ssh_public_keys:
- ssh_config = SshConfiguration()
+ ssh_config = self.compute_models.SshConfiguration()
ssh_config.public_keys = \
- [SshPublicKey(path=key['path'], key_data=key['key_data']) for key in self.ssh_public_keys]
+ [self.compute_models.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
@@ -928,10 +917,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 = VirtualHardDisk(uri=data_disk_requested_vhd_uri)
+ data_disk_vhd = self.compute_models.VirtualHardDisk(uri=data_disk_requested_vhd_uri)
else:
data_disk_vhd = None
- data_disk_managed_disk = ManagedDiskParameters(storage_account_type=data_disk['managed_disk_type'])
+ data_disk_managed_disk = self.compute_models.ManagedDiskParameters(storage_account_type=data_disk['managed_disk_type'])
disk_name = self.name + "-datadisk-" + str(count)
count += 1
@@ -939,12 +928,12 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
'caching', 'ReadOnly'
)
- data_disks.append(DataDisk(
+ data_disks.append(self.compute_models.DataDisk(
lun=data_disk['lun'],
name=disk_name,
vhd=data_disk_vhd,
caching=data_disk['caching'],
- create_option=DiskCreateOptionTypes.empty,
+ create_option=self.compute_models.DiskCreateOptionTypes.empty,
disk_size_gb=data_disk['disk_size_gb'],
managed_disk=data_disk_managed_disk,
))
@@ -960,30 +949,30 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
self.log("Update virtual machine {0}".format(self.name))
self.results['actions'].append('Updated VM {0}'.format(self.name))
- nics = [NetworkInterfaceReference(id=interface['id'])
+ nics = [self.compute_models.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 = VirtualHardDisk(uri=vm_dict['properties']['storageProfile']['osDisk']['vhd']['uri'])
+ vhd = self.compute_models.VirtualHardDisk(uri=vm_dict['properties']['storageProfile']['osDisk']['vhd']['uri'])
else:
vhd = None
- managed_disk = ManagedDiskParameters(
+ managed_disk = self.compute_models.ManagedDiskParameters(
storage_account_type=vm_dict['properties']['storageProfile']['osDisk']['managedDisk']['storageAccountType']
)
- vm_resource = VirtualMachine(
+ vm_resource = self.compute_models.VirtualMachine(
vm_dict['location'],
- os_profile=OSProfile(
+ os_profile=self.compute_models.OSProfile(
admin_username=vm_dict['properties']['osProfile']['adminUsername'],
computer_name=vm_dict['properties']['osProfile']['computerName']
),
- hardware_profile=HardwareProfile(
+ hardware_profile=self.compute_models.HardwareProfile(
vm_size=vm_dict['properties']['hardwareProfile']['vmSize']
),
- storage_profile=StorageProfile(
- os_disk=OSDisk(
+ storage_profile=self.compute_models.StorageProfile(
+ os_disk=self.compute_models.OSDisk(
name=vm_dict['properties']['storageProfile']['osDisk']['name'],
vhd=vhd,
managed_disk=managed_disk,
@@ -991,14 +980,14 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
os_type=vm_dict['properties']['storageProfile']['osDisk']['osType'],
caching=vm_dict['properties']['storageProfile']['osDisk']['caching'],
),
- image_reference=ImageReference(
+ image_reference=self.compute_models.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=NetworkProfile(
+ network_profile=self.compute_models.NetworkProfile(
network_interfaces=nics
),
)
@@ -1014,16 +1003,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 = LinuxConfiguration(
+ vm_resource.os_profile.linux_configuration = self.compute_models.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 = SshConfiguration(public_keys=[])
+ vm_resource.os_profile.linux_configuration.ssh = self.compute_models.SshConfiguration(public_keys=[])
for key in public_keys:
vm_resource.os_profile.linux_configuration.ssh.public_keys.append(
- SshPublicKey(path=key['path'], key_data=key['keyData'])
+ self.compute_models.SshPublicKey(path=key['path'], key_data=key['keyData'])
)
# data disk
@@ -1033,13 +1022,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 = ManagedDiskParameters(storage_account_type=managed_disk_type)
+ data_disk_managed_disk = self.compute_models.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(DataDisk(
+ data_disks.append(self.compute_models.DataDisk(
lun=int(data_disk['lun']),
name=data_disk.get('name'),
vhd=data_disk_vhd,
@@ -1402,10 +1391,10 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
self.log("Storage account {0} found.".format(storage_account_name))
self.check_provisioning_state(account)
return account
- sku = Sku(SkuName.standard_lrs)
- Sku.tier = SkuTier.standard
- kind = Kind.storage
- parameters = StorageAccountCreateParameters(sku, kind, self.location)
+ 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)
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:
@@ -1517,22 +1506,22 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
group = self.create_default_securitygroup(self.resource_group, self.location, self.name, self.os_type,
self.open_ports)
- parameters = NetworkInterface(
+ parameters = self.network_models.NetworkInterface(
location=self.location,
ip_configurations=[
- NetworkInterfaceIPConfiguration(
+ self.network_models.NetworkInterfaceIPConfiguration(
private_ip_allocation_method='Dynamic',
)
]
)
- parameters.ip_configurations[0].subnet = Subnet(id=subnet_id)
+ parameters.ip_configurations[0].subnet = self.network_models.Subnet(id=subnet_id)
parameters.ip_configurations[0].name = 'default'
- 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)
+ 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)
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 c00f53d9af..5735477675 100644
--- a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_extension.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_extension.py
@@ -121,9 +121,6 @@ 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
@@ -263,7 +260,7 @@ class AzureRMVMExtension(AzureRMModuleBase):
'''
self.log("Creating VM extension {0}".format(self.name))
try:
- params = VirtualMachineExtension(
+ params = self.compute_models.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 776c7340dd..5881281bbe 100644
--- a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_scaleset.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_scaleset.py
@@ -296,24 +296,6 @@ 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
@@ -521,46 +503,46 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase):
if not self.short_hostname:
self.short_hostname = self.name
- managed_disk = VirtualMachineScaleSetManagedDiskParameters(storage_account_type=self.managed_disk_type)
+ managed_disk = self.compute_models.VirtualMachineScaleSetManagedDiskParameters(storage_account_type=self.managed_disk_type)
- vmss_resource = VirtualMachineScaleSet(
+ vmss_resource = self.compute_models.VirtualMachineScaleSet(
self.location,
tags=self.tags,
- upgrade_policy=UpgradePolicy(
+ upgrade_policy=self.compute_models.UpgradePolicy(
mode=self.upgrade_policy
),
- sku=Sku(
+ sku=self.compute_models.Sku(
name=self.vm_size,
capacity=self.capacity,
tier=self.tier,
),
- virtual_machine_profile=VirtualMachineScaleSetVMProfile(
- os_profile=VirtualMachineScaleSetOSProfile(
+ virtual_machine_profile=self.compute_models.VirtualMachineScaleSetVMProfile(
+ os_profile=self.compute_models.VirtualMachineScaleSetOSProfile(
admin_username=self.admin_username,
computer_name_prefix=self.short_hostname,
),
- storage_profile=VirtualMachineScaleSetStorageProfile(
- os_disk=VirtualMachineScaleSetOSDisk(
+ storage_profile=self.compute_models.VirtualMachineScaleSetStorageProfile(
+ os_disk=self.compute_models.VirtualMachineScaleSetOSDisk(
managed_disk=managed_disk,
- create_option=DiskCreateOptionTypes.from_image,
+ create_option=self.compute_models.DiskCreateOptionTypes.from_image,
caching=self.os_disk_caching,
),
- image_reference=ImageReference(
+ image_reference=self.compute_models.ImageReference(
publisher=self.image['publisher'],
offer=self.image['offer'],
sku=self.image['sku'],
version=self.image['version'],
),
),
- network_profile=VirtualMachineScaleSetNetworkProfile(
+ network_profile=self.compute_models.VirtualMachineScaleSetNetworkProfile(
network_interface_configurations=[
- VirtualMachineScaleSetNetworkConfiguration(
+ self.compute_models.VirtualMachineScaleSetNetworkConfiguration(
name=self.name,
primary=True,
ip_configurations=[
- VirtualMachineScaleSetIPConfiguration(
+ self.compute_models.VirtualMachineScaleSetIPConfiguration(
name='default',
- subnet=ApiEntityReference(
+ subnet=self.compute_models.ApiEntityReference(
id=subnet.id
)
)
@@ -575,33 +557,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 = LinuxConfiguration(
+ vmss_resource.virtual_machine_profile.os_profile.linux_configuration = self.compute_models.LinuxConfiguration(
disable_password_authentication=disable_ssh_password
)
if self.ssh_public_keys:
- ssh_config = SshConfiguration()
+ ssh_config = self.compute_models.SshConfiguration()
ssh_config.public_keys = \
- [SshPublicKey(path=key['path'], key_data=key['key_data']) for key in self.ssh_public_keys]
+ [self.compute_models.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 = VirtualMachineScaleSetManagedDiskParameters(
+ data_disk_managed_disk = self.compute_models.VirtualMachineScaleSetManagedDiskParameters(
storage_account_type=data_disk['managed_disk_type']
)
data_disk['caching'] = data_disk.get(
'caching',
- CachingTypes.read_only
+ self.compute_models.CachingTypes.read_only
)
- data_disks.append(VirtualMachineScaleSetDataDisk(
+ data_disks.append(self.compute_models.VirtualMachineScaleSetDataDisk(
lun=data_disk['lun'],
caching=data_disk['caching'],
- create_option=DiskCreateOptionTypes.empty,
+ create_option=self.compute_models.DiskCreateOptionTypes.empty,
disk_size_gb=data_disk['disk_size_gb'],
managed_disk=data_disk_managed_disk,
))
@@ -621,12 +603,12 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase):
data_disks = []
for data_disk in self.data_disks:
- data_disks.append(VirtualMachineScaleSetDataDisk(
+ data_disks.append(self.compute_models.VirtualMachineScaleSetDataDisk(
lun=data_disk['lun'],
caching=data_disk['caching'],
- create_option=DiskCreateOptionTypes.empty,
+ create_option=self.compute_models.DiskCreateOptionTypes.empty,
disk_size_gb=data_disk['disk_size_gb'],
- managed_disk=VirtualMachineScaleSetManagedDiskParameters(
+ managed_disk=self.compute_models.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 674743d222..f519f25e9d 100644
--- a/lib/ansible/modules/cloud/azure/azure_rm_virtualnetwork.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_virtualnetwork.py
@@ -129,7 +129,6 @@ 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
@@ -295,14 +294,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 = VirtualNetwork(
+ vnet = self.network_models.VirtualNetwork(
location=self.location,
- address_space=AddressSpace(
+ address_space=self.network_models.AddressSpace(
address_prefixes=self.address_prefixes_cidr
)
)
if self.dns_servers:
- vnet.dhcp_options = DhcpOptions(
+ vnet.dhcp_options = self.network_models.DhcpOptions(
dns_servers=self.dns_servers
)
if self.tags:
@@ -311,15 +310,15 @@ class AzureRMVirtualNetwork(AzureRMModuleBase):
else:
# update existing virtual network
self.log("Update virtual network {0}".format(self.name))
- vnet = VirtualNetwork(
+ vnet = self.network_models.VirtualNetwork(
location=results['location'],
- address_space=AddressSpace(
+ address_space=self.network_models.AddressSpace(
address_prefixes=results['address_prefixes']
),
tags=results['tags']
)
if results.get('dns_servers'):
- vnet.dhcp_options = DhcpOptions(
+ vnet.dhcp_options = self.network_models.DhcpOptions(
dns_servers=results['dns_servers']
)
self.results['state'] = self.create_or_update_vnet(vnet)
diff --git a/packaging/requirements/requirements-azure.txt b/packaging/requirements/requirements-azure.txt
index 2ae8a3a9d1..487d26ad7d 100644
--- a/packaging/requirements/requirements-azure.txt
+++ b/packaging/requirements/requirements-azure.txt
@@ -2,7 +2,7 @@ packaging
requests[security]
azure-mgmt-compute>=2.0.0,<3
azure-mgmt-network>=1.3.0,<2
-azure-mgmt-storage>=1.2.0,<2
+azure-mgmt-storage>=1.5.0,<2
azure-mgmt-resource>=1.1.0,<2
azure-storage>=0.35.1,<0.36
azure-cli-core>=2.0.12,<3