
    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 dl
Z
dZ	 d dlmZmZ d dlm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 Iw xY w)    )absolute_importdivisionprint_functionae  
module: profitbricks_nic
short_description: Create or Remove a NIC
description:
  - This module allows you to create or restore a volume snapshot. 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:
  datacenter:
    description:
      - The datacenter in which to operate.
    type: str
    required: true
  server:
    description:
      - The server name or ID.
    type: str
    required: true
  name:
    description:
      - The name or ID of the NIC. This is only required on deletes, but not on create.
      - If not specified, it defaults to a value based on UUID4.
    type: str
  lan:
    description:
      - The LAN to place the NIC on. You can pass a LAN that does not exist and it will be created. Required on create.
    type: str
  subscription_user:
    description:
      - The ProfitBricks username. Overrides the E(PB_SUBSCRIPTION_ID) environment variable.
    type: str
    required: true
  subscription_password:
    description:
      - THe ProfitBricks password. Overrides the E(PB_PASSWORD) environment variable.
    type: str
    required: true
  wait:
    description:
      - Wait for the operation to complete 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:
      - Indicate desired state of the resource.
      - 'The available choices are: V(present), V(absent).'
    type: str
    required: false
    default: 'present'

requirements: ["profitbricks"]
author: Matt Baldwin (@baldwinSPC) <baldwin@stackpointcloud.com>
aG  
- name: Create a NIC
  community.general.profitbricks_nic:
    datacenter: Tardis One
    server: node002
    lan: 2
    wait_timeout: 500
    state: present

- name: Remove a NIC
  community.general.profitbricks_nic:
    datacenter: Tardis One
    server: node002
    name: 7341c2454f
    wait_timeout: 500
    state: absent
NT)ProfitBricksServiceNICF)AnsibleModulez([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}c                  b    t        t        j                               j                  dd      d d S )N- 
   )struuiduuid4replace     v/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/profitbricks_nic.py_make_default_namer   v   s'    tzz|$$S"-cr22r   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	Exceptionr   )profitbrickspromisewait_timeoutmsgoperation_results        r   _wait_for_completionr&   z   s    99;-L

$

1'33{+ 4  J'1V;j)(3x?-3d:SK(>* *,<=> > 
$ 036=K A
 	
	 r   c                 Z   | j                   j                  d      }| j                   j                  d      }| j                   j                  d      }| j                   j                  d      }|
t               }| j                   j                  d      }| j                   j                  d      }t        j	                  |      s@|j                         }|d   D ](  }	|j                  |	d	         }
||
d
   d   k(  s#|	d	   } n t        j	                  |      s-|j                  |      }|d   D ]  }||d
   d   k(  s|d	   } n 	 t        ||      }|j                  |||      }|rt        |||d       |S # t        $ r(}| j                  dt        |      z         Y d}~yd}~ww xY w)z
    Creates a NIC.

    module : AnsibleModule object
    profitbricks: authenticated profitbricks object.

    Returns:
        True if the nic creates, false otherwise
    
datacenterserverlannameNwaitr#   itemsid
properties)r+   r*   
create_niczfailed to create the NIC: %sr$   )paramsgetr   
uuid_matchmatchlist_datacentersget_datacenterlist_serversr   r0   r&   r    	fail_jsonr   )moduler!   r(   r)   r*   r+   r,   r#   datacenter_listddcserver_listsnnic_responsees                   r   r0   r0      s    ""<0J]]x(F
--

E
"C==V$D|!#==V$D==$$^4L Z(&779 ) 	A,,QtW5BR-f55tW
		 V$"//
;W% 	A<004	F

 $..z61E |!-|=  F;c!fDEEFs   1E9 9	F*F%%F*c                     | j                   j                  d      }| j                   j                  d      }| j                   j                  d      }|
t               }t        j	                  |      s@|j                         }|d   D ](  }|j                  |d         }||d   d   k(  s#|d   } n d}t        j	                  |      s2|j                  |      }	|	d   D ]  }
||
d   d   k(  sd	}|
d   } n |syd}t        j	                  |      s3|j                  ||      }|d   D ]  }||d   d   k(  sd	}|d   } n |sy	 |j                  |||      }|S # t        $ r(}| j                  d
t        |      z         Y d}~yd}~ww xY w)z
    Removes a NIC

    module : AnsibleModule object
    profitbricks: authenticated profitbricks object.

    Returns:
        True if the NIC was removed, false otherwise
    r(   r)   r+   Nr-   r.   r/   FTzfailed to remove the NIC: %sr1   )r2   r3   r   r4   r5   r6   r7   r8   	list_nics
delete_nicr    r9   r   )r:   r!   r(   r)   r+   r;   r<   r=   server_foundr>   r?   	nic_foundnic_listr@   rA   rB   s                   r   rE   rE      s    ""<0J]]x(F==V$D|!# Z(&779 ) 	A,,QtW5BR-f55tW
		 LV$"//
;W% 	A<00#4		  IT"))*f='" 	Aqv.. 	w		 F#..z64H F;c!fDEEFs   E 	F%FFc                  X   t        t        t        d      t        d      t               t               t        d      t        dd      t        dd      t        dd      t        d	      
	      dddgfdddgff      } t        s| j                  d       | j                  j                  d      }| j                  j                  d      }t        ||      }| j                  j                  d      }|dk(  r 	 t        | |      }| j                  |       y |dk(  r 	 t        | |      }| j                  |       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)NT)required)rJ   no_logbool)typedefaultintiX  present)rN   )	r(   r)   r+   r*   subscription_usersubscription_passwordr,   r#   staterS   absentr+   r*   )argument_specrequired_ifz%profitbricks required for this moduler1   rQ   rR   )usernamepassword)changedzfailed to set nic state: %s)nics)r   dict
HAS_PB_SDKr9   r2   r3   r   rE   	exit_jsonr    r   r0   )r:   rQ   rR   r!   rS   rY   rB   nic_dicts           r   mainr_      s   T*&"D1"&T"B6405#6y)

 h)i%)
F$ DE))*=>"MM--.EF&"&(L MMg&E	I"6<8WW- 
)		I#FL9X(+ 
  	I!>Q!GHH	I  	I!>Q!GHH	Is0   ?E $E8 	E5E00E58	F)F$$F)__main__)
__future__r   r   r   rM   __metaclass__DOCUMENTATIONEXAMPLESrer   r   r\   profitbricks.clientr   r   ImportErroransible.module_utils.basicr   compileIr4   r   r&   r0   rE   r_   __name__r   r   r   <module>rl      s    A @FP$ 
  
< 5 RZZ/7
3.2Fj7Ft+I\ zF E  Js   A( (A21A2