
    Vh8                        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)    )annotationsa0  
---
module: datacenter_info

short_description: Gather info about the Hetzner Cloud datacenters.

description:
    - Gather info about your Hetzner Cloud datacenters.

author:
    - Lukas Kaemmerling (@LKaemmerling)

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

a  
- name: Gather hcloud datacenter info
  hetzner.hcloud.datacenter_info:
  register: output

- name: Print the gathered info
  debug:
    var: output

- name: List available server_types in a datacenter
  block:
    - name: Gather a hcloud datacenter
      hetzner.hcloud.datacenter_info:
        name: fsn1-dc14
      register: output

    - name: Gather a hcloud datacenter available server_types
      hetzner.hcloud.server_type_info:
        id: "{{ item }}"
      loop: "{{ output.hcloud_datacenter_info[0].server_types.available }}"
      register: available_server_types

    - name: Print a hcloud datacenter available server_types
      ansible.builtin.debug:
        var: available_server_types.results | map(attribute='hcloud_server_type_info')
a  
hcloud_datacenter_info:
    description:
      - The datacenter info as list
    returned: always
    type: complex
    contains:
        id:
            description: Numeric identifier of the datacenter
            returned: always
            type: int
            sample: 1937415
        name:
            description: Name of the datacenter
            returned: always
            type: str
            sample: fsn1-dc8
        description:
            description: Detail description of the datacenter
            returned: always
            type: str
            sample: Falkenstein DC 8
        location:
            description: Name of the location where the datacenter resides in
            returned: always
            type: str
            sample: fsn1
        city:
            description: City of the location
            returned: always
            type: str
            sample: fsn1
        server_types:
            description: The Server types the Datacenter can handle
            returned: always
            type: dict
            contains:
                available:
                    description: IDs of Server types that are supported and for which the Datacenter has enough resources left
                    returned: always
                    type: list
                    elements: int
                    sample: [1, 2, 3]
                available_for_migration:
                    description: IDs of Server types that are supported and for which the Datacenter has enough resources left
                    returned: always
                    type: list
                    elements: int
                    sample: [1, 2, 3]
                supported:
                    description: IDs of Server types that are supported in the Datacenter
                    returned: always
                    type: list
                    elements: int
                    sample: [1, 2, 3]
)AnsibleModule   )AnsibleHCloud)HCloudException)BoundDatacenterc                  H     e Zd ZU dZdZded<   d Zd Ze fd       Z	 xZ
S )AnsibleHCloudDatacenterInfohcloud_datacenter_infoNzlist[BoundDatacenter] | Nonec                   g }| j                   D ]  }||j                  t        |j                        |j                  |j
                  |j                  j                  |j                  j                  D cg c]  }|j                   c}|j                  j                  D cg c]  }|j                   c}|j                  j                  D cg c]  }|j                   c}dd        |S c c}w c c}w c c}w )N)	availableavailable_for_migration	supported)idnamedescriptionlocationserver_types)r   appendstrr   r   r   r   r   r   r   r   )selftmp
datacenteros       r/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/hetzner/hcloud/plugins/modules/datacenter_info.py_prepare_resultz+AnsibleHCloudDatacenterInfo._prepare_result   s    55 	J!JJjmm,&OO#-#9#9 * 3 3 8 84>4K4K4U4U%Vqadd%VBLBYBYBqBq3rQADD3r4>4K4K4U4U%Vqadd%V%
		$ 
 &W3r%Vs   7C3$C8C=c                v   	 | 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                         | _        y # t        $ r}| j                  |       Y d }~y d }~ww xY w)Nr   r   )moduleparamsgetclientdatacenters	get_by_idr   get_by_nameget_allr   fail_json_hcloud)r   	exceptions     r   get_datacentersz+AnsibleHCloudDatacenterInfo.get_datacenters   s    		-{{!!%%d+7/3{{/F/F/P/PQUQ\Q\QcQcQgQghlQm/n.o+##''/;/3{{/F/F/R/RSWS^S^SeSeSiSijpSq/r.s+.2kk.E.E.M.M.O+ 	-!!),,	-s%   A3D 6A3D *)D 	D8D33D8c           	     V    t        t        dddiddidt        |          d      S )Ntypeintr   )r   r   T)argument_specsupports_check_mode )r   dictsuperbase_module_arguments)cls	__class__s    r   define_modulez)AnsibleHCloudDatacenterInfo.define_module   sB     E?e_ '/1
 !%
 	
    )__name__
__module____qualname__	representr   __annotations__r   r(   classmethodr4   __classcell__)r3   s   @r   r
   r
      s2    (I;?8?.
- 
 
r5   r
   c                     t         j                         } t        |       }|j                          |j                         }d|d   i} | j                  di | y )Nr   r.   )r
   r4   r(   
get_result	exit_json)r   hcloudresultansible_infos       r   mainrC      sW    (668F(0F
 F,f5M.NOLF$|$r5   __main__N)
__future__r   DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   module_utils.hcloudr   module_utils.vendor.hcloudr   &module_utils.vendor.hcloud.datacentersr   r
   rC   r6   r.   r5   r   <module>rM      sT    #667
r 5 / 8 D1
- 1
h% zF r5   