Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new parameters support to azure_rm_manageddisk #1741

Merged
merged 6 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugins/module_utils/azure_rm_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,13 +1135,13 @@ def disk_client(self):
if not self._disk_client:
self._disk_client = self.get_mgmt_svc_client(ComputeManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager,
api_version='2021-04-01')
api_version='2023-04-02')
return self._disk_client

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

@property
def diskencryptionset_client(self):
Expand Down
95 changes: 92 additions & 3 deletions plugins/modules/azure_rm_manageddisk.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
- StandardSSD_LRS
- StandardSSD_ZRS
- Premium_LRS
- PremiumV2_LRS
- Premium_ZRS
- UltraSSD_LRS
create_option:
Expand Down Expand Up @@ -149,6 +150,28 @@
- The logical unit number for data disk.
- This value is used to identify data disks within the VM and therefore must be unique for each data disk attached to a VM.
type: int
disk_iops_read_write:
description:
- The number of IOPS allowed for this disk.
- Only settable for I(storage_account_type=UltraSSD_LRS) disks.
- One operation can transfer between 4k and 256k bytes.
type: int
disk_m_bps_read_write:
description:
- The bandwidth allowed for this disk.
- Only settable for I(storage_account_type=UltraSSD_LRS) disks.
- One operation can transfer between 4k and 256k bytes.
type: int
disk_iops_read_only:
description:
- The total throughput (MBps) that will be allowed across all VMs mounting the shared disk as ReadOnly.
- One operation can transfer between 4k and 256k bytes.
type: int
disk_m_bps_read_only:
description:
- The total throughput (MBps) that will be allowed across all VMs mounting the shared disk as ReadOnly.
- MBps means millions of bytes per second - MB here uses the ISO notation, of powers of 10.
type: int

extends_documentation_fragment:
- azure.azcollection.azure
Expand Down Expand Up @@ -283,6 +306,36 @@
- Tags to assign to the managed disk.
type: dict
sample: { "tag": "value" }
disk_iops_read_write:
description:
- The number of IOPS allowed for this disk.
- Only settable for I(storage_account_type=UltraSSD_LRS) disks.
- One operation can transfer between 4k and 256k bytes.
type: int
returned: always
sample: 200
disk_m_bps_read_write:
description:
- The bandwidth allowed for this disk.
- Only settable for I(storage_account_type=UltraSSD_LRS) disks.
- One operation can transfer between 4k and 256k bytes.
type: int
returned: always
sample: 30
disk_iops_read_only:
description:
- The total throughput (MBps) that will be allowed across all VMs mounting the shared disk as ReadOnly.
- One operation can transfer between 4k and 256k bytes.
type: int
returned: always
sample: 200
disk_m_bps_read_only:
description:
- The total throughput (MBps) that will be allowed across all VMs mounting the shared disk as ReadOnly.
- MBps means millions of bytes per second - MB here uses the ISO notation, of powers of 10.
type: int
returned: always
sample: 30
changed:
description:
- Whether or not the resource has changed.
Expand Down Expand Up @@ -324,7 +377,11 @@ def managed_disk_to_dict(managed_disk):
managed_by=managed_disk.managed_by,
max_shares=managed_disk.max_shares,
managed_by_extended=managed_disk.managed_by_extended,
zone=managed_disk.zones[0] if managed_disk.zones and len(managed_disk.zones) > 0 else ''
zone=managed_disk.zones[0] if managed_disk.zones and len(managed_disk.zones) > 0 else '',
disk_iops_read_write=managed_disk.disk_iops_read_write,
disk_m_bps_read_write=managed_disk.disk_m_bps_read_write,
disk_iops_read_only=managed_disk.disk_iops_read_only,
disk_m_bps_read_only=managed_disk.disk_m_bps_read_only,
)


Expand All @@ -351,7 +408,7 @@ def __init__(self):
),
storage_account_type=dict(
type='str',
choices=['Standard_LRS', 'StandardSSD_LRS', 'StandardSSD_ZRS', 'Premium_LRS', 'Premium_ZRS', 'UltraSSD_LRS']
choices=['Standard_LRS', 'StandardSSD_LRS', 'StandardSSD_ZRS', 'Premium_LRS', 'Premium_ZRS', 'UltraSSD_LRS', 'PremiumV2_LRS']
),
create_option=dict(
type='str',
Expand Down Expand Up @@ -392,7 +449,19 @@ def __init__(self):
type='list',
elements='dict',
options=managed_by_extended_spec
)
),
disk_iops_read_only=dict(
type='int'
),
disk_iops_read_write=dict(
type='int'
),
disk_m_bps_read_only=dict(
type='int'
),
disk_m_bps_read_write=dict(
type='int'
),
)
required_if = [
('create_option', 'import', ['source_uri', 'storage_account_id']),
Expand All @@ -419,6 +488,10 @@ def __init__(self):
self.lun = None
self.max_shares = None
self.managed_by_extended = None
self.disk_iops_read_write = None
self.disk_m_bps_read_write = None
self.disk_iops_read_only = None
self.disk_m_bps_read_only = None

mutually_exclusive = [['managed_by_extended', 'managed_by']]

Expand Down Expand Up @@ -592,6 +665,14 @@ def generate_managed_disk_property(self):
disk_params['os_type'] = None
if self.max_shares:
disk_params['max_shares'] = self.max_shares
if self.disk_m_bps_read_only is not None:
disk_params['disk_m_bps_read_only'] = self.disk_m_bps_read_only
if self.disk_m_bps_read_write is not None:
disk_params['disk_m_bps_read_write'] = self.disk_m_bps_read_write
if self.disk_iops_read_write is not None:
disk_params['disk_iops_read_write'] = self.disk_iops_read_write
if self.disk_iops_read_only is not None:
disk_params['disk_iops_read_only'] = self.disk_iops_read_only
disk_params['creation_data'] = creation_data
return disk_params

Expand Down Expand Up @@ -633,6 +714,14 @@ def is_different(self, found_disk, new_disk):
if self.max_shares is not None:
if not found_disk['max_shares'] == self.max_shares:
resp = True
if self.disk_iops_read_write is not None and found_disk['disk_iops_read_write'] != self.disk_iops_read_write:
resp = True
if self.disk_m_bps_read_write is not None and found_disk['disk_m_bps_read_write'] != self.disk_m_bps_read_write:
resp = True
if self.disk_iops_read_only is not None and found_disk['disk_iops_read_only'] != self.disk_iops_read_only:
resp = True
if self.disk_m_bps_read_only is not None and found_disk['disk_m_bps_read_only'] != self.disk_m_bps_read_only:
resp = True
return resp

def delete_managed_disk(self):
Expand Down
36 changes: 35 additions & 1 deletion plugins/modules/azure_rm_manageddisk_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,36 @@
- The time the disk was created.
type: str
sample: "2018-01-01T11:08:15.338648900:00"
disk_iops_read_write:
description:
- The number of IOPS allowed for this disk.
- Only settable for I(storage_account_type=UltraSSD_LRS) disks.
- One operation can transfer between 4k and 256k bytes.
type: int
returned: always
sample: 200
disk_m_bps_read_write:
description:
- The bandwidth allowed for this disk.
- Only settable for I(storage_account_type=UltraSSD_LRS) disks.
- One operation can transfer between 4k and 256k bytes.
type: int
returned: always
sample: 30
disk_iops_read_only:
description:
- The total throughput (MBps) that will be allowed across all VMs mounting the shared disk as ReadOnly.
- One operation can transfer between 4k and 256k bytes.
type: int
returned: always
sample: 200
disk_m_bps_read_only:
description:
- The total throughput (MBps) that will be allowed across all VMs mounting the shared disk as ReadOnly.
- MBps means millions of bytes per second - MB here uses the ISO notation, of powers of 10.
type: int
returned: always
sample: 30
'''

from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
Expand Down Expand Up @@ -261,7 +291,11 @@ def managed_disk_to_dict(self, managed_disk):
max_shares=managed_disk.max_shares,
managed_by_extended=managed_disk.managed_by_extended,
zone=managed_disk.zones[0] if managed_disk.zones and len(managed_disk.zones) > 0 else '',
time_created=managed_disk.time_created.isoformat() if managed_disk.time_created else None
time_created=managed_disk.time_created.isoformat() if managed_disk.time_created else None,
disk_iops_read_write=managed_disk.disk_iops_read_write,
disk_m_bps_read_write=managed_disk.disk_m_bps_read_write,
disk_iops_read_only=managed_disk.disk_iops_read_only,
disk_m_bps_read_only=managed_disk.disk_m_bps_read_only,
)


Expand Down
67 changes: 67 additions & 0 deletions tests/integration/targets/azure_rm_manageddisk/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,72 @@
- output.ansible_info.azure_managed_disk[0].storage_account_type == "Premium_ZRS"
- output.ansible_info.azure_managed_disk[0].disk_size_gb == 2

- name: Create new managed disk with throught parameters
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}6"
storage_account_type: UltraSSD_LRS
disk_size_gb: 4
disk_iops_read_only: 200
disk_m_bps_read_only: 30
disk_m_bps_read_write: 30
disk_iops_read_write: 200
register: output

- name: Assert the managed disk Created
ansible.builtin.assert:
that:
- output.changed

- name: Create new managed disk with throught parameters(Idempotent Test)
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}6"
storage_account_type: UltraSSD_LRS
disk_size_gb: 4
disk_iops_read_only: 200
disk_m_bps_read_only: 30
disk_m_bps_read_write: 30
disk_iops_read_write: 200
register: output

- name: Assert the managed disk no change
ansible.builtin.assert:
that:
- not output.changed

- name: Update the managed disk
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}6"
storage_account_type: UltraSSD_LRS
disk_size_gb: 4
disk_iops_read_only: 300
disk_m_bps_read_only: 60
disk_m_bps_read_write: 60
disk_iops_read_write: 300
register: output

- name: Assert the managed disk updated
ansible.builtin.assert:
that:
- output.changed

- name: Get the managed disk facts
azure_rm_manageddisk_info:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}6"
register: output

- name: Assert the managed disk facts
ansible.builtin.assert:
that:
- output.ansible_info.azure_managed_disk[0].storage_account_type == "UltraSSD_LRS"
- output.ansible_info.azure_managed_disk[0].disk_iops_read_only == 300
- output.ansible_info.azure_managed_disk[0].disk_m_bps_read_only == 60
- output.ansible_info.azure_managed_disk[0].disk_m_bps_read_write == 60
- output.ansible_info.azure_managed_disk[0].disk_iops_read_write == 300

- name: Delete managed disk (Check Mode)
azure_rm_manageddisk:
resource_group: "{{ resource_group }}"
Expand All @@ -252,6 +318,7 @@
- 3
- 4
- 5
- 6

- name: Delete virtual machine
azure_rm_virtualmachine:
Expand Down