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 more parameters manageddisk #1833

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
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
197 changes: 192 additions & 5 deletions plugins/modules/azure_rm_manageddisk.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@
- empty
- import
- copy
- upload
- fromimage
- restore
- copystart
- importsecure
- uploadpreparedsecure
- copyfromsansnapshot
storage_account_id:
description:
- The full path to the storage account the image is to be imported from.
Expand Down Expand Up @@ -218,6 +225,52 @@
description:
- ARM ID of the DiskAccess resource for using private endpoints on disks.
type: str
performance_plus:
description:
- Set this flag to true to get a boost on the performance target of the disk deployed, see here on the respective performance target.
- This flag can only be set on disk creation time and cannot be disabled after enabled.
type: bool
upload_size_bytes:
description:
- If I(create_option=upload), this is the size of the contents of the upload including the VHD footer.
- This value should be between 20972032 (20 MiB + 512 bytes for the VHD footer) and 35183298347520 bytes (32 TiB + 512 bytes for the VHD footer).
type: int
disk_image_reference:
description:
- Disk source information for PIR or user images or Gallery Image.
type: dict
suboptions:
id:
description:
- A relative uri containing either a Platform Image Repository, user image, or Azure Compute Gallery image reference.
type: str
shared_gallery_image_id:
description:
- A relative uri containing a direct shared Azure Compute Gallery image reference.
type: str
community_gallery_image_id:
description:
- A relative uri containing a community Azure Compute Gallery image reference.
type: str
logical_sector_size:
description:
- Logical sector size in bytes for Ultra disks.
- Supported values are 512 ad 4096. 4096 is the default.
type: int
default: 4096
security_data_uri:
description:
- If I(create_option=importsecure), this is the URI of a blob to be imported into VM guest state.
type: str
elastic_san_resource_id:
description:
- Required if I(create_option=copyfromsansnapshot).
- This is the ARM id of the source elastic san volume snapshot.
type: str
source_resource_id:
description:
- If I(create_option=copy), this is the ARM id of the source snapshot or disk.
type: str
extends_documentation_fragment:
- azure.azcollection.azure
- azure.azcollection.azure_tags
Expand All @@ -244,6 +297,16 @@
os_type: windows
storage_account_type: Premium_LRS

- name: Create managed disk with I(create_option=upload)
azure_rm_manageddisk:
resource_group: myResourceGroup
name: mymanageddisk
storage_account_type: "Standard_LRS"
upload_size_bytes: 20972032
network_access_policy: DenyAll
public_network_access: Disabled
create_option: upload

- name: Mount the managed disk to VM
azure_rm_manageddisk:
name: mymanageddisk
Expand Down Expand Up @@ -404,6 +467,48 @@
type: str
returned: always
sample: '/subscriptions/*********/resourceGroups/myRG/providers/Microsoft.Compute/diskAccesses/diskacc'
performance_plus:
description:
- The flag of the performance target of the disk deployed.
type: bool
returned: always
sample: False
upload_size_bytes:
description:
- This is the size of the contents of the upload including the VHD footer.
type: int
returned: always
sample: None
disk_image_reference:
description:
- Disk source information for PIR or user images or Gallery Image.
type: dict
returned: always
sample: None
logical_sector_size:
description:
- Logical sector size in bytes for Ultra disks.
type: int
returned: always
sample: None
security_data_uri:
description:
- This is the URI of a blob to be imported into VM guest state.
type: str
returned: always
sample: None
elastic_san_resource_id:
description:
- This is the ARM id of the source elastic san volume snapshot.
type: str
returned: always
sample: None
source_resource_id:
description:
- This is the ARM id of the source snapshot or disk.
type: str
returned: always
sample: None
changed:
description:
- Whether or not the resource has changed.
Expand Down Expand Up @@ -453,7 +558,23 @@ def managed_disk_to_dict(managed_disk):
tier=managed_disk.tier,
public_network_access=managed_disk.public_network_access,
network_access_policy=managed_disk.network_access_policy,
disk_access_id=managed_disk.disk_access_id
disk_access_id=managed_disk.disk_access_id,
storage_account_id=create_data.storage_account_id,
upload_size_bytes=create_data.upload_size_bytes,
logical_sector_size=create_data.logical_sector_size,
security_data_uri=create_data.security_data_uri,
performance_plus=create_data.performance_plus,
elastic_san_resource_id=create_data.elastic_san_resource_id,
gallery_image_reference=dict(
id=create_data.gallery_image_reference.id,
shared_gallery_image_id=create_data.gallery_image_reference.shared_gallery_image_id,
community_gallery_image_id=create_data.gallery_image_reference.community_gallery_image_id
) if create_data.gallery_image_reference is not None else None,
image_reference=dict(
id=create_data.gallery_image_reference.id,
shared_gallery_image_id=create_data.gallery_image_reference.shared_gallery_image_id,
community_gallery_image_id=create_data.gallery_image_reference.community_gallery_image_id
) if create_data.image_reference is not None else None
)


Expand Down Expand Up @@ -484,7 +605,8 @@ def __init__(self):
),
create_option=dict(
type='str',
choices=['empty', 'import', 'copy']
choices=['empty', 'import', 'copy', 'upload', 'fromimage', 'restore', 'copystart', 'importsecure',
'uploadpreparedsecure', 'copyfromsansnapshot']
),
storage_account_id=dict(
type='str'
Expand Down Expand Up @@ -551,12 +673,39 @@ def __init__(self):
),
disk_access_id=dict(
type='str'
),
performance_plus=dict(type='bool'),
upload_size_bytes=dict(type='int'),
disk_image_reference=dict(
type='dict',
options=dict(
id=dict(type='str'),
shared_gallery_image_id=dict(type='str'),
community_gallery_image_id=dict(type='str')
)
),
logical_sector_size=dict(
type='int',
default=4096
),
security_data_uri=dict(
type='str'
),
elastic_san_resource_id=dict(
type='str'
),
source_resource_id=dict(
type='str'
)
)
required_if = [
('create_option', 'import', ['source_uri', 'storage_account_id']),
('create_option', 'copy', ['source_uri']),
('create_option', 'copy', ['source_resource_id']),
('create_option', 'empty', ['disk_size_gb']),
('create_option', 'upload', ['upload_size_bytes']),
('create_option', 'fromimage', ['disk_image_reference']),
('create_option', 'importsecure', ['security_data_uri']),
('create_option', 'copyfromsansnapshot', ['elastic_san_resource_id']),
('network_access_policy', 'AllowPrivate', ['disk_access_id'])
]
self.results = dict(
Expand Down Expand Up @@ -588,6 +737,9 @@ def __init__(self):
self.network_access_policy = None
self.write_accelerator_enabled = None
self.disk_access_id = None
self.performance_plus = None
self.upload_size_bytes = None
self.source_resource_id = None

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

Expand Down Expand Up @@ -754,14 +906,49 @@ def generate_managed_disk_property(self):
storage_account_type = self.disk_models.DiskSku(name=self.storage_account_type)
disk_params['sku'] = storage_account_type
disk_params['disk_size_gb'] = self.disk_size_gb
creation_data['create_option'] = self.disk_models.DiskCreateOption.empty

if self.create_option == 'import':
creation_data['create_option'] = self.disk_models.DiskCreateOption.import_enum
creation_data['source_uri'] = self.source_uri
creation_data['storage_account_id'] = self.storage_account_id
elif self.create_option == 'copy':
creation_data['create_option'] = self.disk_models.DiskCreateOption.copy
creation_data['source_resource_id'] = self.source_uri
creation_data['source_resource_id'] = self.source_resource_id
elif self.create_option == 'upload':
creation_data['create_option'] = self.disk_models.DiskCreateOption.upload
creation_data['performance_plus'] = self.performance_plus
creation_data['upload_size_bytes'] = self.upload_size_bytes
elif self.create_option == 'fromimage':
creation_data['create_option'] = self.disk_models.DiskCreateOption.FromImage
if self.disk_image_reference.get('id') is not None:
image_reference = self.disk_models.ImageDiskReference(id=self.disk_image_reference.get('id'))
creation_data['image_reference'] = image_reference
else:
image_reference = self.disk_models.ImageDiskReference(shared_gallery_image_id=self.disk_image_reference.get('shared_gallery_image_id'),
community_gallery_image_id=self.disk_image_reference.get('community_gallery_image_id'))
creation_data['gallery_image_reference'] = image_reference

elif self.create_option == 'restore':
creation_data['create_option'] = self.disk_models.DiskCreateOption.Restore
pass
elif self.create_option == 'copystart':
creation_data['create_option'] = self.disk_models.DiskCreateOption.CopyStart
pass
elif self.create_option == 'importsecure':
creation_data['create_option'] = self.disk_models.DiskCreateOption.ImportSecure
creation_data['source_uri'] = self.source_uri
creation_data['storage_account_id'] = self.storage_account_id
creation_data['security_data_uri'] = self.security_data_uri
elif self.create_option == 'uploadpreparedsecure':
creation_data['create_option'] = self.disk_models.DiskCreateOption.UploadPreparedSecure
creation_data['upload_size_bytes'] = self.upload_size_bytes
elif self.create_option == 'copyfromsansnapshot':
creation_data['create_option'] = self.disk_models.DiskCreateOption.CopyFromSanSnapshot
creation_data['elastic_san_resource_id'] = self.elastic_san_resource_id
else:
creation_data['create_option'] = self.disk_models.DiskCreateOption.empty
creation_data['logical_sector_size'] = self.logical_sector_size
creation_data['performance_plus'] = self.performance_plus
if self.os_type:
disk_params['os_type'] = self.disk_models.OperatingSystemTypes(self.os_type.capitalize())
else:
Expand Down
60 changes: 59 additions & 1 deletion plugins/modules/azure_rm_manageddisk_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,48 @@
type: str
returned: always
sample: '/subscriptions/*********/resourceGroups/myRG/providers/Microsoft.Compute/diskAccesses/diskacc'
performance_plus:
description:
- The flag of the performance target of the disk deployed.
type: bool
returned: always
sample: False
upload_size_bytes:
description:
- This is the size of the contents of the upload including the VHD footer.
type: int
returned: always
sample: None
disk_image_reference:
description:
- Disk source information for PIR or user images or Gallery Image.
type: dict
returned: always
sample: None
logical_sector_size:
description:
- Logical sector size in bytes for Ultra disks.
type: int
returned: always
sample: None
security_data_uri:
description:
- This is the URI of a blob to be imported into VM guest state.
type: str
returned: always
sample: None
elastic_san_resource_id:
description:
- This is the ARM id of the source elastic san volume snapshot.
type: str
returned: always
sample: None
source_resource_id:
description:
- This is the ARM id of the source snapshot or disk.
type: str
returned: always
sample: None
'''

from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
Expand Down Expand Up @@ -323,7 +365,23 @@ def managed_disk_to_dict(self, managed_disk):
tier=managed_disk.tier,
network_access_policy=managed_disk.network_access_policy,
public_network_access=managed_disk.public_network_access,
disk_access_id=managed_disk.disk_access_id
disk_access_id=managed_disk.disk_access_id,
storage_account_id=create_data.storage_account_id,
upload_size_bytes=create_data.upload_size_bytes,
logical_sector_size=create_data.logical_sector_size,
security_data_uri=create_data.security_data_uri,
performance_plus=create_data.performance_plus,
elastic_san_resource_id=create_data.elastic_san_resource_id,
gallery_image_reference=dict(
id=create_data.gallery_image_reference.id,
shared_gallery_image_id=create_data.gallery_image_reference.shared_gallery_image_id,
community_gallery_image_id=create_data.gallery_image_reference.community_gallery_image_id
) if create_data.gallery_image_reference is not None else None,
image_reference=dict(
id=create_data.gallery_image_reference.id,
shared_gallery_image_id=create_data.gallery_image_reference.shared_gallery_image_id,
community_gallery_image_id=create_data.gallery_image_reference.community_gallery_image_id
) if create_data.image_reference is not None else None
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}2"
create_option: "copy"
source_uri: "{{ output.state.id }}"
source_resource_id: "{{ output.state.id }}"
disk_size_gb: 1
register: disk2

Expand Down