compute models

pull/33897/merge
Zhijun Zhao 7 years ago committed by Matt Davis
parent 8b482ecd81
commit 1fecb6f923

@ -112,9 +112,6 @@ from ansible.module_utils.azure_rm_common import AzureRMModuleBase
try: try:
from msrestazure.azure_exceptions import CloudError from msrestazure.azure_exceptions import CloudError
from azure.mgmt.compute.models import (
AvailabilitySet, Sku
)
except ImportError: except ImportError:
# This is handled in azure_rm_common # This is handled in azure_rm_common
pass pass
@ -260,10 +257,10 @@ class AzureRMAvailabilitySet(AzureRMModuleBase):
''' '''
self.log("Creating availabilityset {0}".format(self.name)) self.log("Creating availabilityset {0}".format(self.name))
try: try:
params_sku = Sku( params_sku = self.compute_models.Sku(
name=self.sku name=self.sku
) )
params = AvailabilitySet( params = self.compute_models.AvailabilitySet(
location=self.location, location=self.location,
tags=self.tags, tags=self.tags,
platform_update_domain_count=self.platform_update_domain_count, platform_update_domain_count=self.platform_update_domain_count,

@ -100,7 +100,6 @@ from ansible.module_utils.azure_rm_common import AzureRMModuleBase, format_resou
try: try:
from msrestazure.tools import parse_resource_id from msrestazure.tools import parse_resource_id
from msrestazure.azure_exceptions import CloudError from msrestazure.azure_exceptions import CloudError
from azure.mgmt.compute.models import SubResource, OperatingSystemStateTypes, ImageStorageProfile, Image, ImageOSDisk, ImageDataDisk
except ImportError: except ImportError:
# This is handled in azure_rm_common # This is handled in azure_rm_common
pass pass
@ -177,14 +176,14 @@ class AzureRMImage(AzureRMModuleBase):
if vm: if vm:
if self.data_disk_sources: if self.data_disk_sources:
self.fail('data_disk_sources is not allowed when capturing image from vm') self.fail('data_disk_sources is not allowed when capturing image from vm')
image_instance = Image(self.location, source_virtual_machine=SubResource(vm.id)) image_instance = self.compute_models.Image(self.location, source_virtual_machine=self.compute_models.SubResource(vm.id))
else: else:
if not self.os_type: if not self.os_type:
self.fail('os_type is required to create the image') self.fail('os_type is required to create the image')
os_disk = self.create_os_disk() os_disk = self.create_os_disk()
data_disks = self.create_data_disks() data_disks = self.create_data_disks()
storage_profile = ImageStorageProfile(os_disk=os_disk, data_disks=data_disks) storage_profile = self.compute_models.ImageStorageProfile(os_disk=os_disk, data_disks=data_disks)
image_instance = Image(self.location, storage_profile=storage_profile, tags=self.tags) image_instance = self.compute_models.Image(self.location, storage_profile=storage_profile, tags=self.tags)
# finally make the change if not check mode # finally make the change if not check mode
if not self.check_mode and image_instance: if not self.check_mode and image_instance:
@ -234,10 +233,10 @@ class AzureRMImage(AzureRMModuleBase):
def create_os_disk(self): def create_os_disk(self):
blob_uri, disk, snapshot = self.resolve_storage_source(self.source) blob_uri, disk, snapshot = self.resolve_storage_source(self.source)
snapshot_resource = SubResource(snapshot) if snapshot else None snapshot_resource = self.compute_models.SubResource(snapshot) if snapshot else None
managed_disk = SubResource(disk) if disk else None managed_disk = self.compute_models.SubResource(disk) if disk else None
return ImageOSDisk(os_type=self.os_type, return self.compute_models.ImageOSDisk(os_type=self.os_type,
os_state=OperatingSystemStateTypes.generalized, os_state=self.compute_models.OperatingSystemStateTypes.generalized,
snapshot=snapshot_resource, snapshot=snapshot_resource,
managed_disk=managed_disk, managed_disk=managed_disk,
blob_uri=blob_uri) blob_uri=blob_uri)
@ -245,9 +244,9 @@ class AzureRMImage(AzureRMModuleBase):
def create_data_disk(self, lun, source): def create_data_disk(self, lun, source):
blob_uri, disk, snapshot = self.resolve_storage_source(source) blob_uri, disk, snapshot = self.resolve_storage_source(source)
if blob_uri or disk or snapshot: if blob_uri or disk or snapshot:
snapshot_resource = SubResource(snapshot) if snapshot else None snapshot_resource = self.compute_models.SubResource(snapshot) if snapshot else None
managed_disk = SubResource(disk) if disk else None managed_disk = self.compute_models.SubResource(disk) if disk else None
return ImageDataDisk(lun, return self.compute_models.ImageDataDisk(lun,
blob_uri=blob_uri, blob_uri=blob_uri,
snapshot=snapshot_resource, snapshot=snapshot_resource,
managed_disk=managed_disk) managed_disk=managed_disk)

@ -141,7 +141,6 @@ from ansible.module_utils.azure_rm_common import AzureRMModuleBase
try: try:
from msrestazure.tools import parse_resource_id from msrestazure.tools import parse_resource_id
from msrestazure.azure_exceptions import CloudError from msrestazure.azure_exceptions import CloudError
from azure.mgmt.compute.models import DiskCreateOption, DiskCreateOptionTypes, ManagedDiskParameters, DiskSku, DataDisk
except ImportError: except ImportError:
# This is handled in azure_rm_common # This is handled in azure_rm_common
pass pass
@ -289,8 +288,8 @@ class AzureRMManagedDisk(AzureRMModuleBase):
lun = max(luns) + 1 if luns else 0 lun = max(luns) + 1 if luns else 0
# prepare the data disk # prepare the data disk
params = ManagedDiskParameters(id=disk.get('id'), storage_account_type=disk.get('storage_account_type')) params = self.compute_models.ManagedDiskParameters(id=disk.get('id'), storage_account_type=disk.get('storage_account_type'))
data_disk = DataDisk(lun, DiskCreateOptionTypes.attach, managed_disk=params) data_disk = self.compute_models.DataDisk(lun, self.compute_models.DiskCreateOptionTypes.attach, managed_disk=params)
vm.storage_profile.data_disks.append(data_disk) vm.storage_profile.data_disks.append(data_disk)
self._update_vm(vm_name, vm) self._update_vm(vm_name, vm)
@ -321,16 +320,16 @@ class AzureRMManagedDisk(AzureRMModuleBase):
disk_params['location'] = self.location disk_params['location'] = self.location
disk_params['tags'] = self.tags disk_params['tags'] = self.tags
if self.storage_account_type: 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['sku'] = storage_account_type
disk_params['disk_size_gb'] = self.disk_size_gb disk_params['disk_size_gb'] = self.disk_size_gb
# TODO: Add support for EncryptionSettings # 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': 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 creation_data['source_uri'] = self.source_uri
elif self.create_option == 'copy': 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 creation_data['source_resource_id'] = self.source_resource_uri
disk_params['creation_data'] = creation_data disk_params['creation_data'] = creation_data
return disk_params return disk_params

@ -597,13 +597,6 @@ import re
try: try:
from msrestazure.azure_exceptions import CloudError from msrestazure.azure_exceptions import CloudError
from msrestazure.tools import parse_resource_id from msrestazure.tools import parse_resource_id
from azure.mgmt.compute.models import NetworkInterfaceReference, \
VirtualMachine, HardwareProfile, \
StorageProfile, OSProfile, OSDisk, DataDisk, \
VirtualHardDisk, ManagedDiskParameters, \
ImageReference, NetworkProfile, LinuxConfiguration, \
SshConfiguration, SshPublicKey, VirtualMachineSizeTypes, \
DiskCreateOptionTypes, Plan, SubResource
except ImportError: except ImportError:
# This is handled in azure_rm_common # This is handled in azure_rm_common
pass pass
@ -763,7 +756,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
self.image['version'] = marketplace_image.name self.image['version'] = marketplace_image.name
self.log("Using image version {0}".format(self.image['version'])) self.log("Using image version {0}".format(self.image['version']))
image_reference = ImageReference( image_reference = self.network_models.ImageReference(
publisher=self.image['publisher'], publisher=self.image['publisher'],
offer=self.image['offer'], offer=self.image['offer'],
sku=self.image['sku'], sku=self.image['sku'],
@ -905,7 +898,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
parsed_availability_set = parse_resource_id(self.availability_set) parsed_availability_set = parse_resource_id(self.availability_set)
availability_set = self.get_availability_set(parsed_availability_set.get('resource_group', self.resource_group), availability_set = self.get_availability_set(parsed_availability_set.get('resource_group', self.resource_group),
parsed_availability_set.get('name')) parsed_availability_set.get('name'))
availability_set_resource = SubResource(availability_set.id) availability_set_resource = self.network_models.SubResource(availability_set.id)
# Get defaults # Get defaults
if not self.network_interface_names: if not self.network_interface_names:
@ -929,45 +922,45 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
if not self.short_hostname: if not self.short_hostname:
self.short_hostname = self.name self.short_hostname = self.name
nics = [NetworkInterfaceReference(id=id) for id in network_interfaces] nics = [self.network_models.NetworkInterfaceReference(id=id) for id in network_interfaces]
# os disk # os disk
if self.managed_disk_type: if self.managed_disk_type:
vhd = None vhd = None
managed_disk = ManagedDiskParameters(storage_account_type=self.managed_disk_type) managed_disk = self.network_models.ManagedDiskParameters(storage_account_type=self.managed_disk_type)
elif custom_image: elif custom_image:
vhd = None vhd = None
managed_disk = None managed_disk = None
else: else:
vhd = VirtualHardDisk(uri=requested_vhd_uri) vhd = self.network_models.VirtualHardDisk(uri=requested_vhd_uri)
managed_disk = None managed_disk = None
plan = None plan = None
if self.plan: if self.plan:
plan = Plan(name=self.plan.get('name'), product=self.plan.get('product'), publisher=self.plan.get('publisher'), plan = self.network_models.Plan(name=self.plan.get('name'), product=self.plan.get('product'), publisher=self.plan.get('publisher'),
promotion_code=self.plan.get('promotion_code')) promotion_code=self.plan.get('promotion_code'))
vm_resource = VirtualMachine( vm_resource = self.network_models.VirtualMachine(
self.location, self.location,
tags=self.tags, tags=self.tags,
os_profile=OSProfile( os_profile=self.network_models.OSProfile(
admin_username=self.admin_username, admin_username=self.admin_username,
computer_name=self.short_hostname, computer_name=self.short_hostname,
), ),
hardware_profile=HardwareProfile( hardware_profile=self.network_models.HardwareProfile(
vm_size=self.vm_size vm_size=self.vm_size
), ),
storage_profile=StorageProfile( storage_profile=self.network_models.StorageProfile(
os_disk=OSDisk( os_disk=self.network_models.OSDisk(
name=self.storage_blob_name, name=self.storage_blob_name,
vhd=vhd, vhd=vhd,
managed_disk=managed_disk, managed_disk=managed_disk,
create_option=DiskCreateOptionTypes.from_image, create_option=self.network_models.DiskCreateOptionTypes.from_image,
caching=self.os_disk_caching, caching=self.os_disk_caching,
), ),
image_reference=image_reference, image_reference=image_reference,
), ),
network_profile=NetworkProfile( network_profile=self.network_models.NetworkProfile(
network_interfaces=nics network_interfaces=nics
), ),
availability_set=availability_set_resource, availability_set=availability_set_resource,
@ -978,13 +971,13 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
vm_resource.os_profile.admin_password = self.admin_password vm_resource.os_profile.admin_password = self.admin_password
if self.os_type == 'Linux': if self.os_type == 'Linux':
vm_resource.os_profile.linux_configuration = LinuxConfiguration( vm_resource.os_profile.linux_configuration = self.network_models.LinuxConfiguration(
disable_password_authentication=disable_ssh_password disable_password_authentication=disable_ssh_password
) )
if self.ssh_public_keys: if self.ssh_public_keys:
ssh_config = SshConfiguration() ssh_config = self.network_models.SshConfiguration()
ssh_config.public_keys = \ ssh_config.public_keys = \
[SshPublicKey(path=key['path'], key_data=key['key_data']) for key in self.ssh_public_keys] [self.network_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 vm_resource.os_profile.linux_configuration.ssh = ssh_config
# data disk # data disk
@ -1022,10 +1015,10 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
if not data_disk.get('managed_disk_type'): if not data_disk.get('managed_disk_type'):
data_disk_managed_disk = None data_disk_managed_disk = None
disk_name = data_disk['storage_blob_name'] disk_name = data_disk['storage_blob_name']
data_disk_vhd = VirtualHardDisk(uri=data_disk_requested_vhd_uri) data_disk_vhd = self.network_models.VirtualHardDisk(uri=data_disk_requested_vhd_uri)
else: else:
data_disk_vhd = None data_disk_vhd = None
data_disk_managed_disk = ManagedDiskParameters(storage_account_type=data_disk['managed_disk_type']) data_disk_managed_disk = self.network_models.ManagedDiskParameters(storage_account_type=data_disk['managed_disk_type'])
disk_name = self.name + "-datadisk-" + str(count) disk_name = self.name + "-datadisk-" + str(count)
count += 1 count += 1
@ -1033,12 +1026,12 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
'caching', 'ReadOnly' 'caching', 'ReadOnly'
) )
data_disks.append(DataDisk( data_disks.append(self.network_models.DataDisk(
lun=data_disk['lun'], lun=data_disk['lun'],
name=disk_name, name=disk_name,
vhd=data_disk_vhd, vhd=data_disk_vhd,
caching=data_disk['caching'], caching=data_disk['caching'],
create_option=DiskCreateOptionTypes.empty, create_option=self.network_models.DiskCreateOptionTypes.empty,
disk_size_gb=data_disk['disk_size_gb'], disk_size_gb=data_disk['disk_size_gb'],
managed_disk=data_disk_managed_disk, managed_disk=data_disk_managed_disk,
)) ))
@ -1054,37 +1047,37 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
self.log("Update virtual machine {0}".format(self.name)) self.log("Update virtual machine {0}".format(self.name))
self.results['actions'].append('Updated VM {0}'.format(self.name)) self.results['actions'].append('Updated VM {0}'.format(self.name))
nics = [NetworkInterfaceReference(id=interface['id']) nics = [self.network_models.NetworkInterfaceReference(id=interface['id'])
for interface in vm_dict['properties']['networkProfile']['networkInterfaces']] for interface in vm_dict['properties']['networkProfile']['networkInterfaces']]
# os disk # os disk
if not vm_dict['properties']['storageProfile']['osDisk'].get('managedDisk'): if not vm_dict['properties']['storageProfile']['osDisk'].get('managedDisk'):
managed_disk = None managed_disk = None
vhd = VirtualHardDisk(uri=vm_dict['properties']['storageProfile']['osDisk']['vhd']['uri']) vhd = self.network_models.VirtualHardDisk(uri=vm_dict['properties']['storageProfile']['osDisk']['vhd']['uri'])
else: else:
vhd = None vhd = None
managed_disk = ManagedDiskParameters( managed_disk = self.network_models.ManagedDiskParameters(
storage_account_type=vm_dict['properties']['storageProfile']['osDisk']['managedDisk']['storageAccountType'] storage_account_type=vm_dict['properties']['storageProfile']['osDisk']['managedDisk']['storageAccountType']
) )
availability_set_resource = None availability_set_resource = None
try: try:
availability_set_resource = SubResource(vm_dict['properties']['availabilitySet']['id']) availability_set_resource = self.network_models.SubResource(vm_dict['properties']['availabilitySet']['id'])
except Exception: except Exception:
# pass if the availability set is not set # pass if the availability set is not set
pass pass
vm_resource = VirtualMachine( vm_resource = self.network_models.VirtualMachine(
vm_dict['location'], vm_dict['location'],
os_profile=OSProfile( os_profile=self.network_models.OSProfile(
admin_username=vm_dict['properties']['osProfile']['adminUsername'], admin_username=vm_dict['properties']['osProfile']['adminUsername'],
computer_name=vm_dict['properties']['osProfile']['computerName'] computer_name=vm_dict['properties']['osProfile']['computerName']
), ),
hardware_profile=HardwareProfile( hardware_profile=self.network_models.HardwareProfile(
vm_size=vm_dict['properties']['hardwareProfile']['vmSize'] vm_size=vm_dict['properties']['hardwareProfile']['vmSize']
), ),
storage_profile=StorageProfile( storage_profile=self.network_models.StorageProfile(
os_disk=OSDisk( os_disk=self.network_models.OSDisk(
name=vm_dict['properties']['storageProfile']['osDisk']['name'], name=vm_dict['properties']['storageProfile']['osDisk']['name'],
vhd=vhd, vhd=vhd,
managed_disk=managed_disk, managed_disk=managed_disk,
@ -1092,7 +1085,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
os_type=vm_dict['properties']['storageProfile']['osDisk']['osType'], os_type=vm_dict['properties']['storageProfile']['osDisk']['osType'],
caching=vm_dict['properties']['storageProfile']['osDisk']['caching'], caching=vm_dict['properties']['storageProfile']['osDisk']['caching'],
), ),
image_reference=ImageReference( image_reference=self.network_models.ImageReference(
publisher=vm_dict['properties']['storageProfile']['imageReference']['publisher'], publisher=vm_dict['properties']['storageProfile']['imageReference']['publisher'],
offer=vm_dict['properties']['storageProfile']['imageReference']['offer'], offer=vm_dict['properties']['storageProfile']['imageReference']['offer'],
sku=vm_dict['properties']['storageProfile']['imageReference']['sku'], sku=vm_dict['properties']['storageProfile']['imageReference']['sku'],
@ -1100,7 +1093,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
), ),
), ),
availability_set=availability_set_resource, availability_set=availability_set_resource,
network_profile=NetworkProfile( network_profile=self.network_models.NetworkProfile(
network_interfaces=nics network_interfaces=nics
), ),
) )
@ -1116,16 +1109,16 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
linux_config = vm_dict['properties']['osProfile'].get('linuxConfiguration') linux_config = vm_dict['properties']['osProfile'].get('linuxConfiguration')
if linux_config: if linux_config:
ssh_config = linux_config.get('ssh', None) ssh_config = linux_config.get('ssh', None)
vm_resource.os_profile.linux_configuration = LinuxConfiguration( vm_resource.os_profile.linux_configuration = self.network_models.LinuxConfiguration(
disable_password_authentication=linux_config.get('disablePasswordAuthentication', False) disable_password_authentication=linux_config.get('disablePasswordAuthentication', False)
) )
if ssh_config: if ssh_config:
public_keys = ssh_config.get('publicKeys') public_keys = ssh_config.get('publicKeys')
if public_keys: if public_keys:
vm_resource.os_profile.linux_configuration.ssh = SshConfiguration(public_keys=[]) vm_resource.os_profile.linux_configuration.ssh = self.network_models.SshConfiguration(public_keys=[])
for key in public_keys: for key in public_keys:
vm_resource.os_profile.linux_configuration.ssh.public_keys.append( vm_resource.os_profile.linux_configuration.ssh.public_keys.append(
SshPublicKey(path=key['path'], key_data=key['keyData']) self.network_models.SshPublicKey(path=key['path'], key_data=key['keyData'])
) )
# data disk # data disk
@ -1135,13 +1128,13 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
for data_disk in vm_dict['properties']['storageProfile']['dataDisks']: for data_disk in vm_dict['properties']['storageProfile']['dataDisks']:
if data_disk.get('managedDisk'): if data_disk.get('managedDisk'):
managed_disk_type = data_disk['managedDisk']['storageAccountType'] managed_disk_type = data_disk['managedDisk']['storageAccountType']
data_disk_managed_disk = ManagedDiskParameters(storage_account_type=managed_disk_type) data_disk_managed_disk = self.network_models.ManagedDiskParameters(storage_account_type=managed_disk_type)
data_disk_vhd = None data_disk_vhd = None
else: else:
data_disk_vhd = data_disk['vhd']['uri'] data_disk_vhd = data_disk['vhd']['uri']
data_disk_managed_disk = None data_disk_managed_disk = None
data_disks.append(DataDisk( data_disks.append(self.network_models.DataDisk(
lun=int(data_disk['lun']), lun=int(data_disk['lun']),
name=data_disk.get('name'), name=data_disk.get('name'),
vhd=data_disk_vhd, vhd=data_disk_vhd,
@ -1454,7 +1447,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
for vm_image in vm_images: for vm_image in vm_images:
if vm_image.name == name: if vm_image.name == name:
self.log("Using custom image id {0}".format(vm_image.id)) self.log("Using custom image id {0}".format(vm_image.id))
return ImageReference(id=vm_image.id) return self.network_models.ImageReference(id=vm_image.id)
self.fail("Error could not find image with name {0}".format(name)) self.fail("Error could not find image with name {0}".format(name))

@ -121,9 +121,6 @@ from ansible.module_utils.azure_rm_common import AzureRMModuleBase
try: try:
from msrestazure.azure_exceptions import CloudError from msrestazure.azure_exceptions import CloudError
from azure.mgmt.compute.models import (
VirtualMachineExtension
)
except ImportError: except ImportError:
# This is handled in azure_rm_common # This is handled in azure_rm_common
pass pass
@ -260,7 +257,7 @@ class AzureRMVMExtension(AzureRMModuleBase):
''' '''
self.log("Creating VM extension {0}".format(self.name)) self.log("Creating VM extension {0}".format(self.name))
try: try:
params = VirtualMachineExtension( params = self.compute_models.VirtualMachineExtension(
location=self.location, location=self.location,
publisher=self.publisher, publisher=self.publisher,
virtual_machine_extension_type=self.virtual_machine_extension_type, virtual_machine_extension_type=self.virtual_machine_extension_type,

@ -339,20 +339,6 @@ import re
try: try:
from msrestazure.azure_exceptions import CloudError from msrestazure.azure_exceptions import CloudError
from msrestazure.tools import parse_resource_id from msrestazure.tools import parse_resource_id
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, SubResource
except ImportError: except ImportError:
# This is handled in azure_rm_common # This is handled in azure_rm_common
@ -481,7 +467,7 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase):
self.image['version'] = marketplace_image.name self.image['version'] = marketplace_image.name
self.log("Using image version {0}".format(self.image['version'])) self.log("Using image version {0}".format(self.image['version']))
image_reference = ImageReference( image_reference = self.compute_models.ImageReference(
publisher=self.image['publisher'], publisher=self.image['publisher'],
offer=self.image['offer'], offer=self.image['offer'],
sku=self.image['sku'], sku=self.image['sku'],
@ -583,10 +569,10 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase):
load_balancer_inbound_nat_pools = None load_balancer_inbound_nat_pools = None
if self.load_balancer: if self.load_balancer:
load_balancer = self.get_load_balancer(self.load_balancer) load_balancer = self.get_load_balancer(self.load_balancer)
load_balancer_backend_address_pools = ([SubResource(resource.id) load_balancer_backend_address_pools = ([self.compute_models.SubResource(resource.id)
for resource in load_balancer.backend_address_pools] for resource in load_balancer.backend_address_pools]
if load_balancer.backend_address_pools else None) if load_balancer.backend_address_pools else None)
load_balancer_inbound_nat_pools = ([SubResource(resource.id) load_balancer_inbound_nat_pools = ([self.compute_models.SubResource(resource.id)
for resource in load_balancer.inbound_nat_pools] for resource in load_balancer.inbound_nat_pools]
if load_balancer.inbound_nat_pools else None) if load_balancer.inbound_nat_pools else None)
@ -596,41 +582,41 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase):
if not image_reference: if not image_reference:
self.fail("Parameter error: an image is required when creating a virtual machine.") self.fail("Parameter error: an image is required when creating a virtual machine.")
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, self.location,
tags=self.tags, tags=self.tags,
upgrade_policy=UpgradePolicy( upgrade_policy=self.compute_models.UpgradePolicy(
mode=self.upgrade_policy mode=self.upgrade_policy
), ),
sku=Sku( sku=self.compute_models.Sku(
name=self.vm_size, name=self.vm_size,
capacity=self.capacity, capacity=self.capacity,
tier=self.tier, tier=self.tier,
), ),
virtual_machine_profile=VirtualMachineScaleSetVMProfile( virtual_machine_profile=self.compute_models.VirtualMachineScaleSetVMProfile(
os_profile=VirtualMachineScaleSetOSProfile( os_profile=self.compute_models.VirtualMachineScaleSetOSProfile(
admin_username=self.admin_username, admin_username=self.admin_username,
computer_name_prefix=self.short_hostname, computer_name_prefix=self.short_hostname,
), ),
storage_profile=VirtualMachineScaleSetStorageProfile( storage_profile=self.compute_models.VirtualMachineScaleSetStorageProfile(
os_disk=VirtualMachineScaleSetOSDisk( os_disk=self.compute_models.VirtualMachineScaleSetOSDisk(
managed_disk=managed_disk, managed_disk=managed_disk,
create_option=DiskCreateOptionTypes.from_image, create_option=self.compute_models.DiskCreateOptionTypes.from_image,
caching=self.os_disk_caching, caching=self.os_disk_caching,
), ),
image_reference=image_reference, image_reference=image_reference,
), ),
network_profile=VirtualMachineScaleSetNetworkProfile( network_profile=self.compute_models.VirtualMachineScaleSetNetworkProfile(
network_interface_configurations=[ network_interface_configurations=[
VirtualMachineScaleSetNetworkConfiguration( self.compute_models.VirtualMachineScaleSetNetworkConfiguration(
name=self.name, name=self.name,
primary=True, primary=True,
ip_configurations=[ ip_configurations=[
VirtualMachineScaleSetIPConfiguration( self.compute_models.VirtualMachineScaleSetIPConfiguration(
name='default', name='default',
subnet=ApiEntityReference( subnet=self.compute_models.ApiEntityReference(
id=subnet.id id=subnet.id
), ),
primary=True, primary=True,
@ -648,33 +634,33 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase):
vmss_resource.virtual_machine_profile.os_profile.admin_password = self.admin_password vmss_resource.virtual_machine_profile.os_profile.admin_password = self.admin_password
if self.os_type == 'Linux': 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 disable_password_authentication=disable_ssh_password
) )
if self.ssh_public_keys: if self.ssh_public_keys:
ssh_config = SshConfiguration() ssh_config = self.compute_models.SshConfiguration()
ssh_config.public_keys = \ 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 vmss_resource.virtual_machine_profile.os_profile.linux_configuration.ssh = ssh_config
if self.data_disks: if self.data_disks:
data_disks = [] data_disks = []
for data_disk in self.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'] storage_account_type=data_disk['managed_disk_type']
) )
data_disk['caching'] = data_disk.get( data_disk['caching'] = data_disk.get(
'caching', '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'], lun=data_disk['lun'],
caching=data_disk['caching'], caching=data_disk['caching'],
create_option=DiskCreateOptionTypes.empty, create_option=self.compute_models.DiskCreateOptionTypes.empty,
disk_size_gb=data_disk['disk_size_gb'], disk_size_gb=data_disk['disk_size_gb'],
managed_disk=data_disk_managed_disk, managed_disk=data_disk_managed_disk,
)) ))
@ -694,12 +680,12 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase):
data_disks = [] data_disks = []
for data_disk in self.data_disks: for data_disk in self.data_disks:
data_disks.append(VirtualMachineScaleSetDataDisk( data_disks.append(self.compute_models.VirtualMachineScaleSetDataDisk(
lun=data_disk['lun'], lun=data_disk['lun'],
caching=data_disk['caching'], caching=data_disk['caching'],
create_option=DiskCreateOptionTypes.empty, create_option=self.compute_models.DiskCreateOptionTypes.empty,
disk_size_gb=data_disk['disk_size_gb'], 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'] storage_account_type=data_disk['managed_disk_type']
), ),
)) ))
@ -822,7 +808,7 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase):
for vm_image in vm_images: for vm_image in vm_images:
if vm_image.name == name: if vm_image.name == name:
self.log("Using custom image id {0}".format(vm_image.id)) self.log("Using custom image id {0}".format(vm_image.id))
return ImageReference(id=vm_image.id) return self.compute_models.ImageReference(id=vm_image.id)
self.fail("Error could not find image with name {0}".format(name)) self.fail("Error could not find image with name {0}".format(name))

Loading…
Cancel
Save