
    Vh                        d dl mZ dZdZ	 d dlmc mZ d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  e       Z G d	 d
e      Zy# e$ r Y 8w xY w)    )annotationsaC  
author: Michael Scherer (@mscherer) <misc@zarb.org>
name: funcd
short_description: Use funcd to connect to target
description:
  - This transport permits you to use Ansible over Func.
  - For people who have already setup func and that wish to play with ansible, this permit to move gradually to ansible without
    having to redo completely the setup of the network.
options:
  remote_addr:
    description:
      - The path of the chroot you want to access.
    type: string
    default: inventory_hostname
    vars:
      - name: ansible_host
      - name: ansible_func_host
FNT)AnsibleError)ConnectionBase)Displayc                  L    e Zd ZdZdZd ZddZddZed        Z	d Z
d	 Zd
 Zy)
Connectionz Func-based connections Fc                <    || _         || _        || _        d | _        y N)runnerhostportclient)selfr   r   r   argskwargss         n/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/connection/funcd.py__init__zConnection.__init__5   s    		    Nc                p    t         st        d      t        j                  | j                        | _        | S )Nzfunc is not installed)	HAVE_FUNCr   fcClientr   r   )r   r   s     r   connectzConnection.connect<   s*    677ii		*r   c                    |rt        d      t        j                  d| | j                         | j                  j
                  j                  |      | j                     }|d   |d   |d   fS )z$ run a command on the remote minion zHInternal Error: this module does not support optimized module pipeliningzEXEC r   r         )r   displayvvvr   r   commandrun)r   cmdin_datasudoableps        r   exec_commandzConnection.exec_commandC   sk     ijj 	eC5M		2KK##C(3tQqT1Q4r   c                H   | j                  t        j                  j                        s8t        j                  j	                  t        j                  j                  |       } t        j                  j                  |       }t        j                  j	                  ||dd        S )Nr   )
startswithospathsepjoinnormpath)r*   prefixr-   s      r   _normalize_pathzConnection._normalize_pathN   sa    rww{{+77<<T2D77##D)ww||FHQRL11r   c                    | j                  |d      }t        j                  d| d| | j                         | j                  j
                  j                  j                  ||       y)z& transfer a file from local to remote /zPUT  TO r   N)r/   r   r   r   r   localcopyfilesend)r   in_pathout_paths      r   put_filezConnection.put_fileU   sW     ''#6d7)4z2C""'':r   c           	        | j                  |d      }t        j                  d| d| | j                         t	        j
                  d      }| j                  j                  j                  j                  ||       t        j                  t        j                  j                  || j                  t        j                  j                  |            |       t        j                   |       y)z# fetch a file from remote to local r1   zFETCH r2   r   func_ansible)r.   N)r/   r   r   r   tempfilemkdtempr   r3   getfilegetshutilmover)   r*   r,   basenamermtree)r   r6   r7   tmpdirs       r   
fetch_filezConnection.fetch_file\   s     &&w4fWIT(4499E !!8!!%%gv6BGGLLBGG4D4DW4MNPXYfr   c                     y)z. terminate the connection; nothing to do here N )r   s    r   closezConnection.closei   s    r   r
   )NT)__name__
__module____qualname____doc__has_pipeliningr   r   r&   staticmethodr/   r8   rD   rG   rF   r   r   r   r   0   s<    "N	  2 2;r   r   )
__future__r   DOCUMENTATIONr   func.overlord.clientoverlordr   r   ImportErrorr)   r;   r?   ansible.errorsr   ansible.plugins.connectionr   ansible.utils.displayr   r   r   rF   r   r   <module>rV      sc    #& 		%%I 
   ' 5 )
); ;  		s   A AA