
    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: image_info

short_description: Gather infos about your Hetzner Cloud images.


description:
    - Gather infos about your Hetzner Cloud images.

author:
    - Lukas Kaemmerling (@LKaemmerling)

options:
    id:
        description:
            - The ID of the image you want to get.
            - The module will fail if the provided ID is invalid.
        type: int
    name:
        description:
            - The name of the image you want to get.
        type: str
    label_selector:
        description:
            - The label selector for the images you want to get.
        type: str
    type:
        description:
            - The type for the images you want to get.
        default: system
        choices: [ system, snapshot, backup ]
        type: str
    architecture:
        description:
            - The architecture for the images you want to get.
        type: str
        choices: [ x86, arm ]
extends_documentation_fragment:
- hetzner.hcloud.hcloud

z
- name: Gather hcloud image infos
  hetzner.hcloud.image_info:
  register: output

- name: Print the gathered infos
  debug:
    var: output
a  
hcloud_image_info:
    description: The image infos as list
    returned: always
    type: complex
    contains:
        id:
            description: Numeric identifier of the image
            returned: always
            type: int
            sample: 1937415
        type:
            description: Type of the image
            returned: always
            type: str
            sample: system
        status:
            description: Status of the image
            returned: always
            type: str
            sample: available
        name:
            description: Name of the image
            returned: always
            type: str
            sample: ubuntu-22.04
        description:
            description: Detail description of the image
            returned: always
            type: str
            sample: Ubuntu 18.04 Standard 64 bit
        os_flavor:
            description: OS flavor of the image
            returned: always
            type: str
            sample: ubuntu
        os_version:
            description: OS version of the image
            returned: always
            type: str
            sample: 18.04
        architecture:
            description: Image is compatible with this architecture
            returned: always
            type: str
            sample: x86
        labels:
            description: User-defined labels (key-value pairs)
            returned: always
            type: dict
)AnsibleModule   )AnsibleHCloud)HCloudException)
BoundImagec                  H     e Zd ZU dZdZded<   d Zd Ze fd       Z	 xZ
S )AnsibleHCloudImageInfohcloud_image_infoNzlist[BoundImage] | Nonec                .   g }| j                   D ]  }||j                  t        |j                        |j                  |j
                  |j                  |j                  |j                  |j                  |j                  |j                  d	        |S )N)	idstatustypenamedescription	os_flavor
os_versionarchitecturelabels)r   appendstrr   r   r   r   r   r   r   r   r   )selftmpimages      m/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/hetzner/hcloud/plugins/modules/image_info.py_prepare_resultz&AnsibleHCloudImageInfo._prepare_result~   s    ++ 	E}JJehh-#ll!JJ!JJ#(#4#4!&"'"2"2$)$6$6#ll
		" 
    c                6   	 | j                   j                  j                  d      O| j                  j                  j                  | j                   j                  j                  d            g| _        y | j                   j                  j                  d      | j                   j                  j                  d      s| j                  j                  j                  | j                   j                  j                  d      | j                   j                  j                  d            g| _        y | j                   j                  j                  d      j| j                   j                  d       | j                  j                  j                  | j                   j                  j                  d            g| _        y i }| j                   j                  j                  d      }|r||d<   | j                   j                  j                  d      }|r||d<   | j                   j                  j                  d      }|r||d<    | j                  j                  j                  di || _        y # t        $ r}| j                  |       Y d }~y d }~ww xY w)Nr   r   r   zeThis module only returns x86 images by default. Please set architecture:x86|arm to hide this message.label_selectorr    )moduleparamsgetclientimages	get_by_idr   get_by_name_and_architecturewarnget_by_nameget_allr   fail_json_hcloud)r   r"   r   
image_typer   	exceptions         r   
get_imagesz!AnsibleHCloudImageInfo.get_images   s    	-{{!!%%d+7*.++*<*<*F*Ft{{GYGYG]G]^bGc*d)e&##''/;@R@R@V@VWe@f@rKK&&CC**..v6**..~>*& ##''/;  { +/++*<*<*H*HI[I[I_I_`fIg*h)i&!%!3!3!7!78H!I!/=F+,![[//33F;
%/F6N#{{1155nE-9F>*)C););)C)C)Mf)M& 	-!!),,	-s-   A3I4 6B<I4 3BI4 B1I4 4	J=JJc                v    t        t        dddiddiddig ddddddgdd	d
t        |          d      S )Nr   intr   )systemsnapshotbackupr1   )choicesdefaultr   x86arm)r4   r   )r   r   r   r   r   T)argument_specsupports_check_moder    )r   dictsuperbase_module_arguments)cls	__class__s    r   define_modulez$AnsibleHCloudImageInfo.define_module   s`     E?e_ &!Ah`ef*/G '/1 !%

 
	
r   )__name__
__module____qualname__	representr   __annotations__r   r.   classmethodr?   __classcell__)r>   s   @r   r
   r
   y   s3    #I15.5,!-F 
 
r   r
   c                     t         j                         } t        |       }|j                          |j                         }d|d   i} | j                  di | y )Nr   r    )r
   r?   r.   
get_result	exit_json)r!   hcloudresultansible_infos       r   mainrM      sW    #113F#F+F
 F'0C)DELF$|$r   __main__N)
__future__r   DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   module_utils.hcloudr   module_utils.vendor.hcloudr   !module_utils.vendor.hcloud.imagesr   r
   rM   r@   r    r   r   <module>rW      sW    #)V2
h 5 / 8 :J
] J
Z% zF r   