
    VhN                         d dl mZmZmZ eZdZdZdZd dl	m
Z
 d dlmZ d dlmZmZ d dlmZmZmZ d	 Z G d
 de      Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functiona+  
module: proxmox_disk
short_description: Management of a disk of a Qemu(KVM) VM in a Proxmox VE cluster
version_added: 5.7.0
description:
  - Allows you to perform some supported operations on a disk in Qemu(KVM) Virtual Machines in a Proxmox VE cluster.
author: "Castor Sky (@castorsky) <csky57@gmail.com>"
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
  action_group:
    version_added: 9.0.0
options:
  name:
    description:
      - The unique name of the VM.
      - You can specify either O(name) or O(vmid) or both of them.
    type: str
  vmid:
    description:
      - The unique ID of the VM.
      - You can specify either O(vmid) or O(name) or both of them.
    type: int
  disk:
    description:
      - The disk key (V(unused[n]), V(ide[n]), V(sata[n]), V(scsi[n]) or V(virtio[n])) you want to operate on.
      - Disk buses (IDE, SATA and so on) have fixed ranges of V(n) that accepted by Proxmox API.
      - 'For IDE: 0-3; for SCSI: 0-30; for SATA: 0-5; for VirtIO: 0-15; for Unused: 0-255.'
    type: str
    required: true
  state:
    description:
      - Indicates desired state of the disk.
      - O(state=present) can be used to create, replace disk or update options in existing disk. It will create missing disk
        or update options in existing one by default. See the O(create) parameter description to control behavior of this
        option.
      - Some updates on options (like O(cache)) are not being applied instantly and require VM restart.
      - Use O(state=detached) to detach existing disk from VM but do not remove it entirely. When O(state=detached) and disk
        is V(unused[n]) it will be left in same state (not removed).
      - O(state=moved) may be used to change backing storage for the disk in bounds of the same VM or to send the disk to
        another VM (using the same backing storage).
      - O(state=resized) intended to change the disk size. As of Proxmox 7.2 you can only increase the disk size because shrinking
        disks is not supported by the PVE API and has to be done manually.
      - To entirely remove the disk from backing storage use O(state=absent).
    type: str
    choices: ['present', 'resized', 'detached', 'moved', 'absent']
    default: present
  create:
    description:
      - With O(create) flag you can control behavior of O(state=present).
      - When O(create=disabled) it will not create new disk (if not exists) but will update options in existing disk.
      - When O(create=regular) it will either create new disk (if not exists) or update options in existing disk.
      - When O(create=forced) it will always create new disk (if disk exists it will be detached and left unused).
    type: str
    choices: ['disabled', 'regular', 'forced']
    default: regular
  storage:
    description:
      - The drive's backing storage.
      - Used only when O(state) is V(present).
    type: str
  size:
    description:
      - Desired volume size in GB to allocate when O(state=present) (specify O(size) without suffix).
      - New (or additional) size of volume when O(state=resized). With the V(+) sign the value is added to the actual size
        of the volume and without it, the value is taken as an absolute one.
    type: str
  bwlimit:
    description:
      - Override I/O bandwidth limit (in KB/s).
      - Used only when O(state=moved).
    type: int
  delete_moved:
    description:
      - Delete the original disk after successful copy.
      - By default the original disk is kept as unused disk.
      - Used only when O(state=moved).
    type: bool
  target_disk:
    description:
      - The config key the disk will be moved to on the target VM (for example, V(ide0) or V(scsi1)).
      - Default is the source disk key.
      - Used only when O(state=moved).
    type: str
  target_storage:
    description:
      - Move the disk to this storage when O(state=moved).
      - You can move between storages only in scope of one VM.
      - Mutually exclusive with O(target_vmid).
      - Consider increasing O(timeout) in case of large disk images or slow storage backend.
    type: str
  target_vmid:
    description:
      - The (unique) ID of the VM where disk will be placed when O(state=moved).
      - You can move disk between VMs only when the same storage is used.
      - Mutually exclusive with O(target_vmid).
    type: int
  timeout:
    description:
      - Timeout in seconds to wait for slow operations such as importing disk or moving disk between storages.
      - Used only when O(state) is V(present) or V(moved).
    type: int
    default: 600
  aio:
    description:
      - AIO type to use.
    type: str
    choices: ['native', 'threads', 'io_uring']
  backup:
    description:
      - Whether the drive should be included when making backups.
    type: bool
  bps_max_length:
    description:
      - Maximum length of total r/w I/O bursts in seconds.
    type: int
  bps_rd_max_length:
    description:
      - Maximum length of read I/O bursts in seconds.
    type: int
  bps_wr_max_length:
    description:
      - Maximum length of write I/O bursts in seconds.
    type: int
  cache:
    description:
      - The drive's cache mode.
    type: str
    choices: ['none', 'writethrough', 'writeback', 'unsafe', 'directsync']
  cyls:
    description:
      - Force the drive's physical geometry to have a specific cylinder count.
    type: int
  detect_zeroes:
    description:
      - Control whether to detect and try to optimize writes of zeroes.
    type: bool
  discard:
    description:
      - Control whether to pass discard/trim requests to the underlying storage.
    type: str
    choices: ['ignore', 'on']
  format:
    description:
      - The drive's backing file's data format.
    type: str
    choices: ['raw', 'cow', 'qcow', 'qed', 'qcow2', 'vmdk', 'cloop']
  heads:
    description:
      - Force the drive's physical geometry to have a specific head count.
    type: int
  import_from:
    description:
      - Import volume from this existing one.
      - Volume string format.
      - V(<STORAGE>:<VMID>/<FULL_NAME>) or V(<ABSOLUTE_PATH>/<FULL_NAME>).
      - Attention! Only root can use absolute paths.
      - This parameter is mutually exclusive with O(size).
      - Increase O(timeout) parameter when importing large disk images or using slow storage.
    type: str
  iops:
    description:
      - Maximum total r/w I/O in operations per second.
      - You can specify either total limit or per operation (mutually exclusive with O(iops_rd) and O(iops_wr)).
    type: int
  iops_max:
    description:
      - Maximum unthrottled total r/w I/O pool in operations per second.
    type: int
  iops_max_length:
    description:
      - Maximum length of total r/w I/O bursts in seconds.
    type: int
  iops_rd:
    description:
      - Maximum read I/O in operations per second.
      - You can specify either read or total limit (mutually exclusive with O(iops)).
    type: int
  iops_rd_max:
    description:
      - Maximum unthrottled read I/O pool in operations per second.
    type: int
  iops_rd_max_length:
    description:
      - Maximum length of read I/O bursts in seconds.
    type: int
  iops_wr:
    description:
      - Maximum write I/O in operations per second.
      - You can specify either write or total limit (mutually exclusive with O(iops)).
    type: int
  iops_wr_max:
    description:
      - Maximum unthrottled write I/O pool in operations per second.
    type: int
  iops_wr_max_length:
    description:
      - Maximum length of write I/O bursts in seconds.
    type: int
  iothread:
    description:
      - Whether to use iothreads for this drive (only for SCSI and VirtIO).
    type: bool
  mbps:
    description:
      - Maximum total r/w speed in megabytes per second.
      - Can be fractional but use with caution - fractionals less than 1 are not supported officially.
      - You can specify either total limit or per operation (mutually exclusive with O(mbps_rd) and O(mbps_wr)).
    type: float
  mbps_max:
    description:
      - Maximum unthrottled total r/w pool in megabytes per second.
    type: float
  mbps_rd:
    description:
      - Maximum read speed in megabytes per second.
      - You can specify either read or total limit (mutually exclusive with O(mbps)).
    type: float
  mbps_rd_max:
    description:
      - Maximum unthrottled read pool in megabytes per second.
    type: float
  mbps_wr:
    description:
      - Maximum write speed in megabytes per second.
      - You can specify either write or total limit (mutually exclusive with O(mbps)).
    type: float
  mbps_wr_max:
    description:
      - Maximum unthrottled write pool in megabytes per second.
    type: float
  media:
    description:
      - The drive's media type.
    type: str
    choices: ['cdrom', 'disk']
  iso_image:
    description:
      - The ISO image to be mounted on the specified in O(disk) CD-ROM.
      - O(media=cdrom) needs to be specified for this option to work.
      - Use V(<STORAGE>:iso/<ISO_NAME>) to mount ISO.
      - Use V(cdrom) to access the physical CD/DVD drive.
      - Use V(none) to unmount image from existent CD-ROM or create empty CD-ROM drive.
    type: str
    version_added: 8.1.0
  queues:
    description:
      - Number of queues (SCSI only).
    type: int
  replicate:
    description:
      - Whether the drive should considered for replication jobs.
    type: bool
  rerror:
    description:
      - Read error action.
    type: str
    choices: ['ignore', 'report', 'stop']
  ro:
    description:
      - Whether the drive is read-only.
    type: bool
  scsiblock:
    description:
      - Whether to use scsi-block for full passthrough of host block device.
      - Can lead to I/O errors in combination with low memory or high memory fragmentation on host.
    type: bool
  secs:
    description:
      - Force the drive's physical geometry to have a specific sector count.
    type: int
  serial:
    description:
      - The drive's reported serial number, url-encoded, up to 20 bytes long.
    type: str
  shared:
    description:
      - Mark this locally-managed volume as available on all nodes.
      - This option does not share the volume automatically, it assumes it is shared already!
    type: bool
  snapshot:
    description:
      - Control qemu's snapshot mode feature.
      - If activated, changes made to the disk are temporary and will be discarded when the VM is shutdown.
    type: bool
  ssd:
    description:
      - Whether to expose this drive as an SSD, rather than a rotational hard disk.
    type: bool
  trans:
    description:
      - Force disk geometry bios translation mode.
    type: str
    choices: ['auto', 'lba', 'none']
  werror:
    description:
      - Write error action.
    type: str
    choices: ['enospc', 'ignore', 'report', 'stop']
  wwn:
    description:
      - The drive's worldwide name, encoded as 16 bytes hex string, prefixed by V(0x).
    type: str
extends_documentation_fragment:
  - community.general.proxmox.actiongroup_proxmox
  - community.general.proxmox.documentation
  - community.general.attributes
aJ	  
- name: Create new disk in VM (do not rewrite in case it exists already)
  community.general.proxmox_disk:
    api_host: node1
    api_user: root@pam
    api_token_id: token1
    api_token_secret: some-token-data
    name: vm-name
    disk: scsi3
    backup: true
    cache: none
    storage: local-zfs
    size: 5
    state: present

- name: Create new disk in VM (force rewrite in case it exists already)
  community.general.proxmox_disk:
    api_host: node1
    api_user: root@pam
    api_token_id: token1
    api_token_secret: some-token-data
    vmid: 101
    disk: scsi3
    format: qcow2
    storage: local
    size: 16
    create: forced
    state: present

- name: Update existing disk
  community.general.proxmox_disk:
    api_host: node1
    api_user: root@pam
    api_token_id: token1
    api_token_secret: some-token-data
    vmid: 101
    disk: ide0
    backup: false
    ro: true
    aio: native
    state: present

- name: Grow existing disk
  community.general.proxmox_disk:
    api_host: node1
    api_user: root@pam
    api_token_id: token1
    api_token_secret: some-token-data
    vmid: 101
    disk: sata4
    size: +5G
    state: resized

- name: Detach disk (leave it unused)
  community.general.proxmox_disk:
    api_host: node1
    api_user: root@pam
    api_token_id: token1
    api_token_secret: some-token-data
    name: vm-name
    disk: virtio0
    state: detached

- name: Move disk to another storage
  community.general.proxmox_disk:
    api_host: node1
    api_user: root@pam
    api_password: secret
    vmid: 101
    disk: scsi7
    target_storage: local
    format: qcow2
    state: moved

- name: Move disk from one VM to another
  community.general.proxmox_disk:
    api_host: node1
    api_user: root@pam
    api_token_id: token1
    api_token_secret: some-token-data
    vmid: 101
    disk: scsi7
    target_vmid: 201
    state: moved

- name: Remove disk permanently
  community.general.proxmox_disk:
    api_host: node1
    api_user: root@pam
    api_password: secret
    vmid: 101
    disk: scsi4
    state: absent

- name: Mount ISO image on CD-ROM (create drive if missing)
  community.general.proxmox_disk:
    api_host: node1
    api_user: root@pam
    api_token_id: token1
    api_token_secret: some-token-data
    vmid: 101
    disk: ide2
    media: cdrom
    iso_image: local:iso/favorite_distro_amd64.iso
    state: present
z
vmid:
  description: The VM vmid.
  returned: success
  type: int
  sample: 101
msg:
  description: A short message on what the module did.
  returned: always
  type: str
  sample: "Disk scsi3 created in VM 101"
)AnsibleModule)LooseVersion)proxmox_auth_argument_specProxmoxAnsible)compilematchsubc                 .   | j                  d      }|j                  d      }|dv rt        |ddd      }n.|j                  d      }|d   }|d   }t        |d|||      }|j                          |D ]  }|j                  d	      \  }}|||<    |S )
a  
    Transform Proxmox configuration string for disk element into dictionary which has
    volume option parsed in '{ storage }:{ volume }' format and other options parsed
    in '{ option }={ value }' format. This dictionary will be compared afterward with
    attributes that user passed to this module in playbook.

    config_string examples:
      - local-lvm:vm-100-disk-0,ssd=1,discard=on,size=25G
      - local:iso/new-vm-ignition.iso,media=cdrom,size=70k
      - none,media=cdrom
    :param config_string: Retrieved from Proxmox API configuration string
    :return: Dictionary with volume option divided into parts ('volume_name', 'storage_name', 'volume') 

        and other options as key:value.
    ,r   )nonecdromN)volumestorage_namevolume_namesize:   )r   r   r   =)splitpopdictsort)	config_stringconfigstorage_volumeconfig_currentr   r   optionkvs	            r/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/proxmox_disk.pydisk_conf_str_to_dictr$     s       %F ZZ]N**!	
 (--c2%a($Q'*K8%#
 KKM ||C 1q     c            
           e Zd Zg dZ e edd       edd       edd       edd       edd            Zd	 Zd
 Zd Z	d Z
y)ProxmoxDiskAnsible)*aiobackupbps_max_lengthbps_rd_max_lengthbps_wr_max_lengthcachecylsdetect_zeroesdiscardformatheadsimport_fromiopsiops_maxiops_max_lengthiops_rdiops_rd_maxiops_rd_max_lengthiops_wriops_wr_maxiops_wr_max_lengthiothreadmbpsmbps_maxmbps_rdmbps_rd_maxmbps_wrmbps_wr_maxmediaqueues	replicatererrorro	scsiblocksecsserialsharedsnapshotssdtranswerrorwwnr                  )idescsisatavirtiounusedc           	          | j                   j                  j                         D ci c]3  \  }}|,|| j                  v r|t	        |t
              rt        |      n|5 }}}|S c c}}w )N)moduleparamsitemscreate_update_fields
isinstanceboolint)selfr!   r"   r^   s       r#   get_create_attributesz(ProxmoxDiskAnsible.get_create_attributes  sj     **002
1}d&?&?!? At,s1v!3
 

 
s   8A%c                 >   | j                   j                  d   }|dk(  r||vrdd|d|dfS d}|dk(  r||vs|d	k(  r7| j                         }|j                  d
d      }| j                   j                  j	                  dd      }	|r&| j                   j                  d   ddd|}
d}d}n|	|	}
d}n| j                   j                  d   }
|
s| j                   j                  d       | j                   j                  j	                  d      dk7  r|
d| j                   j                  d   z  z  }
d}d}|j                         D ]  \  }}|
d|d|z  }
 | j                   j                  d   |
i}|dv r||v rd }| j                   j                  j	                  dd      }	t        ||         }| j                         }|j                  d
d       |	|	}
n|d!   }
|j                         D ]  \  }}|
d|d|z  }
 d"D ]  }|j                  |||   i        |	|	|d!<   |j                         D ci c]  \  }}|t        |       }}}||k(  r
dd|d#|fS | j                   j                  d   |
i} | j                  j                  |d$         j                  |      j                  j                  d)i }| j                  |d$   || j                   j                  d%         \  }}|r	d&||fz  fS |t         j"                  k(  rf| j                   j                  || j                  j                  |d$         j%                  |      j&                  j	                         dd' z         y| j                   j                  d(|z         yc c}}w )*a  Create a disk in the specified virtual machine. Check if creation is required,
        and if so, compile the disk configuration and create it by updating the virtual
        machine configuration. After calling the API function, wait for the result.

        :param disk: ID of the disk in format "<bus><number>".
        :param vmid: ID of the virtual machine where the disk will be created.
        :param vm: Name of the virtual machine where the disk will be created.
        :param vm_config: Configuration of the virtual machine.
        :return: (bool, string) Whether the task was successful or not
            and the message to return to Ansible.
        createdisabledFDisk z not found in VM z) and creation was disabled in parameters.z5Reached timeout. Last line in task before timeout: %sregularforcedr3   N	iso_imagestorager   0z,import-from=zMReached timeout while importing VM disk. Last line in task before timeout: %szDisk %s imported into VM %sz%CD-ROM was created on %s bus in VM %sz%The storage option must be specified.msgrD   r   z:%sr   zDisk %s created in VM %szLReached timeout while creating VM disk. Last line in task before timeout: %sr   r   disk)rh   rj   zDisk %s updated in VM %sr   )r   r   r   r   z is up to date in VM nodetimeoutTr   $Error occurred on task execution: %s )r]   r^   re   r   get	fail_jsonr_   r$   updatestrproxmox_apinodesqemur   postapi_task_completer	   TASK_TIMED_OUTtaskslog)rd   rq   vmidvm	vm_configrg   timeout_strplaybook_configimport_stringrl   
config_strok_strr!   r"   disk_config_to_applyproxmox_configr    current_task_idtask_successfail_reasons                       r#   create_diskzProxmoxDiskAnsible.create_disk
  s    ##H-ZD	$9cgimnnnMiD	$9v?Q"88:O+//tDM**..{DAI7;{{7I7I)7TVY[hi
m6&&
@![[//	:
!KK)).U)V;;%%))'2g=%4;;+=+=f+E"FFJ3l'--/ 01!Q//
0 %)KK$6$6v$>
#K ,,1B/F**..{DAI29T?CN"88:Ot4 $&
+H5
'--/ 01!Q//
0 L I&&v0F'GHI $,5)5D5J5J5LMTQq#a&yMOM 0$MMM$(KK$6$6v$>
#K S$**00F<AA$GNNSSkVjk$($:$:2f:X\XcXcXjXjktXu$v!k4,...n;;;%%#d&6&6&<&<RZ&H&N&N&_&c&c&g&g&ijlkl&mm &  %%*PS^*^%_' Ns   ;Nc                    t        ||         }|d   }t               }||d<   ||d<   | j                  j                  d   |d<   | j                  j                  d   |d<   | j                  j                  d   |d<   | j                  j                  d	   |d
<   | j                  j                  d   |d<   | j                  j                  j	                  dd      rdnd|d<   |j                         D 	ci c]  \  }}	|		||	 }}}	|j	                  dd      r$t        ||         }|d   |d   k(  rdd|d|dfS  | j                  j                  |d         j                  |      j                  j                  di |}
| j                  |d   |
| j                  j                  d         \  }}|rdd|d|d|fS |t        j                  k(  rf| j                  j                  d| j                  j                  |d         j                  |
      j                   j	                         dd z         y| j                  j                  d|z         yc c}	}w )a  Call the `move_disk` API function that moves the disk to another storage and wait for the result.

        :param disk: ID of disk in format "<bus><number>".
        :param vmid: ID of virtual machine which disk will be moved.
        :param vm: Name of virtual machine which disk will be moved.
        :param vm_config: Virtual machine configuration.
        :return: (bool, string) Whether the task was successful or not
            and the message to return to Ansible.
        r   rq   r   bwlimittarget_storagerm   target_diskztarget-disktarget_vmidztarget-vmidr1   delete_movedFr   r   deleteNri   z already at z storagerr   rs   Tz moved from VM z	 storage zVReached timeout while waiting for moving VM disk. Last line in task before timeout: %sro   rt   ru   )r$   r   r]   r^   rv   r_   rz   r{   r|   	move_diskr}   r~   r	   r   rw   r   r   )rd   rq   r   r   r   disk_configdisk_storager^   r!   r"   r   r   r   s                r#   r   zProxmoxDiskAnsible.move_diskh  sJ    ,IdO<">2vv KK..y9y KK../?@y $ 2 2= A} $ 2 2= A};;--h7x $ 2 2 6 6~u M1STx#)<<>C41aQ]!Q$CC::i'/	$@Ki K$??|TTTV$**00F<AA$GQQVV`Y_`$($:$:2f:X\XcXcXjXjktXu$v!k$l[[[n;;;%%p((..r&z:@@QUUYY[\^]^_` & 
 %%*PS^*^%_) Ds   4
I?Ic                    | j                   j                  d   }t        d|      s"| j                   j                  d|d|       t	        ||         }|d   }||k(  rdd|d|d	fS | j                         }|t        d
      k  rdn|j
                  d   }	|	dk\  r| j                  j                  |d         j                  |      j                  j                  ||      }
| j                  |d   |
| j                   j                  d         \  }}|r
dd|d|fS |t        j                  k(  rf| j                   j                  d| j                  j                  |d         j                  |
      j                   j#                         dd z         y| j                   j                  d|z         y| j                  j                  |d         j                  |      j                  j                  ||       dd|d|fS )a  Call the `resize` API function to change the disk size and wait for the result.

        :param disk: ID of disk in format "<bus><number>".
        :param vmid: ID of virtual machine which disk will be resized.
        :param vm: Name of virtual machine which disk will be resized.
        :param vm_config: Virtual machine configuration.
        :return: (Bool, string) Whether the task was successful or not
            and the message to return to Ansible.
        r   z^\+?\d+(\.\d+)?[KMGT]?$z#Unrecognized size pattern for disk : ro   Fri   z is already z sizez4.0   r      rr   )rq   r   rs   Tz resized in VM zIReached timeout while resizing disk. Last line in task before timeout: %sNr   rt   )r]   r^   r   rw   r$   versionr   rz   r{   r|   resizesetr~   r	   r   r   r   rv   )rd   rq   r   r   r   r   r   actual_sizer   pve_major_versionr   r   r   s                r#   resize_diskzProxmoxDiskAnsible.resize_disk  s    {{!!&)/6KK!!UY[_&`!a+IdO<!&);$EEE ,,.!(<+>!>AGOOTUDV!"..44RZ@EEdKRRVV\`gkVlO(,(>(>r&z?\`\g\g\n\nox\y(z%L+4FFF."?"??KK))g ,,222f:>DD_UYY]]_`babcd * 
 KK)).TWb.b)c""2f:.33D9@@DD$UYDZtTBBBr%   N)__name__
__module____qualname__r`   r   rangesupported_bus_num_rangesre   r   r   r   ru   r%   r#   r'   r'     s^      $!QK1b\1a[Q|Q} 
\`|+`Z$Cr%   r'   c                     t               } t        di dt        dg d      dt        d      dt        d	      d
t        d	      dt        d	      dt        dg d      dt        d	      dt        d      dt        dddg      dt        dg d      dt        d	      dt        d      dt        d	      dt        d	      dt        d	      dt        d	      dt        d	      dt        d	      dt        d	      dt        d	      dt        d	      d t        d      d!t        d      d"t        d#      d$t        d#      d%t        d#      d&t        d#      d't        d#      d(t        d#      d)t        dd*d+g      d,t        d	      d-t        d      d.t        dg d/      d0t        d      d1t        d      d2t        d	      d3t        d      d4t        d      d5t        d      d6t        d      d7t        dg d8      d9t        dg d:      d;t        d      d<t        d	      d=t        d      d>t        d      d?t        d	      d@t        d      dAt        d	dBC      dDt        d      dEt        d	      d+t        ddFG      dHt        d      dIt        d      dJt        dg dKdLM      dNt        dg dOdPM      }| j                  |       t        | dQgdRdSgdNdTdHgfdJdUdIgfgd?d"d%d'd$d&d(ddddddd)dVdWg dXY      }t	        |      }|j
                  d+   }t        dZ      }t        |d[|      }t        t        |d\|            }||j                  vr |j                  j                  d]|z  ^       nL||j                  |   vr;|j                  |   }|j                  j                  d_|d`|da   db|dc   dd^       |j
                  dD   }	|j
                  dJ   }
|j
                  dE   xs |j                  |	      }d }d }	 |j                  |      }|j                  j                  |de         j!                  |      j"                  j%                         }||vr|
dhv r|j                  |di|dj|k       |
dLk(  r-	 |j+                  ||||      \  }}|j-                  |||l       y |
dok(  r	 |dpk(  r|j-                  dW|d_|dq|l       ||vr|j-                  dW|d_|dr|dsl       |j                  j                  |de         j!                  |      j.                  j1                  |dat       |j-                  dF|d_|du|l       y |
dyk(  r-	 |j3                  ||||      \  }}|j-                  |||l       y |
dUk(  r-	 |j5                  ||||      \  }}|j-                  |||l       y |
d|k(  r	 ||vr|j-                  dW|d_|d}|l       |j                  j                  |de         j!                  |      j.                  j1                  |d~t       |j-                  dF|d_|d|l       y y # t&        $ r6}|j                  j                  df|dgt)        |      ^       Y d }~ d }~ww xY w# t&        $ r/}|j                  |dm|dj|dnt)        |      k       Y d }~y d }~ww xY w# t&        $ r.}|j                  dv|dw|dxt)        |      ^       Y d }~y d }~ww xY w# t&        $ r.}|j                  dz|dj|dxt)        |      ^       Y d }~y d }~ww xY w# t&        $ r.}|j                  d{|dj|dxt)        |      ^       Y d }~y d }~ww xY w# t&        $ r/}|j                  |d|dw|dnt)        |      k       Y d }~y d }~ww xY w)Nr(   ry   )nativethreadsio_uring)typechoicesr)   rb   )r   r*   rc   r+   r,   r-   )r   writethrough	writebackunsafe
directsyncr.   r/   r0   ignoreonr1   )rawcowqcowqedqcow2vmdkcloopr2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   rl   r>   floatr?   r@   rA   rB   rC   rD   r   rq   rE   rF   rG   )r   reportstoprH   rI   rJ   rK   rL   rM   rN   rO   )autolbar   rP   )enospcr   r   r   rQ   r   r   r   r   r   rs   600)r   defaultnamer   T)r   requiredrm   r   state)presentresizeddetachedmovedabsentr   )r   r   r   rg   )rh   rj   rk   rj   )api_token_idapi_token_secret)r   r   )api_passwordr   rk   r   )r   r?   rA   rC   r*   r+   r,   r5   r8   r;   r6   r9   r<   rl   F))r   r   )r>   r@   )r>   rB   )r4   r7   )r4   r:   )r3   r   )argument_specrequired_togetherrequired_one_ofrequired_ifrequired_bysupports_check_modemutually_exclusivez^([a-z]+)([0-9]+)$z\1z\2zUnsupported disk bus: %sro   ri   z number not in range r   z.. rr   zGetting information for VM z failed with exception: )r   r   zUnable to process missing disk z in VM )r   rp   )changedr   rp   zUnable to create/update disk r   r   r[   z already detached in VM z not present in VM z config)idlistforcez detached from VM zFailed to detach disk z	 from VM z with exception: r   zFailed to move disk zFailed to resize disk r   z is already absent in VM r   z removed from VM zUnable to remove disk ru   )r   r   rx   r   r'   r^   r
   r   rc   r   r]   rw   get_vmidget_vmrz   r{   r|   r   rv   	Exceptionry   r   	exit_jsonunlinkputr   r   )module_args	disk_argsr]   proxmoxrq   
disk_regexdisk_busdisk_number	bus_ranger   r   r   r   r   er   messages                    r#   mainr     s	   ,.K ?e%FG?  ? '	?
 E*? E*? 'de? u? '? %(D)9:? (_`? ? e$? u? 5!?  %(!?" % #?$ e$%?&  U+'?( % )?* e$+?,  U+-?. 6"/?0 E"1?2 w3?4 7#5?6 '"7?8 g&9?: '";?< g&=?> '89??@ A?B F#C?D (DEE?F VG?H F#I?J uK?L M?N  O?P 6"Q?R fS?T '>?U?V (NOW?X eY?^ % _?` 'a?b e$c?d e$e?f v&g?h %/i?n uo?p uq?r ut,s?t % u?v uw?x '\$&y?| (IS\]}?IB y!!?@)+KLx)-i&*

 )$$(!.!.$$)"/"/ 
  "
3!FF !(G== D./J:ud+Hc*eT23Kw777  %?(%J K	G<<XF	F44X>	  dT]^_T`bklnbo%p q== DMM'"E== :G$4$4T$:D 
BIq^^D!''--bj9>>tDKKOOQ	
 9*>!>dX\^b(cd		s&224r9MGWW4WE 
*		r8#  Tfjlp?q r9$  Thlnr?s t%%bj166t<CCGGt[\G]T[_ae:fg 
'		n&00tRKGWW4WE 
)		p&224r9MGWW4WE 
(		n9$  Tgkmq?r s%%bj166t<CCGGt[\G]TZ^`d:ef 
O  q  bfhklmhn%o ppq  	s$^bdhjmnojp,qrr	s  	r]acgilmnio!pqq	r  	nY]_cehijek!lmm	n  	p[_aegjklgm!noo	p  	n$Y]_cehijek,lmm	ns   AZ +[ B \ ,+]	 +^ B ^= 	[+[[	\%\\	]$]]		^ $];;^ 	^:$^55^:=	_5%_00_5__main__N)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   Bansible_collections.community.general.plugins.module_utils.versionr   Bansible_collections.community.general.plugins.module_utils.proxmoxr   r	   rer
   r   r   r$   r'   r   r   ru   r%   r#   <module>r      ss    A @un	iV
 5 [` " "(VLC LC^mn` zF r%   