Add lun for azure_rm_manageddisk (#66153)

* add lun for azure_rm_manageddisk

* add whitespace

* Change condition
This commit is contained in:
Fred-sun 2020-01-23 20:51:20 +08:00 committed by ansibot
parent a589b10b26
commit eb3d081c11

View file

@ -115,6 +115,12 @@ options:
- 3
- ''
version_added: "2.8"
lun:
description:
- 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
version_added: '2.10'
extends_documentation_fragment:
- azure
@ -263,6 +269,9 @@ class AzureRMManagedDisk(AzureRMModuleBase):
attach_caching=dict(
type='str',
choices=['', 'read_only', 'read_write']
),
lun=dict(
type='int'
)
)
required_if = [
@ -286,6 +295,7 @@ class AzureRMManagedDisk(AzureRMModuleBase):
self.zone = None
self.managed_by = None
self.attach_caching = None
self.lun = None
super(AzureRMManagedDisk, self).__init__(
derived_arg_spec=self.module_arg_spec,
required_if=required_if,
@ -343,9 +353,12 @@ class AzureRMManagedDisk(AzureRMModuleBase):
def attach(self, vm_name, disk):
vm = self._get_vm(vm_name)
# find the lun
luns = ([d.lun for d in vm.storage_profile.data_disks]
if vm.storage_profile.data_disks else [])
lun = max(luns) + 1 if luns else 0
if self.lun:
lun = self.lun
else:
luns = ([d.lun for d in vm.storage_profile.data_disks]
if vm.storage_profile.data_disks else [])
lun = max(luns) + 1 if luns else 0
# prepare the data disk
params = self.compute_models.ManagedDiskParameters(id=disk.get('id'), storage_account_type=disk.get('storage_account_type'))