
    Vh                     "   d dl mZmZmZ eZd dlZd dlmZ d dl	m
Z
 d dlmZmZ d dlmZ d dlmZmZ i Z e        ed	       ee
d
gf       ee
dgfd       ee
dgfd       ed	      dZi Zd Zd Zd Zd ZddZd Zd ZddZd Zy)    )absolute_importdivisionprint_functionN)	to_native)env_fallback)to_listComplexList)LooseVersion)
ConnectionConnectionErrorint)typeANSIBLE_NET_USERNAME)fallbackANSIBLE_NET_PASSWORDT)r   no_logANSIBLE_NET_SSH_KEYFILEpath)r   r   )hostportusernamepasswordssh_keyfiletimeoutc                      t         S N)routeros_provider_spec     t/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/routeros/plugins/module_utils/routeros.pyget_provider_argspecr!      s    !!r   c                    t        | d      r| j                  S t        |       }|j                  d      }|dk(  r&t	        | j
                        | _        | j                  S | j                  d|z         | j                  S )N_routeros_connectionnetwork_apicliconfzInvalid connection type %smsg)hasattrr#   get_capabilitiesgetr   _socket_path	fail_json)modulecapabilitiesr$   s      r    get_connectionr/       s    v-.***#F+L""=1Ki&01D1D&E# &&& 	9KGH&&&r   c                 ,   t        | d      r| j                  S 	 t        | j                        j	                         }t        j                  |      | _        | j                  S # t        $ r'}| j                  t        |d             Y d }~y d }~ww xY w)N_routeros_capabilitiessurrogate_then_replaceerrorsr&   )
r(   r1   r   r+   r)   jsonloadsr   r,   r   )r-   r.   excs      r    r)   r)   .   s    v/0,,,N!&"5"56GGI(,

<(@%,,, NYs3KLMMNs   AA# #	B,BBc                    t        |       }	 |j                  d      }t	        d      }t               }|j                         D ]C  }|j                         s|j                  |j                         j                         d          E d|v rdgS dgS # t        $ r'}| j                  t	        |d             Y d }~d }~ww xY w)Nz#/system default-configuration printr2   r3   r&   r   allfull)
r/   r*   r   r,   r   set
splitlinesstripaddsplit)r-   
connectionoutr7   commandslines         r    get_defaults_flagrD   :   s    'JNnnBC C 8
9CuH  2::<LL++-a012 wx  NYs3KLMMNs   B 	CC  Cc                 X   dj                  t        |            }	 t        |   S # t        $ r{ t	        |       }	 |j                  |      }n3# t        $ r'}| j                  t        |d             Y d }~nd }~ww xY wt        d      j                         }|t        |<   |cY S w xY w)N )flagsr2   r3   r&   )
joinr   _DEVICE_CONFIGSKeyErrorr/   
get_configr   r,   r   r=   )r-   rG   flag_strr@   rA   r7   cfgs          r    rK   rK   O   s    xx'Hx(( 
#F+
	R''e'4C 	R37O!PQQ	R $<=CCE$'!

s8   % B)AB)	A=A83B)8A==)B)(B)c                 j    t        d      t               t               d}t        ||       } ||      S )NT)key)commandpromptanswer)dictr	   )r-   rB   spec	transforms       r    to_commandsrV   a   s3    D>&&D
 D&)IXr   c                     t        |       }|j                  di       j                  d      }|yt        d      t        |      cxk  xr t        d      k  S c S )ztDetermines whether adding a leading space to the command is needed
    to workaround prompt bug in 6.49 <= ROS < 7.2device_infonetwork_os_versionFz6.49z7.2)r)   r*   r
   )r-   r.   rY   s      r    should_add_leading_spacerZ   k   s]     $F+L%))-<@@AUV!<0B#CYlSXFYYYYYr   c           
         t               }t        |       }t        |      D ]k  }t        |t              r|d   }|d   }|d   }n|}d }d }t        |       rd|z   }	 |j                  |||      }		 t        	d      }	|j                  |	       m |S # t        $ r'}
| j                  t        |
d             Y d }
~
Nd }
~
ww xY w# t        $ r$ | j                  d	|d
t        	             Y tw xY w)NrP   rQ   rR   rF   r2   r3   r&   surrogate_or_strictzFailed to decode output from z: )listr/   r   
isinstancerS   rZ   r*   r   r,   r   UnicodeErrorappend)r-   rB   check_rc	responsesr@   cmdrP   rQ   rR   rA   r7   s              r    run_commandsrd   u   s   I'Jx  c4 )nG]F]FGFF#F+GmG	R..&&9C	TC(=>C
 	14   	R37O!PQQ	R
  	T>A9S>R  T	Ts*   B/C	CB<<C*C10C1c                 <    t        |       }|j                  |      }y r   )r/   edit_config)r-   rB   r@   rA   s       r    load_configrg      s    'J

 
 
*Cr   r   )T) 
__future__r   r   r   r   __metaclass__r5   +ansible.module_utils.common.text.convertersr   ansible.module_utils.basicr   Oansible_collections.ansible.netcommon.plugins.module_utils.network.common.utilsr   r	   Cansible_collections.community.routeros.plugins.module_utils.versionr
   ansible.module_utils.connectionr   r   rI   rS   r   routeros_argument_specr!   r/   r)   rD   rK   rV   rZ   rd   rg   r   r   r    <module>rp      s   
 A @  A 3 p \ G Fe|.D-EFG|.D-EFtT,1J0K!LSYZ   "'	N*$ZB+r   