Fixing issues with azure_rm_virtualmachine crashing (#45269)

* vm fixes
This commit is contained in:
Zim Kalinowski 2018-11-09 11:44:51 +08:00 committed by GitHub
parent f75a84e382
commit f04139bfa3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -912,7 +912,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
vm_dict['properties']['storageProfile']['osDisk']['name'] = self.os_disk_name
if self.os_disk_size_gb and \
self.os_disk_size_gb != vm_dict['properties']['storageProfile']['osDisk']['diskSizeGB']:
self.os_disk_size_gb != vm_dict['properties']['storageProfile']['osDisk'].get('diskSizeGB'):
self.log('CHANGED: virtual machine {0} - OS disk size '.format(self.name))
differences.append('OS Disk size')
changed = True
@ -1178,16 +1178,16 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
# 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 = self.compute_models.VirtualHardDisk(uri=vm_dict['properties']['storageProfile']['osDisk'].get('vhd', {}).get('uri'))
else:
vhd = None
managed_disk = self.compute_models.ManagedDiskParameters(
storage_account_type=vm_dict['properties']['storageProfile']['osDisk']['managedDisk']['storageAccountType']
storage_account_type=vm_dict['properties']['storageProfile']['osDisk']['managedDisk'].get('storageAccountType')
)
availability_set_resource = None
try:
availability_set_resource = self.compute_models.SubResource(vm_dict['properties']['availabilitySet']['id'])
availability_set_resource = self.compute_models.SubResource(vm_dict['properties']['availabilitySet'].get('id'))
except Exception:
# pass if the availability set is not set
pass
@ -1195,29 +1195,29 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
vm_resource = self.compute_models.VirtualMachine(
vm_dict['location'],
os_profile=self.compute_models.OSProfile(
admin_username=vm_dict['properties']['osProfile']['adminUsername'],
computer_name=vm_dict['properties']['osProfile']['computerName']
admin_username=vm_dict['properties'].get('osProfile', {}).get('adminUsername'),
computer_name=vm_dict['properties'].get('osProfile', {}).get('computerName')
),
hardware_profile=self.compute_models.HardwareProfile(
vm_size=vm_dict['properties']['hardwareProfile']['vmSize']
vm_size=vm_dict['properties']['hardwareProfile'].get('vmSize')
),
storage_profile=self.compute_models.StorageProfile(
os_disk=self.compute_models.OSDisk(
name=vm_dict['properties']['storageProfile']['osDisk']['name'],
name=vm_dict['properties']['storageProfile']['osDisk'].get('name'),
vhd=vhd,
managed_disk=managed_disk,
create_option=vm_dict['properties']['storageProfile']['osDisk']['createOption'],
os_type=vm_dict['properties']['storageProfile']['osDisk']['osType'],
caching=vm_dict['properties']['storageProfile']['osDisk']['caching'],
disk_size_gb=vm_dict['properties']['storageProfile']['osDisk']['diskSizeGB']
create_option=vm_dict['properties']['storageProfile']['osDisk'].get('createOption'),
os_type=vm_dict['properties']['storageProfile']['osDisk'].get('osType'),
caching=vm_dict['properties']['storageProfile']['osDisk'].get('caching'),
disk_size_gb=vm_dict['properties']['storageProfile']['osDisk'].get('diskSizeGB')
),
image_reference=self.compute_models.ImageReference(
id=vm_dict['properties']['storageProfile']['imageReference']['id'],
) if 'id' in vm_dict['properties']['storageProfile']['imageReference'].keys() else 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']
publisher=vm_dict['properties']['storageProfile']['imageReference'].get('publisher'),
offer=vm_dict['properties']['storageProfile']['imageReference'].get('offer'),
sku=vm_dict['properties']['storageProfile']['imageReference'].get('sku'),
version=vm_dict['properties']['storageProfile']['imageReference'].get('version')
),
),
availability_set=availability_set_resource,
@ -1261,7 +1261,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
for data_disk in vm_dict['properties']['storageProfile']['dataDisks']:
if data_disk.get('managedDisk'):
managed_disk_type = data_disk['managedDisk']['storageAccountType']
managed_disk_type = data_disk['managedDisk'].get('storageAccountType')
data_disk_managed_disk = self.compute_models.ManagedDiskParameters(storage_account_type=managed_disk_type)
data_disk_vhd = None
else: