
    Vhy$                         d dl mZmZmZ eZd dlZ G d d      Zd ZddZ	ddZ
ddZdd	Zdd
ZddZddZddZddZddZddZddZd Zd Zy)    )absolute_importdivisionprint_functionNc                   0    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zy
)OneAndOneResourcesfirewall_policyload_balancermonitoring_policyprivate_network	public_iproleserveruservpnN)__name__
__module____qualname__r   r	   r
   r   r   r   r   r   r        t/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/module_utils/oneandone.pyr   r      s0    'O#M+'OIDFD
Cr   r   c           
          | j                   | j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  d	} |j                  |d       |      S )N)	r   r	   r
   r   r   r   r   r   r   )
get_firewallget_load_balancerget_monitoring_policyget_private_networkget_public_ipget_role
get_serverget_userget_vpnget)oneandone_connresource_typeresource_idswitchers       r   get_resourcer&      st    )66'99+AA)==#11'' ++''%%
H -8<<t,[99r   c                 `    | j                         D ]  }||d   |d   fv s|r|c S |d   c S  y)z_
    Validates the datacenter exists by ID or country code.
    Returns the datacenter ID.
    idcountry_codeN)list_datacenters)r"   
datacenterfull_object_datacenters       r   get_datacenterr.   (   sG    
 &668 %+d+[-HII""t$$	%r   c                 `    | j                         D ]  }||d   |d   fv s|r|c S |d   c S  y)zb
    Validates the fixed instance size exists by ID or name.
    Return the instance size ID.
    r(   nameN)fixed_server_flavors)r"   fixed_instance_sizer,   _fixed_instance_sizes       r   get_fixed_instance_sizer4   4   sP    
 !/ C C E .#7#=#7#?#A A++'--.r   c                 d    | j                  d      D ]  }||d   |d   fv s|r|c S |d   c S  y)zT
    Validates the appliance exists by ID or name.
    Return the appliance ID.
    IMAGE)qr(   r0   N)list_appliances)r"   	appliancer,   
_appliances       r   get_appliancer;   A   sL    
 %44w4? $
D):f+=>>!!d##	$r   c                 `    | j                         D ]  }||d   |d   fv s|r|c S |d   c S  y)z`
    Validates the private network exists by ID or name.
    Return the private network ID.
    r0   r(   N)list_private_networks)r"   r   r,   _private_networks       r   r   r   M   sN    
 +@@B */7/57 7''#D))*r   c                 `    | j                         D ]  }||d   |d   fv s|r|c S |d   c S  y)zd
    Validates the monitoring policy exists by ID or name.
    Return the monitoring policy ID.
    r0   r(   N)list_monitoring_policies)r"   r
   r,   _monitoring_policys       r   r   r   Z   sN    
 -EEG ,!3F!;!3D!9!; ;))%d++,r   c                 `    | j                         D ]  }||d   |d   fv s|r|c S |d   c S  y)z`
    Validates the firewall policy exists by ID or name.
    Return the firewall policy ID.
    r0   r(   N)list_firewall_policies)r"   r   r,   _firewall_policys       r   get_firewall_policyrE   g   sN    
 +AAC */7/57 7''#D))*r   c                 `    | j                         D ]  }||d   |d   fv s|r|c S |d   c S  y)z\
    Validates the load balancer exists by ID or name.
    Return the load balancer ID.
    r0   r(   N)list_load_balancers)r"   r	   r,   _load_balancers       r   r   r   t   sL    
 )<<> (^F3+D13 3%%!$''(r   c                 d    | j                  d      D ]  }||d   |d   fv s|r|c S |d   c S  y)zj
    Validates that the server exists whether by ID or name.
    Returns the server if one was found.
      per_pager(   r0   N)list_servers)r"   instancer,   r   s       r   r   r      sH    
 !--t-<  tfVn55$<	 r   c                 d    | j                  d      D ]  }||d   |d   fv s|r|c S |d   c S  y)z`
    Validates that the user exists by ID or a name.
    Returns the user if one was found.
    rJ   rK   r(   r0   N)
list_users)r"   r   r,   _users       r   r   r      sH    
  **D*9 E$Kv//;	r   c                 d    | j                  d      D ]  }||d   |d   fv s|r|c S |d   c S  y)z
    Given a name, validates that the role exists
    whether it is a proper ID or a name.
    Returns the role if one was found, else None.
    rJ   rK   r(   r0   N)
list_roles)r"   r   r,   _roles       r   r   r      sH      **D*9 E$Kv//;	r   c                 d    | j                  d      D ]  }||d   |d   fv s|r|c S |d   c S  y)z^
    Validates that the vpn exists by ID or a name.
    Returns the vpn if one was found.
    rJ   rK   r(   r0   N)	list_vpns)r"   r   r,   _vpns       r   r    r       sH    
 (($(7 4:tF|,,:	r   c                 d    | j                  d      D ]  }||d   |d   fv s|r|c S |d   c S  y)zj
    Validates that the public ip exists by ID or a name.
    Returns the public ip if one was found.
    rJ   rK   r(   ipN)list_public_ips)r"   r   r,   
_public_ips       r   r   r      sL    
 %44d4C $
D):d+;<<!!d##	$r   c                 .   t        j                          |z   }|t        j                          kD  rt        j                  |       t        | ||      }|t        j                  k(  r	|d   d   }n|d   }|t        j                  k(  r|j                         dk(  s&|t        j                  k7  r|j                         dk(  ry|j                         dk(  rt        |d|      |j                         dv rt        d	|d
|      t        d|d|      )zZ
    Waits for the resource create operation to complete based on the timeout period.
    statusstate
powered_onactiveNfailedz creation failed for )r`   enabled	deployingconfiguringzUnknown z state Timed out waiting for z completion for )timesleepr&   r   r   lower	Exception)r"   r#   r$   wait_timeoutwait_intervalresourceresource_states          r   %wait_for_resource_creation_completionrn      s    99;-L

$

=!  {K.555%h/8N%g.N0777N<P<P<RVb<b"4";";;@T@T@VZb@b!!#x/=+VWW!!# (7 7 )6GI I 8E{SU Ur   c                    t        j                          |z   }|t        j                          kD  rt        j                  |       | j                  ddd      }|t        j                  k(  rd}n$|t        j
                  k(  rd}nt        d|z        |D ]-  }|d   d	   |k(  s|d
   dk(  s|d   |k(  s!|d   d   dk(  s- y |t        j                          kD  rt        d|d|      )zZ
    Waits for the resource delete operation to complete based on the timeout period.
    DELETE	LAST_HOURz-start_date)r7   periodsortVMPRIVATENETWORKz5Unsupported wait_for delete operation for %s resourcerl   r(   actiontyper]   r^   OKNre   z deletion for )rf   rg   	list_logsr   r   r   ri   )r"   r#   r$   rj   rk   logs_typelogs           r   %wait_for_resource_deletion_completionr}      s    99;-L

$

=! ''(/:-: ( < .555E0@@@$EG-WY Y  	CJ%4MX-K5(M'*d2	! 
$, 6C[QS Sr   )F)
__future__r   r   r   rw   __metaclass__rf   r   r&   r.   r4   r;   r   r   rE   r   r   r   r   r    r   rn   r}   r   r   r   <module>r      sn    C B 	 	: 	%
.	$
*
,
*
(	 	
		$#UL Sr   