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 support for write_accelerator_enabled #1808

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

Fred-sun
Copy link
Collaborator

@Fred-sun Fred-sun commented Jan 20, 2025

SUMMARY

Add support 'write_accelerator_enabled', try to fixes #430, #1811

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

azure_rm_manageddisk.py
azure_rm_virtualmachine.py

ADDITIONAL INFORMATION

@Fred-sun Fred-sun changed the title Add support 'write_accelerator_enabled' Add support for write_accelerator_enabled Jan 20, 2025
@unkaputtbar112
Copy link

@Fred-sun thanks for your work, here are my tests:

First I create a disk with the Azure.Azcollection Collection 3.1.0:

Playbook - need to set environment variables before and replace '':

---
- name: 'test write accelerator on disk'
  hosts: localhost
  gather_facts: false
  tasks:
    - name: 'Create managed disk with write accelerator'
      azure.azcollection.azure_rm_manageddisk:
        name: '_DataDisk_write_accelerator_0'
        location: 'westeurope'
        resource_group: '<cleaned>'
        create_option: 'empty'
        storage_account_type: 'Premium_LRS'
        disk_size_gb: 256
        attach_caching: 'read_only'
          #        write_accelerator_enabled: True
        managed_by: '<cleaned>'
        zone: 2

    - name: 'Fetch info of managed disk'
      azure.azcollection.azure_rm_manageddisk_info:
        name: '_DataDisk_write_accelerator_0'
        resource_group: '<cleaned>'
      register: manageddisk_info

    - debug:
        var: manageddisk_info

Works, output looks like this:

[~]$ ansible-playbook azure-write-accel.yml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [test write accelerator on disk] *******************************************************************************************************************************************************

TASK [Create managed disk with write accelerator] *******************************************************************************************************************************************
changed: [localhost]

TASK [Fetch info of managed disk] ***********************************************************************************************************************************************************
ok: [localhost]

TASK [debug] ********************************************************************************************************************************************************************************
ok: [localhost] => {
    "manageddisk_info": {
        "ansible_info": {
            "azure_managed_disk": [
                {
                    "create_option": "empty",
                    "disk_iops_read_only": null,
                    "disk_iops_read_write": 1100,
                    "disk_m_bps_read_only": null,
                    "disk_m_bps_read_write": 125,
                    "disk_size_gb": 256,
                    "id": "<cleaned>_DataDisk_write_accelerator_0",
                    "location": "westeurope",
                    "managed_by": "<cleaned>",
                    "managed_by_extended": null,
                    "max_shares": null,
                    "name": "_DataDisk_write_accelerator_0",
                    "os_type": null,
                    "source_uri": null,
                    "storage_account_type": "Premium_LRS",
                    "tags": null,
                    "time_created": "2025-01-20T09:01:40.503007+00:00",
                    "zone": "2"
                }
            ]
        },
        "changed": false,
        "failed": false
    }
}

PLAY RECAP **********************************************************************************************************************************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

executing it a second time (testing idempotence):

[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [test write accelerator on disk] *******************************************************************************************************************************************************

TASK [Create managed disk with write accelerator] *******************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: module 'azure.mgmt.compute.v2023_04_02.models' has no attribute 'CachingTypes'
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/home/<cleaned>/.ansible/tmp/ansible-tmp-1737363751.8698359-59352-189127815929536/AnsiballZ_azure_rm_manageddisk.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/<cleaned>/.ansible/tmp/ansible-tmp-1737363751.8698359-59352-189127815929536/AnsiballZ_azure_rm_manageddisk.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/<cleaned>/.ansible/tmp/ansible-tmp-1737363751.8698359-59352-189127815929536/AnsiballZ_azure_rm_manageddisk.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.azure.azcollection.plugins.modules.azure_rm_manageddisk', init_globals=dict(_module_fqn='ansible_collections.azure.azcollection.plugins.modules.azure_rm_manageddisk', _modlib_path=modlib_path),\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _run_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/tmp/ansible_azure.azcollection.azure_rm_manageddisk_payload_6t16vpvh/ansible_azure.azcollection.azure_rm_manageddisk_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_manageddisk.py\", line 771, in <module>\n  File \"/tmp/ansible_azure.azcollection.azure_rm_manageddisk_payload_6t16vpvh/ansible_azure.azcollection.azure_rm_manageddisk_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_manageddisk.py\", line 767, in main\n  File \"/tmp/ansible_azure.azcollection.azure_rm_manageddisk_payload_6t16vpvh/ansible_azure.azcollection.azure_rm_manageddisk_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_manageddisk.py\", line 505, in __init__\n  File \"/tmp/ansible_azure.azcollection.azure_rm_manageddisk_payload_6t16vpvh/ansible_azure.azcollection.azure_rm_manageddisk_payload.zip/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py\", line 482, in __init__\n  File \"/tmp/ansible_azure.azcollection.azure_rm_manageddisk_payload_6t16vpvh/ansible_azure.azcollection.azure_rm_manageddisk_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_manageddisk.py\", line 578, in exec_module\n  File \"/tmp/ansible_azure.azcollection.azure_rm_manageddisk_payload_6t16vpvh/ansible_azure.azcollection.azure_rm_manageddisk_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_manageddisk.py\", line 757, in is_attach_caching_option_different\nAttributeError: module 'azure.mgmt.compute.v2023_04_02.models' has no attribute 'CachingTypes'\n", "module_stdout": "", "msg": "MODULE FAILURE: No start of json char found\nSee stdout/stderr for the exact error", "rc": 1}

PLAY RECAP **********************************************************************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

Well, let's ignore that for now, seems like another Bug/Issue.

I implement your changes and try from the start, playbook is the same, i just uncomment the "write_accelerator_enabled: True"-line. I've removed the disk manually in the Azure Portal inbetween.

First run:

[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [test write accelerator on disk] *******************************************************************************************************************************************************

TASK [Create managed disk with write accelerator] *******************************************************************************************************************************************
changed: [localhost]

TASK [Fetch info of managed disk] ***********************************************************************************************************************************************************
ok: [localhost]

TASK [debug] ********************************************************************************************************************************************************************************
ok: [localhost] => {
    "manageddisk_info": {
        "ansible_info": {
            "azure_managed_disk": [
                {
                    "create_option": "empty",
                    "disk_iops_read_only": null,
                    "disk_iops_read_write": 1100,
                    "disk_m_bps_read_only": null,
                    "disk_m_bps_read_write": 125,
                    "disk_size_gb": 256,
                    "id": "<cleaned>_DataDisk_write_accelerator_0",
                    "location": "westeurope",
                    "managed_by": "<cleaned>",
                    "managed_by_extended": null,
                    "max_shares": null,
                    "name": "_DataDisk_write_accelerator_0",
                    "os_type": null,
                    "source_uri": null,
                    "storage_account_type": "Premium_LRS",
                    "tags": null,
                    "time_created": "2025-01-20T09:13:11.334935+00:00",
                    "zone": "2"
                }
            ]
        },
        "changed": false,
        "failed": false
    }
}

PLAY RECAP **********************************************************************************************************************************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

The disk is created and attached successfully to a VM, with Write Accelerator enabled, shown in the Azure Portal:
image
The 2nd run fails as the test before, complaining about CachingTypes not in the version of the model.

However, the _info module misses the caching and the write_accelerator information.
I can work around that, using azure_rm_virtualmachine_info, quick & dirty playbook:

---
- name: 'fetch vminfo'
  hosts: localhost
  gather_facts: false
  tasks:
    - name: 'fetch vminfos'
      azure.azcollection.azure_rm_virtualmachine_info:
      register: azure_vms_info

    - name: 'set disk info'
      ansible.builtin.set_fact:
        azure_vm_disk_info: "{{ (azure_vms_info.vms | json_query(tmp_jq)).data_disks }}"
      vars:
        tmp_jq: "[?name=='<cleaned>'] | [0]"

    - debug:
        var: azure_vm_disk_info
...

Output:

    "azure_vm_disk_info": [
<shortened>
        {
            "caching": "ReadOnly",
            "disk_size_gb": null,
            "lun": 10,
            "managed_disk_id": "<cleaned>_DataDisk_write_accelerator_0",
            "managed_disk_type": null,
            "name": "_DataDisk_write_accelerator_0"
        }
    ]
}

While this shows the caching information, it doesn't show the write_accelerator information.
I suppose somewhere it should show up, either in the vm-info, or in the manageddisk-info.

@Fred-sun
Copy link
Collaborator Author

@unkaputtbar112 I have updated, Please take a try! Thanks!

@unkaputtbar112
Copy link

@Fred-sun thanks a lot for your work. :)

Now it works just fine, the output of azure_rm_virtualmachine_info looks now like this:

        {
            "caching": "ReadOnly",
            "disk_size_gb": null,
            "lun": 10,
            "managed_disk_id": "<cleaned>_DataDisk_write_accelerator_0",
            "managed_disk_type": null,
            "name": "_DataDisk_write_accelerator_0",
            "write_accelerator_enabled": true
        }

Just for reference, for the issue of re-running / changing "attach_caching" i've created following issue:
#1811

@Fred-sun Fred-sun added ready_for_review The PR has been modified and can be reviewed and merged medium_priority Medium priority labels Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
medium_priority Medium priority ready_for_review The PR has been modified and can be reviewed and merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support of Write Accelerator to azure_rm_manageddisk
3 participants