
    Vhp                         d dl mZmZmZ eZdZdZdZd dl	m
Z
mZmZ d dlmZ d Zd Zd	 Zd
 Zd Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functiona  
module: scaleway_ip
short_description: Scaleway IP management module
author: Remy Leone (@remyleone)
description:
  - This module manages IP on Scaleway account U(https://developer.scaleway.com).
extends_documentation_fragment:
  - community.general.scaleway
  - community.general.attributes

attributes:
  check_mode:
    support: full
  diff_mode:
    support: none

options:
  state:
    type: str
    description:
      - Indicate desired state of the IP.
    default: present
    choices:
      - present
      - absent

  organization:
    type: str
    description:
      - Scaleway organization identifier.
    required: true

  region:
    type: str
    description:
      - Scaleway region to use (for example par1).
    required: true
    choices:
      - ams1
      - EMEA-NL-EVS
      - par1
      - EMEA-FR-PAR1
      - par2
      - EMEA-FR-PAR2
      - waw1
      - EMEA-PL-WAW1

  id:
    type: str
    description:
      - ID of the Scaleway IP (UUID).
  server:
    type: str
    description:
      - ID of the server you want to attach an IP to.
      - To unattach an IP do not specify this option.
  reverse:
    type: str
    description:
      - Reverse to assign to the IP.
a,  
- name: Create an IP
  community.general.scaleway_ip:
    organization: '{{ scw_org }}'
    state: present
    region: par1
  register: ip_creation_task

- name: Make sure IP deleted
  community.general.scaleway_ip:
    id: '{{ ip_creation_task.scaleway_ip.id }}'
    state: absent
    region: par1
a  
data:
  description: This is only present when O(state=present).
  returned: when O(state=present)
  type: dict
  sample:
    {
      "ips": [
        {
          "organization": "951df375-e094-4d26-97c1-ba548eeb9c42",
          "reverse": null,
          "id": "dd9e8df6-6775-4863-b517-e0b0ee3d7477",
          "server": {
            "id": "3f1568ca-b1a2-4e98-b6f7-31a0588157f1",
            "name": "ansible_tuto-1"
          },
          "address": "212.47.232.136"
        }
      ]
    }
)SCALEWAY_LOCATIONscaleway_argument_specScaleway)AnsibleModulec                    i }|d   |d   k7  r|d   |d<   |d   |d   r|d   |d<   	 |d   d   r|d   |d   |d<   	 |d   d   |d   k7  r|d   |d<   |S # t         t        f$ r Y *w xY w# t         t        f$ r Y |S w xY w)Nreverseserverid)	TypeErrorKeyError)api	target_ip	wished_ippatch_payloads       q/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/scaleway_ip.pyip_attributes_should_be_changedr   u   s    My33#,Y#7i  "y':"+H"5hXt$8)<)D&/&9M(#
Xt$	((;;&/&9M(#  x   x  s"   A A, A)(A),A?>A?c                 d    | j                         D ci c]  \  }}|dk7  r||| c}}S c c}}w )Nr   )items)r   kvs      r   payload_from_wished_ipr      s>     OO%Aq9 	
1  s   ,c                    d}| j                  d      }|j                  sC| j                  j                  dj	                  |j
                  |j                  d                |j                  d   }|D ci c]  }|d   |
 }}|d   |j                         vrd}| j                  j                  r|dd	ifS | j                  d
t        |            }|j                  sLd|j                  d   d|j                  d   d|j                  d}| j                  j                  |       ||j                  d   fS ||d      }	t        | |	|      }
|
s||	fS d}| j                  j                  r|ddifS | j                  d|	d   z  |
      }|j                  sC| j                  j                  dj	                  |j
                  |j                  d                ||j                  d   fS c c}w )NFipsError getting IPs [{0}: {1}]messagemsgr   TstatuszAn IP would be created.z/ips)datazError during ip creation: r    z: 'z' ()ip)r   r   r   zIP attributes would be changed.zips/%s)pathr"   z-Error during IP attributes update: [{0}: {1}])getokmodule	fail_jsonformatstatus_codejsonkeys
check_modepostr   infor   patch)r   r   changedresponseips_listr$   	ip_lookupcreation_responser    r   r   ip_patch_responses               r   present_strategyr8      s   Gwwu~H;;

!?!F!F  (--	":"< 	= }}U#H(01"D21I1inn..::  X'@AAA  HHV*@*K % M !##?P?U?UV[?\?P?U?UV_?`?P?U?UWC JJ  S ))..t444)D/*I3y\efM	!!G
zz#DEEE		x)D/'A'4 " 6 

!P!W!W))+<+A+A)+L"N 	O %**4000G 2s   6G0c                 l   | j                  d      }d}|j                  }|j                  }|d   }|j                  s9| j                  j                  dj                  ||j                  d                |D ci c]  }|d   |
 }}|d   |j                         vr|i fS d}| j                  j                  r|dd	ifS | j                  d
|d   z         }|j                  s@| j                  j                  dj                  |j                  |j                               ||j                  fS c c}w )Nr   Fr   r   r   r   Tr!   zIP would be destroyedz/ips/zError deleting IP [{0}: {1}])
r&   r+   r,   r'   r(   r)   r*   r-   r.   delete)	r   r   r3   r2   r+   ips_jsonr4   r$   r5   s	            r   absent_strategyr<      s,   wwu~HG&&K}}HH;;

!?!F!Fy1"3 	4 )11"D21I1inn..{G
zz#:;;;zz'IdO34H;;

!?!F!F  (--"1 	2 HMM!! 2s   :D1c                 n   | j                   d   | j                   d   | j                   d   | j                   d   d}| j                   d   }t        |   d   | j                   d<   t        | 	      }| j                   d
   dk(  rt        ||      \  }}nt	        ||      \  }}| j                  ||       y )Norganizationr   r   r   )r>   r   r   r   regionapi_endpointapi_url)r(   stateabsent)r   r   )r2   scaleway_ip)paramsr   r   r<   r8   	exit_json)r(   r   r?   r   r2   summarys         r   corerH      s    n5==+mmD!--)	I ]]8$F08HFMM)
&
!C}}W)*siH+yI
W':    c                  2   t               } | j                  t        t        dddg      t        d      t               t               t        dt        t	        j
                                     t                            t        | d      }t        |       y )	NpresentrC   )defaultchoicesT)required)rN   rM   )rB   r>   r   r   r?   r   )argument_specsupports_check_mode)r   updatedictlistr   r-   r	   rH   )rO   r(   s     r   mainrT      sy    *,M9x.CD4(vT40A0F0F0H+IJ6  # F
 	LrI   __main__N)
__future__r   r   r   type__metaclass__DOCUMENTATIONEXAMPLESRETURNCansible_collections.community.general.plugins.module_utils.scalewayr   r   r   ansible.module_utils.basicr	   r   r   r8   r<   rH   rT   __name__ rI   r   <module>r`      sk    A @<|
, D  D 46,1^"8;&$ zF rI   