
    Vh                        d dl mZ dZdZdZd dlmZ ddlmZ ddl	m
Z
 dd	lmZ  G d
 de      Zd Zedk(  r e        yy)    )annotationsa  
---
module: volume_info

short_description: Gather infos about your Hetzner Cloud Volumes.

description:
    - Gather infos about your Hetzner Cloud Volumes.

author:
    - Lukas Kaemmerling (@LKaemmerling)

options:
    id:
        description:
            - The ID of the Volume you want to get.
            - The module will fail if the provided ID is invalid.
        type: int
    name:
        description:
            - The name of the Volume you want to get.
        type: str
    label_selector:
        description:
            - The label selector for the Volume you want to get.
        type: str
extends_documentation_fragment:
- hetzner.hcloud.hcloud

z
- name: Gather hcloud Volume infos
  hetzner.hcloud.volume_info:
  register: output
- name: Print the gathered infos
  debug:
    var: output.hcloud_volume_info
a  
hcloud_volume_info:
    description: The Volume infos as list
    returned: always
    type: complex
    contains:
        id:
            description: Numeric identifier of the Volume
            returned: always
            type: int
            sample: 1937415
        name:
            description: Name of the Volume
            returned: always
            type: str
            sample: my-volume
        size:
            description: Size of the Volume
            returned: always
            type: str
            sample: 10
        linux_device:
            description: Path to the device that contains the Volume.
            returned: always
            type: str
            sample: /dev/disk/by-id/scsi-0HC_Volume_12345
            version_added: "0.1.0"
        location:
            description: Name of the location where the Volume resides in
            returned: always
            type: str
            sample: fsn1
        server:
            description: Name of the server where the Volume is attached to
            returned: always
            type: str
            sample: my-server
        delete_protection:
            description: True if the Volume is protected for deletion
            returned: always
            type: bool
            version_added: "0.1.0"
        labels:
            description: User-defined labels (key-value pairs)
            returned: always
            type: dict
)AnsibleModule   )AnsibleHCloud)HCloudException)BoundVolumec                  H     e Zd ZU dZdZded<   d Zd Ze fd       Z	 xZ
S )AnsibleHCloudVolumeInfohcloud_volume_infoNzlist[BoundVolume] | Nonec                b   g }| j                   D ]  }||j                  t        |j                        |j                  |j
                  |j                  j                  |j                  |j                  |j                  j                  nd |j                  |j                  d   d        |S )Ndelete)idnamesizelocationlabelsserverlinux_devicedelete_protection)r   appendstrr   r   r   r   r   r   r   
protection)selftmpvolumes      n/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/hetzner/hcloud/plugins/modules/volume_info.py_prepare_resultz'AnsibleHCloudVolumeInfo._prepare_resultm   s    -- 	F~JJfii."KK"KK & 4 4$mm4:MM4Mfmm00SW$*$7$7)/):):8)D			" 
    c                ^   	 | j                   j                  j                  d      O| j                  j                  j                  | j                   j                  j                  d            g| _        y | j                   j                  j                  d      O| j                  j                  j                  | j                   j                  j                  d            g| _        y | j                   j                  j                  d      O| j                  j                  j                  | j                   j                  j                  d            | _        y | j                  j                  j                         | _        y # t        $ r}| j                  |       Y d }~y d }~ww xY w)Nr   r   label_selector)r    )moduleparamsgetclientvolumes	get_by_idr   get_by_nameget_allr   fail_json_hcloud)r   	exceptions     r   get_volumesz#AnsibleHCloudVolumeInfo.get_volumes   s?   	-{{!!%%d+7+/;;+>+>+H+HI[I[I_I_`dIe+f*g'##''/;+/;;+>+>+J+J4;;K]K]KaKabhKi+j*k'##''(89E*.++*=*=*E*E#';;#5#5#9#9:J#K +F +' +/++*=*=*E*E*G' 	-!!),,	-s,   A3F 6A3F *A3F )F 	F,F''F,c           	     \    t        t        dddiddiddidt        |          d      S )Ntypeintr   )r   r   r    T)argument_specsupports_check_mode )r   dictsuperbase_module_arguments)cls	__class__s    r   define_modulez%AnsibleHCloudVolumeInfo.define_module   sI     E?e_ & '/1	 !%
 	
r   )__name__
__module____qualname__	representr   __annotations__r   r+   classmethodr7   __classcell__)r6   s   @r   r
   r
   h   s2    $I3707,-  	
 	
r   r
   c                     t         j                         } t        |       }|j                          |j                         }d|d   i} | j                  di | y )Nr   r1   )r
   r7   r+   
get_result	exit_json)r!   hcloudresultansible_infos       r   mainrE      sW    $224F$V,F
 F(&1E*FGLF$|$r   __main__N)
__future__r   DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   module_utils.hcloudr   module_utils.vendor.hcloudr   "module_utils.vendor.hcloud.volumesr   r
   rE   r8   r1   r   r   <module>rO      sT    #>.
` 5 / 8 <5
m 5
p% zF r   