
    VhH                       d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z
ddlmZ ddlmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddl m!Z!m"Z"m#Z#m$Z$m%Z%  ejL                  d	
       G d de             Z' ejL                  d	
       G d d             Z(ejL                   G d dejR                               Z*ejL                   G d dejR                               Z+ejL                   G d de+             Z,ejL                   G d de+             Z-ejL                   G d de*ejR                               Z.ejL                   G d de.ejR                               Z/ejL                   G d de*ejR                               Z0ejL                   G d de.             Z1ejL                   G d  d!e*             Z2ejL                   G d" d#e/e.             Z3ejL                   G d$ d%e0e/e.             Z4ejL                   G d& d'e*ejR                               Z5ejL                   G d( d)e0e5             Z6ejL                   G d* d+e2e5             Z7ejL                   G d, d-e*ejR                               Z8ejL                   G d. d/e0e8             Z9ejL                   G d0 d1e2e8             Z:ejL                   G d2 d3e/e.             Z;ejL                   G d4 d5e.             Z< G d6 d7ejz                        Z> ejL                  d	
       G d8 d9             Z? ejL                  d	
       G d: d;             Z@y)<z7Configuration for the test hosts requested by the user.    )annotationsN   )SUPPORTED_PYTHON_VERSIONS)open_binary_file)	AuditModeCGroupVersionCompletionConfigdocker_completionDockerCompletionConfigInventoryCompletionConfignetwork_completionNetworkRemoteCompletionConfigPosixCompletionConfigPosixRemoteCompletionConfigPosixSshCompletionConfigremote_completionRemoteCompletionConfigwindows_completionWindowsRemoteCompletionConfigfilter_completion)find_pythonget_available_python_versionsstr_to_versionversion_to_strArchitectureT)frozenc                  P     e Zd ZdZd fdZedd       ZddZed	d       Z xZ	S )
OriginCompletionConfigz(Pseudo completion config for the origin.c                &    t         |   d       y )Norigin)name)super__init__)self	__class__s    S/home/dcms/DCMS/lib/python3.12/site-packages/ansible_test/_internal/host_configs.pyr#   zOriginCompletionConfig.__init__4   s    h'    c                    t        t        j                  dd       }t        D cg c]
  }||k(  s	| c}t        D cg c]
  }||k7  s	| c}z   }|S c c}w c c}w )z/Return a list of the supported Python versions.N   )r   sysversion_infor   )r$   current_versionversionversionss       r&   supported_pythonsz(OriginCompletionConfig.supported_pythons7   s]     ))9)9"1)=>+DcSbHbGc+DcSbHbGcd dcs   
AA
A	Ac                    t        |      }|S )z0Return the path of the requested Python version.)r   )r$   r-   s     r&   get_python_pathz&OriginCompletionConfig.get_python_path?   s    g&r'   c                     y)zHTrue if the completion entry is only used for defaults, otherwise False.F r$   s    r&   
is_defaultz!OriginCompletionConfig.is_defaultD   s     r'   returnNone)r7   	list[str])r-   strr7   r:   r7   bool)
__name__
__module____qualname____doc__r#   propertyr/   r1   r5   __classcell__r%   s   @r&   r   r   0   s8    2(  
  r'   r   c                  .    e Zd ZU dZded<   edd       Zy)HostContextzHContext used when getting and applying defaults for host configurations.zt.Optional['PosixConfig']controller_configc                    | j                    S )z;True if the context is for the controller, otherwise False.rF   r4   s    r&   
controllerzHostContext.controllerP   s     ))))r'   Nr;   )r=   r>   r?   r@   __annotations__rA   rI   r3   r'   r&   rE   rE   J   s    R00* *r'   rE   c                  n    e Zd ZdZej
                  dd       Zej
                  dd       Zedd       Z	y)	
HostConfigz"Base class for host configuration.c                     yReturn the default settings.Nr3   r$   contexts     r&   get_defaultszHostConfig.get_defaultsZ       r'   c                     yApply default settings.Nr3   r$   rQ   defaultss      r&   apply_defaultszHostConfig.apply_defaults^   rS   r'   c                     y)
        True if the host is a managed instance, otherwise False.
        Managed instances are used exclusively by ansible-test and can safely have destructive operations performed without explicit permission from the user.
        Fr3   r4   s    r&   
is_managedzHostConfig.is_managedb        r'   N)rQ   rE   r7   r	   rQ   rE   rX   r	   r7   r8   r;   )
r=   r>   r?   r@   abcabstractmethodrR   rY   rA   r\   r3   r'   r&   rL   rL   V   sK    ,+ + 	& &  r'   rL   )	metaclassc                      e Zd ZU dZdZded<   dZded<   ed
d       Zedd       Z	ddZ
eej                  dd	              Zy)PythonConfigzConfiguration for Python.Nt.Optional[str]r-   pathc                ,    t        | j                        S )z%Return the Python version as a tuple.)r   r-   r4   s    r&   tuplezPythonConfig.tupler   s     dll++r'   c                     | j                   d   S )z Return the Python major version.r   )rg   r4   s    r&   major_versionzPythonConfig.major_versionw   s     zz!}r'   c                j   | j                   dv r |j                  |j                        | _         | j                  rY| j                  j	                  d      r=t
        j                  j                  | j                  d| j                          | _        yy|j                  | j                         | _        y)rV   )Ndefault/pythonN)r-   get_default_pythonrI   re   endswithosjoinr1   rW   s      r&   rY   zPythonConfig.apply_defaults|   s    <<,,#66w7I7IJDL99yy!!#&GGLLfT\\N4KL	 '
 !00>DIr'   c                     y)
        True if this Python is a managed instance, otherwise False.
        Managed instances are used exclusively by ansible-test and can safely have requirements installed without explicit permission from the user.
        Nr3   r4   s    r&   r\   zPythonConfig.is_managed   rS   r'   )r7   ztuple[int, ...])r7   intrQ   rE   rX   r   r7   r8   r;   )r=   r>   r?   r@   r-   rJ   re   rA   rg   ri   rY   r_   r`   r\   r3   r'   r&   rc   rc   k   sf    ##G_# D/ , ,  ?   r'   rc   c                  "    e Zd ZdZedd       Zy)NativePythonConfigz Configuration for native Python.c                     y)rs   Fr3   r4   s    r&   r\   zNativePythonConfig.is_managed   r]   r'   Nr;   )r=   r>   r?   r@   rA   r\   r3   r'   r&   rw   rw      s    * r'   rw   c                  F     e Zd ZU dZdZded<   d fdZedd       Z xZ	S )	VirtualPythonConfigz2Configuration for Python in a virtual environment.Nt.Optional[bool]system_site_packagesc                N    t         |   ||       | j                  d| _        yyrV   NF)r"   rY   r|   r$   rQ   rX   r%   s      r&   rY   z"VirtualPythonConfig.apply_defaults   s+    w1$$,(-D% -r'   c                     y)rs   Tr3   r4   s    r&   r\   zVirtualPythonConfig.is_managed        r'   ru   r;   )
r=   r>   r?   r@   r|   rJ   rY   rA   r\   rB   rC   s   @r&   rz   rz      s+    <-1*1.  r'   rz   c                       e Zd ZU dZdZded<   eej                  dd              Z	ej                  d	d       Z
d
 fdZ xZS )PosixConfigz(Base class for POSIX host configuration.Nzt.Optional[PythonConfig]rm   c                     y)+True if root is available, otherwise False.Nr3   r4   s    r&   	have_rootzPosixConfig.have_root   rS   r'   c                     yrN   r3   rP   s     r&   rR   zPosixConfig.get_defaults   rS   r'   c                    t        |t              sJ t        |   ||       | j                  xs
 t               | _        | j                  j                  ||       yrU   )
isinstancer   r"   rY   rm   rw   r   s      r&   rY   zPosixConfig.apply_defaults   sK    ($9:::w1kk9%7%9""7H5r'   r;   rQ   rE   r7   r   r^   )r=   r>   r?   r@   rm   rJ   rA   r_   r`   r   rR   rY   rB   rC   s   @r&   r   r      sU    2'+F$+:  : 	+ +6 6r'   r   c                  6    e Zd ZdZej
                  dd       Zy)ControllerHostConfigz@Base class for host configurations which support the controller.c                     y)0Return the default targets for this host config.Nr3   rP   s     r&   get_default_targetsz(ControllerHostConfig.get_default_targets   rS   r'   NrQ   rE   r7   zlist[ControllerConfig])r=   r>   r?   r@   r_   r`   r   r3   r'   r&   r   r      s    J? ?r'   r   c                       e Zd ZU dZdZded<   dZded<   dZded<   edd       Z	edd       Z
d fd	Zedd
       Z xZS )RemoteConfigz)Base class for remote host configuration.Nrd   r!   providerarchc                >    | j                   j                  d      d   S )zThe name of the platform.rl   r   r!   	partitionr4   s    r&   platformzRemoteConfig.platform        yy""3'**r'   c                >    | j                   j                  d      d   S )zThe version of the platform.rl   r)   r   r4   s    r&   r-   zRemoteConfig.version   r   r'   c                   t        |t              sJ t        |   ||       | j                  dk(  rd| _        | j                  xs |j                  xs d| _        | j
                  xs |j
                  xs t        j                  | _        y)rV   rk   Naws)r   r   r"   rY   r   r   r   X86_64r   s      r&   rY   zRemoteConfig.apply_defaults   sp    ($:;;;w1==I% DMC):):CeIIEE,2E2E	r'   c                     yz
        True if this host is a managed instance, otherwise False.
        Managed instances are used exclusively by ansible-test and can safely have destructive operations performed without explicit permission from the user.
        Tr3   r4   s    r&   r\   zRemoteConfig.is_managed   r   r'   )r7   r:   r^   r;   )r=   r>   r?   r@   r!   rJ   r   r   rA   r   r-   rY   r\   rB   rC   s   @r&   r   r      sd    3 D/  $Ho$ D/ + + + +
F  r'   r   c                  V    e Zd ZU dZdZded<   dZded<   dZded<   d
dZe	dd	       Z
y)PosixSshConfigz#Configuration for a POSIX SSH host.Nrd   userhostt.Optional[int]portc                D    t        | j                  | j                        S )rO   )r   r   )r   r   r   rP   s     r&   rR   zPosixSshConfig.get_defaults  s    '
 	
r'   c                     | j                   dk(  S )r   root)r   r4   s    r&   r   zPosixSshConfig.have_root  s     yyF""r'   )rQ   rE   r7   r   r;   )r=   r>   r?   r@   r   rJ   r   r   rR   rA   r   r3   r'   r&   r   r      s<    - D/  D/  D/ 
 # #r'   r   c                  0    e Zd ZU dZdZded<   ddZddZy)	InventoryConfigzConfiguration using inventory.Nrd   re   c                    t               S rO   )r   rP   s     r&   rR   zInventoryConfig.get_defaults  s    (**r'   c                (    t        |t              sJ yrU   )r   r   rW   s      r&   rY   zInventoryConfig.apply_defaults  s    ($=>>>r'   )rQ   rE   r7   r   r^   )r=   r>   r?   r@   re   rJ   rR   rY   r3   r'   r&   r   r     s    ( D/ +?r'   r   c                       e Zd ZU dZdZded<   dZded<   dZded<   dZded	<   dZ	ded
<   dZ
ded<   dZded<   ddZddZd fdZedd       Zedd       Z xZS )DockerConfigz Configuration for a docker host.Nrd   r!   imager   memoryr{   
privilegedseccompzt.Optional[CGroupVersion]cgroupzt.Optional[AuditMode]auditc                    t        t                     j                  | j                        xs" t	        | j                  | j                  d      S )rO   T)r!   r   placeholder)r   r
   getr!   r   rP   s     r&   rR   zDockerConfig.get_defaults.  sA     !2!4599$))D 
H^))I
 	
r'   c           
        | j                   t        t                     v r;| j                  |      }|j                  D ci c]  }||j                  |       }}n@|j                  j                  j                  |j                  j                  j                  i}|j                         D cg c]  \  }}t        t        ||             c}}S c c}w c c}}w r   )r-   re   )rm   )r!   r   r
   rR   r/   r1   rF   rm   r-   re   itemsControllerConfigrw   r$   rQ   rX   r-   pythonsre   s         r&   r   z DockerConfig.get_default_targets6      99)*;*=>>((1HQYQkQklgw 8 8 AAlGl0077??AZAZAaAaAfAfgGmtmzmzm|}\i\cei (:7QU(VW}}	 m ~   C.!Cc                d   t        |t              sJ t        |   ||       |j                  | _        |j
                  | _        | j                  |j                  | _        | j                  |j                  | _        | j                  |j                  | _	        | j                  d| _        yyr~   )r   r   r"   rY   r!   r   r   r   cgroup_enumr   
audit_enumr   r   s      r&   rY   zDockerConfig.apply_defaults@  s    ($:;;;w1MM	^^
<<#++DL;;"..DK::!,,DJ??"#DO #r'   c                     yr   r3   r4   s    r&   r\   zDockerConfig.is_managedU  r   r'   c                     yr   Tr3   r4   s    r&   r   zDockerConfig.have_root]       r'   )rQ   rE   r7   r   r   r^   r;   )r=   r>   r?   r@   r!   rJ   r   r   r   r   r   r   rR   r   rY   rA   r\   r   rB   rC   s   @r&   r   r   "  s    * D/ !E?!"FO"#'J '#G_#(,F%,#'E '
~$*    r'   r   c                  V     e Zd ZU dZdZded<   d	dZd
dZd fdZe	dd       Z
 xZS )PosixRemoteConfigz&Configuration for a POSIX remote host.Nrd   becomec                    t        t                     j                  | j                        xs< t               j                  | j                        xs t        | j                  d      S rO   T)r!   r   )r   r   r   r!   r   r   rP   s     r&   rR   zPosixRemoteConfig.get_defaultsi  s]     !!2!4599$))D 
HYH[H_H_`d`m`mHn 
  sNs
 	
r'   c           
        | j                   t        t                     v r;| j                  |      }|j                  D ci c]  }||j                  |       }}n@|j                  j                  j                  |j                  j                  j                  i}|j                         D cg c]  \  }}t        t        ||             c}}S c c}w c c}}w r   )r!   r   r   rR   r/   r1   rF   rm   r-   re   r   r   rw   r   s         r&   r   z%PosixRemoteConfig.get_default_targetsq  r   r   c                    t        |t              sJ t        |   ||       | j                  xs |j                  | _        yrU   )r   r   r"   rY   r   r   s      r&   rY   z PosixRemoteConfig.apply_defaults{  s7    ($?@@@w1kk4X__r'   c                     yr   r3   r4   s    r&   r   zPosixRemoteConfig.have_root  r   r'   )rQ   rE   r7   r   r   r^   r;   )r=   r>   r?   r@   r   rJ   rR   r   rY   rA   r   rB   rC   s   @r&   r   r   c  s4    0"FO"
~5  r'   r   c                      e Zd ZdZy)WindowsConfigz*Base class for Windows host configuration.Nr=   r>   r?   r@   r3   r'   r&   r   r         4r'   r   c                  <     e Zd ZU dZdZded<   ddZd fdZ xZS )	WindowsRemoteConfigz(Configuration for a remote Windows host.Nrd   
connectionc                    t        t                     j                  | j                        xs# t               j                  | j                        S r   )r   r   r   r!   r   rP   s     r&   rR   z WindowsRemoteConfig.get_defaults  s;     !3!56::499EpI[I]IaIabfboboIppr'   c                    t        |t              sJ t        |   ||       | j                  xs |j                  | _        yrU   )r   r   r"   rY   r   r   s      r&   rY   z"WindowsRemoteConfig.apply_defaults  s9    ($ABBBw1//@X-@-@r'   )rQ   rE   r7   r   r^   )	r=   r>   r?   r@   r   rJ   rR   rY   rB   rC   s   @r&   r   r     s"    2"&J&qA Ar'   r   c                      e Zd ZdZy)WindowsInventoryConfigz0Configuration for Windows hosts using inventory.Nr   r3   r'   r&   r   r         :r'   r   c                      e Zd ZdZy)NetworkConfigz*Base class for network host configuration.Nr   r3   r'   r&   r   r     r   r'   r   c                  J     e Zd ZU dZdZded<   dZded<   ddZd	 fdZ xZ	S )
NetworkRemoteConfigz(Configuration for a remote network host.Nrd   
collectionr   c                    t        t                     j                  | j                        xs t	        | j                  d      S r   )r   r   r   r!   r   rP   s     r&   rR   z NetworkRemoteConfig.get_defaults  s:     !3!56::499E 
IfJ
 	
r'   c                    t        |t              sJ t        |   ||       | j                  xs |j                  | _        | j
                  xs |j
                  | _        yrU   )r   r   r"   rY   r   r   r   s      r&   rY   z"NetworkRemoteConfig.apply_defaults  sO    ($ABBBw1//@X-@-@//@X-@-@r'   )rQ   rE   r7   r   r^   )
r=   r>   r?   r@   r   rJ   r   rR   rY   rB   rC   s   @r&   r   r     s+    2"&J&"&J&
A Ar'   r   c                      e Zd ZdZy)NetworkInventoryConfigz0Configuration for network hosts using inventory.Nr   r3   r'   r&   r   r     r   r'   r   c                  2    e Zd ZdZddZddZedd       Zy)	OriginConfigz"Configuration for the origin host.c                    t               S r   )r   rP   s     r&   rR   zOriginConfig.get_defaults  s    %''r'   c           
         t               j                         D cg c]  \  }}t        t        ||             c}}S c c}}w r   )r   r   r   rw   )r$   rQ   r-   re   s       r&   r   z OriginConfig.get_default_targets  sX     nK  nM  nS  nS  nU  V\i\cei (:7QU(VW  V  	V  Vs   !Ac                0    t        j                         dk(  S )r   r   )rp   getuidr4   s    r&   r   zOriginConfig.have_root  s     yy{ar'   N)rQ   rE   r7   r   r   r;   )r=   r>   r?   r@   rR   r   rA   r   r3   r'   r&   r   r     s$    ,(V    r'   r   c                  `     e Zd ZU dZdZded<   d	dZd
 fdZedd       Z	edd       Z
 xZS )r   z&Configuration for the controller host.Nzt.Optional[PosixConfig]rI   c                8    |j                   j                  |      S r   )rF   rR   rP   s     r&   rR   zControllerConfig.get_defaults  s    ((55g>>r'   c                    t        |t              sJ |j                  | _        | j                  s'|j
                  s|j                  j                  | _        t        |   ||       yrU   )r   r   rF   rI   rm   r/   r"   rY   r   s      r&   rY   zControllerConfig.apply_defaults  sR    ($9:::!33{{8#=#=!33::DKw1r'   c                .    | j                   j                  S )r[   )rI   r\   r4   s    r&   r\   zControllerConfig.is_managed  s     )))r'   c                .    | j                   j                  S )r   )rI   r   r4   s    r&   r   zControllerConfig.have_root  s     (((r'   r   r^   r;   )r=   r>   r?   r@   rI   rJ   rR   rY   rA   r\   r   rB   rC   s   @r&   r   r     sC    0*.J'.?
2 * * ) )r'   r   c                  T    e Zd ZdZ ej
                         Z ej
                         Zy)FallbackReasonzReason fallback was performed.N)r=   r>   r?   r@   enumautoENVIRONMENTPYTHONr3   r'   r&   r   r     s    ($))+KTYY[Fr'   r   c                  &    e Zd ZU dZded<   ded<   y)FallbackDetailz+Details about controller fallback behavior.r   reasonr:   messageN)r=   r>   r?   r@   rJ   r3   r'   r&   r   r     s    5Lr'   r   c                  f    e Zd ZU dZded<   ded<   ded<   ded<   d	ed
<   ddZedd       ZddZy)HostSettingsz-Host settings for the controller and targets.r   rI   zlist[HostConfig]targetsr9   skipped_python_versionsfiltered_argszt.Optional[FallbackDetail]controller_fallbackc                r    t        |d      5 }t        j                  | |       ddd       y# 1 sw Y   yxY w)z.Serialize the host settings to the given path.wbN)r   pickledump)r$   re   settings_files      r&   	serializezHostSettings.serialize  s1    dD) 	-]KKm,	- 	- 	-s   -6c                n    t        |       5 }t        j                  |      cddd       S # 1 sw Y   yxY w)z(Deserialize host settings from the path.N)r   r  load)re   r  s     r&   deserializezHostSettings.deserialize  s/     d# 	.};;}-	. 	. 	.s   +4c                   t        d      }| j                  j                  || j                  j                  |             | j                  D ]9  }t        | j                        }|j                  ||j                  |             ; y)z$Apply defaults to the host settings.NrH   )rE   rI   rY   rR   r   )r$   rQ   targets      r&   rY   zHostSettings.apply_defaults"  sm    5&&w0L0LW0UVll 	IF!DOODG!!'6+>+>w+GH	Ir'   N)re   r:   r7   r8   )re   r:   r7   r   r6   )	r=   r>   r?   r@   rJ   r  staticmethodr  rY   r3   r'   r&   r   r     sB    7$$&&33-
 . .
Ir'   r   )Ar@   
__future__r   r_   dataclassesr   rp   r  r*   typingt	constantsr   ior   
completionr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   utilr   r   r   r   r   	dataclassr   rE   ABCMetarL   rc   rw   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Enumr   r   r   r3   r'   r&   <module>r     s   = " 
   	  
     &  d#2  $2 d#* * $* 3;;  ( #S[[ # #L 	 	 	 ,  * 6* 6 60 ?;#++ ? ? #: # #L #[ # #( ?j ? ? =' = =@ "&:K " "J 5J#++ 5 5 A, A A$ ;_m ; ; 5J#++ 5 5 A, A A. ;_m ; ;  '    "  ){  )  )FTYY  d#  $ d#I I $Ir'   