Skip to content

Commit

Permalink
Fixed a bug where the pipeline test failed (ansible-collections#1748)
Browse files Browse the repository at this point in the history
* Fixed a bug where the pipeline test failed

* small change

* small change
  • Loading branch information
Fred-sun authored Oct 28, 2024
1 parent ae1ccf9 commit df5a444
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
15 changes: 15 additions & 0 deletions plugins/module_utils/azure_rm_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ def __init__(self, derived_arg_spec, bypass_checks=False, no_log=False,
self._resource_client = None
self._compute_client = None
self._disk_client = None
self._multi_disk_client = None
self._diskencryptionset_client = None
self._image_client = None
self._dns_client = None
Expand Down Expand Up @@ -1143,6 +1144,20 @@ def disk_models(self):
self.log("Getting disk models")
return ComputeManagementClient.models("2023-04-02")

@property
def multi_disk_client(self):
self.log('Getting disk client')
if not self._multi_disk_client:
self._multi_disk_client = self.get_mgmt_svc_client(ComputeManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager,
api_version='2021-04-01')
return self._multi_disk_client

@property
def multi_disk_models(self):
self.log("Getting disk models")
return ComputeManagementClient.models("2021-04-01")

@property
def diskencryptionset_client(self):
self.log('Getting diskencryptionset client')
Expand Down
30 changes: 15 additions & 15 deletions plugins/modules/azure_rm_multiplemanageddisks.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,19 +449,19 @@ def generate_disk_parameters(self, location, tags, zone=None,
if zone:
disk_params['zones'] = [zone]
if storage_account_type:
storage = self.disk_models.DiskSku(name=storage_account_type)
storage = self.multi_disk_models.DiskSku(name=storage_account_type)
disk_params['sku'] = storage
disk_params['disk_size_gb'] = disk_size_gb
creation_data['create_option'] = self.disk_models.DiskCreateOption.empty
creation_data['create_option'] = self.multi_disk_models.DiskCreateOption.empty
if create_option == 'import':
creation_data['create_option'] = self.disk_models.DiskCreateOption.import_enum
creation_data['create_option'] = self.multi_disk_models.DiskCreateOption.import_enum
creation_data['source_uri'] = source_uri
creation_data['storage_account_id'] = storage_account_id
elif create_option == 'copy':
creation_data['create_option'] = self.disk_models.DiskCreateOption.copy
creation_data['create_option'] = self.multi_disk_models.DiskCreateOption.copy
creation_data['source_resource_id'] = source_uri
if os_type:
disk_params['os_type'] = self.disk_models.OperatingSystemTypes(os_type.capitalize())
disk_params['os_type'] = self.multi_disk_models.OperatingSystemTypes(os_type.capitalize())
else:
disk_params['os_type'] = None
if max_shares:
Expand Down Expand Up @@ -629,15 +629,15 @@ def create_attachment_configuration(self, vm, disks):
lun = item.lun

# prepare the data disk
params = self.disk_models.ManagedDiskParameters(id=disk_instance.get('id'), storage_account_type=disk_instance.get('storage_account_type'))
params = self.multi_disk_models.ManagedDiskParameters(id=disk_instance.get('id'), storage_account_type=disk_instance.get('storage_account_type'))
attach_caching = managed_disk.get("attach_caching")
caching_options = self.disk_models.CachingTypes[attach_caching] if attach_caching and attach_caching != '' else None
caching_options = self.multi_disk_models.CachingTypes[attach_caching] if attach_caching and attach_caching != '' else None

# pylint: disable=missing-kwoa
data_disk = self.disk_models.DataDisk(lun=lun,
create_option=self.compute_models.DiskCreateOptionTypes.attach,
managed_disk=params,
caching=caching_options)
data_disk = self.multi_disk_models.DataDisk(lun=lun,
create_option=self.compute_models.DiskCreateOptionTypes.attach,
managed_disk=params,
caching=caching_options)
vm.storage_profile.data_disks.append(data_disk)
return vm_id["resource_group"], vm_id["resource_name"], vm

Expand All @@ -663,7 +663,7 @@ def create_or_update_disks(self, disks_to_create):
resource_group = disk_info.get("resource_group")
name = disk_info.get("name")
try:
poller = self.disk_client.disks.begin_create_or_update(resource_group, name, disk)
poller = self.multi_disk_client.disks.begin_create_or_update(resource_group, name, disk)
pollers.append(poller)
except Exception as e:
self.fail("Error creating the managed disk {0}/{1}: {2}".format(resource_group, name, str(e)))
Expand All @@ -681,7 +681,7 @@ def is_different(self, zone, max_shares, found_disk, new_disk):
if not found_disk['disk_size_gb'] == new_disk['disk_size_gb']:
resp = True
if new_disk.get('os_type'):
if found_disk['os_type'] is None or not self.disk_models.OperatingSystemTypes(found_disk['os_type'].capitalize()) == new_disk['os_type']:
if found_disk['os_type'] is None or not self.multi_disk_models.OperatingSystemTypes(found_disk['os_type'].capitalize()) == new_disk['os_type']:
resp = True
if new_disk.get('sku'):
if not found_disk['storage_account_type'] == new_disk['sku'].name:
Expand All @@ -704,7 +704,7 @@ def delete_disks(self, ids):
try:
disk = parse_resource_id(disk_id)
resource_group, name = disk.get("resource_group"), disk.get("resource_name")
poller = self.disk_client.disks.begin_delete(resource_group, name)
poller = self.multi_disk_client.disks.begin_delete(resource_group, name)
pollers.append(poller)
except Exception as e:
self.fail("Error deleting the managed disk {0}/{1}: {2}".format(resource_group, name, str(e)))
Expand All @@ -722,7 +722,7 @@ def update_virtual_machines(self, config):

def get_managed_disk(self, resource_group, name):
try:
resp = self.disk_client.disks.get(resource_group, name)
resp = self.multi_disk_client.disks.get(resource_group, name)
return managed_disk_to_dict(resp)
except ResourceNotFoundError:
self.log("Did not find managed disk {0}/{1}".format(resource_group, name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
- name: Create public IP address
azure_rm_publicipaddress:
resource_group: "{{ resource_group }}"
allocation_method: Dynamic
allocation_method: Static
sku: standard
name: "{{ pubipname }}"

- name: Create a virtual network gateway
Expand Down

0 comments on commit df5a444

Please sign in to comment.