From eb3d081c1188c10a560b919f48ef9b517a0df65d Mon Sep 17 00:00:00 2001 From: Fred-sun <37327967+Fred-sun@users.noreply.github.com> Date: Thu, 23 Jan 2020 20:51:20 +0800 Subject: [PATCH] Add lun for azure_rm_manageddisk (#66153) * add lun for azure_rm_manageddisk * add whitespace * Change condition --- .../cloud/azure/azure_rm_manageddisk.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_manageddisk.py b/lib/ansible/modules/cloud/azure/azure_rm_manageddisk.py index 5ea2240d2f0..856cb6d722d 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_manageddisk.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_manageddisk.py @@ -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'))