
    VhL                        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: server_info

short_description: Gather infos about your Hetzner Cloud servers.


description:
    - Gather infos about your Hetzner Cloud servers.

author:
    - Lukas Kaemmerling (@LKaemmerling)

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

z
- name: Gather hcloud server infos
  hetzner.hcloud.server_info:
  register: output

- name: Print the gathered infos
  debug:
    var: output.hcloud_server_info
a  
hcloud_server_info:
    description: The server infos as list
    returned: always
    type: complex
    contains:
        id:
            description: Numeric identifier of the server
            returned: always
            type: int
            sample: 1937415
        name:
            description: Name of the server
            returned: always
            type: str
            sample: my-server
        created:
            description: Point in time when the Server was created (in ISO-8601 format)
            returned: always
            type: str
            sample: "2023-11-06T13:36:56+00:00"
        status:
            description: Status of the server
            returned: always
            type: str
            sample: running
        server_type:
            description: Name of the server type of the server
            returned: always
            type: str
            sample: cx22
        ipv4_address:
            description: Public IPv4 address of the server
            returned: always
            type: str
            sample: 116.203.104.109
        ipv6:
            description: IPv6 network of the server
            returned: always
            type: str
            sample: 2a01:4f8:1c1c:c140::/64
        private_networks:
            description: List of private networks the server is attached to (name)
            returned: always
            type: list
            elements: str
            sample: ['my-network', 'another-network']
        private_networks_info:
            description: List of private networks the server is attached to (dict with name and ip)
            returned: always
            type: list
            elements: dict
            sample: [{'name': 'my-network', 'ip': '192.168.1.1'}, {'name': 'another-network', 'ip': '10.185.50.40'}]
        location:
            description: Name of the location of the server
            returned: always
            type: str
            sample: fsn1
        placement_group:
            description: Placement Group of the server
            type: str
            returned: always
            sample: 4711
            version_added: "1.5.0"
        datacenter:
            description: Name of the datacenter of the server
            returned: always
            type: str
            sample: fsn1-dc14
        rescue_enabled:
            description: True if rescue mode is enabled, Server will then boot into rescue system on next reboot
            returned: always
            type: bool
            sample: false
        backup_window:
            description: Time window (UTC) in which the backup will run, or null if the backups are not enabled
            returned: always
            type: bool
            sample: 22-02
        labels:
            description: User-defined labels (key-value pairs)
            returned: always
            type: dict
        delete_protection:
            description: True if server is protected for deletion
            type: bool
            returned: always
            sample: false
            version_added: "0.1.0"
        rebuild_protection:
            description: True if server is protected for rebuild
            type: bool
            returned: always
            sample: false
            version_added: "0.1.0"
)AnsibleModule   )AnsibleHCloud)HCloudException)BoundServerc                  H     e Zd ZU dZdZded<   d Zd Ze fd       Z	 xZ
S )AnsibleHCloudServerInfohcloud_server_infoNzlist[BoundServer] | Nonec                ~   g }| j                   D ]   }||j                  i dt        |j                        d|j                  d|j
                  j                         d|j                  j                   |j                  j                  j                  nd d|j                  j                   |j                  j                  j                  nd d|j                  D cg c]  }|j                  j                   c}d|j                  D cg c]%  }|j                  j                  |j                  d' c}d	|j                  |j                  j                  nd d
|j                  j                  d|j                  j                  d|j                  j                   j                  d|j"                  |j"                  j                  nd d|j$                  d|j&                  d|j(                  d|j*                  d|j,                  d   d|j,                  d   i       # |S c c}w c c}w )Nidnamecreatedipv4_addressipv6private_networksprivate_networks_info)r   ipimageserver_type
datacenterlocationplacement_grouprescue_enabledbackup_windowlabelsstatusdelete_protectiondeleterebuild_protectionrebuild)r   appendstrr   r   r   	isoformat
public_netipv4r   r   private_netnetworkr   r   r   r   r   r   r   r   r   
protection)selftmpservernets       n/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/hetzner/hcloud/plugins/modules/server_info.py_prepare_resultz'AnsibleHCloudServerInfo._prepare_result   sC   -- 	F~JJ#fii.FKK v~~779 #ARARAWAWAcF$5$5$:$:$=$=im	
 9J9J9O9O9[F--2255ae 'VEWEW(Xc)9)9(X ,bhbtbt-u[^s{{7G7Gsvv.V-u &,,2JV\\..PT "6#5#5#:#: !&"3"3"8"8  1 1 : : ? ? &fF\F\Fhv'='='B'Bnr %f&;&; $V%9%9 fmm  fmm!" ():):8)D#$ )&*;*;I*F%		4 
 )Y-us   !H5*H: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)r1   )moduleparamsgetclientservers	get_by_idr   get_by_nameget_allr   fail_json_hcloud)r*   	exceptions     r.   get_serversz#AnsibleHCloudServerInfo.get_servers   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   r1   T)argument_specsupports_check_mode )r   dictsuperbase_module_arguments)cls	__class__s    r.   define_modulez%AnsibleHCloudServerInfo.define_module   sI     E?e_ & '/1	 !%
 	
    )__name__
__module____qualname__	representr   __annotations__r/   r<   classmethodrH   __classcell__)rG   s   @r.   r
   r
      s2    $I3707>-  	
 	
rI   r
   c                     t         j                         } t        |       }|j                          |j                         }d|d   i} | j                  di | y )Nr   rB   )r
   rH   r<   
get_result	exit_json)r2   hcloudresultansible_infos       r.   mainrW      sW    $224F$V,F
 F(&1E*FGLF$|$rI   __main__N)
__future__r   DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   module_utils.hcloudr   module_utils.vendor.hcloudr   "module_utils.vendor.hcloud.serversr   r
   rW   rJ   rB   rI   r.   <module>ra      sV    #@_
B 5 / 8 <>
m >
B% zF rI   