
    Vh                         d dl mZmZmZ eZdZdZd dlZd dl	Z	dZ
	 d dlmZmZ d dlmZ g d	Z ej$                  d
ej&                        Zd Zd Zd Zd Zd Zedk(  r e        yy# e$ r dZ
Y Mw xY w)    )absolute_importdivisionprint_functiona  
module: profitbricks_datacenter
short_description: Create or destroy a ProfitBricks Virtual Datacenter
description:
  - This is a simple module that supports creating or removing vDCs. A vDC is required before you can create servers. This
    module has a dependency on profitbricks >= 1.0.0.
deprecated:
  removed_in: 11.0.0
  why: Module relies on library unsupported since 2021.
  alternative: >
    Profitbricks has rebranded as Ionos Cloud and they provide a collection named ionoscloudsdk.ionoscloud.
    Whilst it is likely it will provide the features of this module, that has not been verified.
    Please refer to that collection's documentation for more details.

extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
options:
  name:
    description:
      - The name of the virtual datacenter.
    type: str
  description:
    description:
      - The description of the virtual datacenter.
    type: str
    required: false
  location:
    description:
      - The datacenter location.
    type: str
    required: false
    default: us/las
    choices: ["us/las", "de/fra", "de/fkb"]
  subscription_user:
    description:
      - The ProfitBricks username. Overrides the E(PB_SUBSCRIPTION_ID) environment variable.
    type: str
    required: false
  subscription_password:
    description:
      - THe ProfitBricks password. Overrides the E(PB_PASSWORD) environment variable.
    type: str
    required: false
  wait:
    description:
      - Wait for the datacenter to be created before returning.
    required: false
    default: true
    type: bool
  wait_timeout:
    description:
      - How long before wait gives up, in seconds.
    type: int
    default: 600
  state:
    description:
      - Create or terminate datacenters.
      - 'The available choices are: V(present), V(absent).'
    type: str
    required: false
    default: 'present'

requirements: ["profitbricks"]
author: Matt Baldwin (@baldwinSPC) <baldwin@stackpointcloud.com>
aL  
- name: Create a datacenter
  community.general.profitbricks_datacenter:
    datacenter: Tardis One
    wait_timeout: 500

- name: Destroy a datacenter (remove all servers, volumes, and other objects in the datacenter)
  community.general.profitbricks_datacenter:
    datacenter: Tardis One
    wait_timeout: 500
    state: absent
NT)ProfitBricksService
DatacenterF)AnsibleModule)us/laszde/frazde/fkbz([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}c                    |sy t        j                          |z   }|t        j                          kD  r}t        j                  d       | j                  |d   d      }|d   d   dk(  ry |d   d   dk(  r#t        d	|z   d
z   t	        |d         z   dz         |t        j                          kD  r}t        d|z   d
z   t	        |d         z   dz         )N   	requestIdT)
request_idstatusmetadatar   DONEFAILEDzRequest failed to complete z "z" to complete.z&Timed out waiting for async operation )timesleepget_request	Exceptionstr)profitbrickspromisewait_timeoutmsgoperation_results        }/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/profitbricks_datacenter.py_wait_for_completionr   s   s    99;-L

$

1'33{+ 4  J'1V;j)(3x?-3d:SK(>* *,<=> > 
$ 036=K A
 	
	     c                     	 |j                  |       y # t        $ r(}| j                  dt        |      z         Y d }~y d }~ww xY w)Nz#failed to remove the datacenter: %sr   )delete_datacenterr   	fail_jsonr   )moduler   
datacenteres       r   _remove_datacenterr&      sF    M&&z2 MBSVKLLMs    	AA  Ac                    | j                   j                  d      }| j                   j                  d      }| j                   j                  d      }| j                   j                  d      }t        | j                   j                  d            }t        |||      }	 |j	                  |      }|rt        |||d       d	|d
   i}	|	S # t        $ r(}
| j                  dt        |
      z         Y d}
~
yd}
~
ww xY w)a  
    Creates a Datacenter

    This will create a new Datacenter in the specified location.

    module : AnsibleModule object
    profitbricks: authenticated profitbricks object.

    Returns:
        True if a new datacenter was created, false otherwise
    namelocationdescriptionwaitr   )r(   r)   r*   )r$   _create_datacenterdatacenter_ididz'failed to create the new datacenter: %sr    N)	paramsgetintr   create_datacenterr   r   r"   r   )r#   r   r(   r)   r*   r+   r   idatacenter_responseresultsr%   s              r   r2   r2      s     ==V$D}}  ,H--##M2K==V$Dv}}((89L	AQ*<<<J /B!-/CE 06
  QFQOPPQs    *C 	C<C77C<c                 (   | j                   j                  d      }d}t        j                  |      rt	        | ||       d}|S |j                         }|d   D ]6  }|j                  |d         }||d   d   k(  s#|d   }t	        | ||       d}8 |S )z
    Removes a Datacenter.

    This will remove a datacenter.

    module : AnsibleModule object
    profitbricks: authenticated profitbricks object.

    Returns:
        True if the datacenter was deleted, false otherwise
    r(   FTitemsr.   
properties)r/   r0   
uuid_matchmatchr&   list_datacentersget_datacenter)r#   r   r(   changeddatacentersdvdcs          r   remove_datacenterrA      s     ==V$DG6<6 N #335W% 	A--ag6Cs<(00w"6<>	 Nr   c                     t        t        t               t               t        t        d      t               t        d      t        dd      t        dd	      t        d
                  } t        s| j	                  d       | j
                  j                  d      s| j	                  d       | j
                  j                  d      s| j	                  d       | j
                  j                  d      }| j
                  j                  d      }t        ||      }| j
                  j                  d      }|dk(  rM| j
                  j                  d      s| j	                  d       	 t        | |      }| j                  |       y |d
k(  rz| j
                  j                  d      s| j	                  d       | j
                  j                  d      s| j	                  d       	 t        | |      } | j                  di | y y # t        $ r(}| j	                  dt        |      z         Y d }~y d }~ww xY w# t        $ r(}| j	                  dt        |      z         Y d }~y d }~ww xY w)Nr	   )choicesdefaultT)no_logbool)typerD   iX  r1   )rD   rG   present)rD   )r(   r*   r)   subscription_usersubscription_passwordr+   r   state)argument_specz%profitbricks required for this moduler    rI   z'subscription_user parameter is requiredrJ   z+subscription_password parameter is required)usernamepasswordrK   absentr(   z9name parameter is required deleting a virtual datacenter.)r=   z"failed to set datacenter state: %sz/name parameter is required for a new datacenterr)   z3location parameter is required for a new datacenter )r   dict	LOCATIONS
HAS_PB_SDKr"   r/   r0   r   rA   	exit_jsonr   r   r2   )r#   rI   rJ   r   rK   r=   r%   datacenter_dict_arrays           r   mainrV      s9   )X>"f"&d"3640c6y)	
F DE==01FG==45JK))*=>"MM--.EF&"&(L MMg&E}}  (!\]	P)&,?W  !
 
)	}}  (!RS}}  ,!VW	P&7&M"F545 
  	P!EA!NOO	P  	P!EA!NOO	Ps0   2H 1I 	IH==I	I6I11I6__main__)
__future__r   r   r   rG   __metaclass__DOCUMENTATIONEXAMPLESrer   rS   profitbricks.clientr   r   ImportErroransible.module_utils.basicr   rR   compileIr9   r   r&   r2   rA   rV   __name__rP   r   r   <module>rc      s    A @EN 
 
C 5	 RZZ/7
.M&QR@3Pl zF W  Js   A( (A21A2