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