
    Vh$                         d dl mZmZmZ eZd dlZd dlZd dlZd dl	m
Z
 d dlmZmZ d dlmZmZ d dlmZ d dlmZ d dlmZ  e       Z G d	 d
e      Zy)    )absolute_importdivisionprint_functionN)AnsibleError)to_bytesto_text)
ConnectionConnectionError)urlsplit)
ActionBase)Displayc                   @     e Zd Zd fd	Zd Zd Zd ZddZd Z xZ	S )	ActionModulec                 ^   d}d }| j                  |      j                  d      d   }| j                  j                  j                  d      d   }t        t
        |   |      }|dk7  r#d|d<   d| j                  j                  z  |d	<   |S 	 | j                  j                  d
   }|}
| j                  j                  j                  d      }| j                  j                  j                  d      }|d}| j                  j                  j                  d      }|d}|dk(  r	 | j                  d       | j                  j                  j                  d
      }t        t!        j"                               }| j$                  j'                         }t(        j*                  j-                  ||      }	 t/        |d      5 }|j1                  t3        |d             d d d        n	 | j9                  |      }|| j<                  j>                  }tA        |      }|jC                  d      }||
}	 | jE                  |||||      }|du r&||d<   ||d<   |dk(  rt)        j6                  |       |S 	 	 |jG                  ||||       |dk(  rt)        j6                  |       ||d<   ||d<   |S # t        $ r}	dd|	z  dcY d }	~	S d }	~	ww xY w# t        $ r }	t        dt        |	            cY d }	~	S d }	~	ww xY w# 1 sw Y   xY w# t4        $ r t)        j6                  |        w xY w# t:        $ r }	t        dt        |	            cY d }	~	S d }	~	ww xY w# t4        $ r}	d|	z  |d	<   Y d }	~	d }	~	ww xY w# t4        $ r1}	t        |	      dk(  r|dk(  rd|d	<   nd|d<   d|	z  |d	<   Y d }	~	d }	~	ww xY w) NF.)	task_varsnetwork_cliTfailedzrconnection type %s is not valid for net_put module, please use fully qualified name of network_cli connection typemsgsrczmissing required argument: %s)r   r   destprotocolscpmodebinarytext)convert_datawbzutf-8)encodingpersistent_command_timeoutchangeddestinationz0Warning: %s idempotency check failed. Check destsourcer#   prototimeoutzNo response from serveriosxrz<Warning: iosxr scp server pre close issue. Please check destzException received: %s)$_get_network_ossplit_play_context
connectionsuperr   run_taskargsKeyErrorget_handle_src_optionr   dictr   struuiduuid4_loaderget_basedirospathjoinopenwriter   	Exceptionremove_get_binary_src_file
ValueError_connectionsocket_pathr	   
get_option_handle_existing_file	copy_file)selftmpr   r"   rD   
network_ospersistent_connectionresultr   excsrc_file_path_namer   r&   r   filenamecwdoutput_filefconnsock_timeout	__class__s                       l/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/ansible/netcommon/plugins/action/net_put.pyr.   zActionModule.run   s   )))4::3?C
 $ 2 2 = = C CC H L|T..C M1#F8R$$//0 5M
 M	**//%(C ! zz""6* 

##J/=E zz""6*<D6>;''U';
 **//%%e,C4::<(H,,**,C'',,sH5K+t, =GGHS7;<=;"77< **66K+&'CD<%D
	U00{D%Q]^G%$+y!(,}%6>IIk*  	?NN" $	    6>IIk"#y $}o  	6< 	0   ;4WS\::;= = 		+&  ;4WS\::;(  	UNQTTF5M	U  	?s|88( %cF5M#'x  83 >u	?s   J. &K 5L K8L (L( 2>M 3M2 .	K	7K>K	K		K5K0*K50K58L=L  L%(	M1MMM	M/M**M/2	N,;&N''N,c                    | j                   j                         }t        t        j                               }t
        j                  j                  ||      }	 |j                  ||||       	 t        |d      5 }|j                         }ddd       t        |d      5 }|j                         }ddd       t%        j&                         }t)        d      }|j+                  |       |j-                         }t%        j&                         }t)        d      }|j+                  |       |j-                         }t        j                  |       ||k(  ry	y# t        $ rd}	t        |	      }
|
j                  d      sd|
v r9t
        j                  j                  |      rt        j                  |       Y d}	~	yY d}	~	Sd}	~	ww xY w# 1 sw Y   ?xY w# 1 sw Y   'xY w# t         t"        f$ r t        j                  |        w xY w)
z
        Determines whether the source and destination file match.

        :return: False if source and dest both exist and have matching sha1 sums, True otherwise.
        r$   zNo such file or directoryzFile doesn't existNTrsurrogate_or_strict)errorsF)r8   r9   r5   r6   r7   r:   r;   r<   get_filer
   r   endswithexistsr@   r=   readIOErrorOSErrorhashlibsha1r   updatedigest)rH   rS   r%   r   r&   r'   rP   rO   tmp_source_filerM   errorrR   new_contentold_contentrb   old_content_bchecksum_oldnew_content_bchecksum_news                      rV   rF   z"ActionModule._handle_existing_file   s    ll&&(tzz|$'',,sH5	MM+	  	fc" 'affh'os+ 'qffh' ||~ 5JKM"{{}||~ 5JKM"{{}
		/"<'7  	CLE~~9:>RV[>[77>>/2IIo. ?\	' '' '! 	IIo&	sU   E /G# ;G	G#  G1G# 	G"AGG	GG# G G# #&H	c                 ^   | j                         }t        j                  j                  |      st	        d      j
                  r|}n;| j                  j                  |d|      }|s| j                  j                  ||      }t        j                  j                  |      st        d      |S )Nr   	templatespath specified in src not found)
_get_working_pathr:   r;   isabsr   schemer8   path_dwim_relativer]   rB   )rH   r   working_pathr%   s       rV   rA   z!ActionModule._get_binary_src_file   s    --/77==%!7!7F\\44\;PSTF88sKww~~f%>??    c                     | j                   j                         }| j                  j                   | j                  j                  j                  }|S )N)r8   r9   r/   _role
_role_path)rH   rP   s     rV   rp   zActionModule._get_working_path   s>    ll&&(::'**""--C
ru   c                    | j                   j                  j                  d      }| j                         }t        j
                  j                  |      st        d      j                  r|}n;| j                  j                  |d|      }|s| j                  j                  ||      }t        j
                  j                  |      st        d      	 t        |d      5 }t        |j                               }d d d        |g}| j                   j(                  |j+                  | j                   j(                  j,                         t/        | j                   d      rH| j                   j0                  j3                         }	|	"|	D ]  }
|j+                  |
j,                          |j+                  t        j
                  j5                  |             || j6                  j8                  j:                  _        | j6                  j?                        | j                   j                  d<   y # 1 sw Y   6xY w# t         $ r5}t        dj#                  ||j$                  |j&                              d }~ww xY w)Nr   rn   ro   rX   z0unable to load src file {0}, I/O error({1}): {2}z_block:) r/   r0   r2   rp   r:   r;   rq   r   rr   r8   rs   r]   r   r=   r   r^   r_   formaterrnostrerrorrw   appendrx   hasattr_blockget_dep_chaindirname_templarenvironmentloader
searchpathtemplate)rH   r   r   rt   r%   rR   template_dataer   	dep_chainroles              rV   r3   zActionModule._handle_src_option   s   jjoo!!%(--/77==%!7!7F\\44\;PSTF88sKww~~f%@AA	fc" 2a ' 12 #^
::'djj..99:tzz9- JJ--;;=	( ) ;"))$//:;"''//&126@!!((3!%!7!7!F

+2 2 	BIIAGGQZZ 	s0   H: H-9H: -H72H: :	I80I33I8c                    d| j                   j                  v rI| j                   j                  d   r0t        j                  d       | j                   j                  d   }|S | j                  j
                  r-t        j                  d       | j                  j
                  }|S d|j                  di       v r'|d   d   rt        j                  d       |d   d   }|S t        d      )NrJ   z%Getting network OS from task argumentz!Getting network OS from inventoryansible_factszGetting network OS from factz1ansible_network_os must be specified on this host)r/   r0   displayvvvvr+   rJ   r2   r   )rH   r   rJ   s      rV   r)   zActionModule._get_network_os   s    4::??*tzz|/LLL@A6J  **LL<=++66J  IMM/2>>/*<8LL78"?3LAJ  RSSru   )NN)T)
__name__
__module____qualname__r.   rF   rA   rp   r3   r)   __classcell__)rU   s   @rV   r   r      s&    kZ+Z$GLru   r   )
__future__r   r   r   type__metaclass__ra   r:   r6   ansible.errorsr   ansible.module_utils._textr   r   ansible.module_utils.connectionr	   r
   +ansible.module_utils.six.moves.urllib.parser   ansible.plugins.actionr   ansible.utils.displayr   r   r    ru   rV   <module>r      sG   
 A @   	  ' 8 G @ - ) )f: fru   