
    VhY                         d dl mZmZmZ eZdZd dlZd dlm	Z	 d dl
mZmZ d dlmZ d dlmZ d dlmZmZ  G d	 d
e      Zy)    )absolute_importdivisionprint_functionz
---
name: sonic
short_description: Use sonic cliconf to run command on Dell SONiC platforms
description:
  - This sonic plugin provides low level abstraction apis for
    sending and receiving CLI commands on Dell SONiC network devices.
N)AnsibleConnectionFailure)to_bytesto_text)Mapping)to_list)CliconfBaseenable_modec                   \     e Zd Zd Zed        Zedd       Zd	dZ fdZd
dZ	d Z
 xZS )Cliconfc                     i }d|d<   |S )Nsonic
network_os )selfdevice_infos     r/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/dellemc/enterprise_sonic/plugins/cliconf/sonic.pyget_device_infozCliconf.get_device_info,   s    $+L!    c                 >   g }| j                  d       t        |      D ]j  }t        |t              r/| j	                  |d   |d   |d         }|j                  |       B|j                  | j                  t        |                   l | j                  d       |S )Nzconfigure terminalcommandpromptanswer)r   r   r   end)send_commandr
   
isinstancedictgetappendr   )r   r   responsecmdresps        r   edit_configzCliconf.edit_config1   s    ./7# 	BC#t$xxIs8}UXYaUbxc% 1 1(3- @A	B 	% r   c                     |dvrt        d|z        |sg }|dk(  rd}nd}|dj                  t        |            z  }|j                         }| j	                  |      S )N)runningstartupz/fetching configuration from %s is not supportedr'   zshow running-config zshow startup-config  )
ValueErrorjoinr
   stripr   )r   sourceflagsformatr#   s        r   
get_configzCliconf.get_config>   so    //AFJ  EY(C(Csxx''iik  %%r   c                 0    | j                  ||||||      S )N)r   r   r   sendonlynewline	check_all)r   )r   r   r   r   r2   r3   r4   s          r   r    zCliconf.getO   s-      Yakr  H   I  	Ir   c                 R    t         t        |          }t        j                  |      S )N)superr   get_capabilitiesjsondumps)r   result	__class__s     r   r7   zCliconf.get_capabilitiesR   s!    w68zz&!!r   c           	      f   |t        d      t               }t        |      D ]\  }t        |t              sd|i}|j                  dd       }|rt        d|z        	  | j                  di |}|j                  |       ^ |S # t        $ r#}|r t        |dt        |            }Y d }~<d }~ww xY w)Nz'commands' value is requiredr   outputz3'output' value %s is not supported for run_commandserrr   )r*   listr
   r   r	   popr   r   getattrr   r!   )r   commandscheck_rc	responsesr#   r=   outes           r   run_commandszCliconf.run_commandsV   s    ;<<F	8$ 	"Cc7+ #&WWXt,F !VY_!_``4'd''.#. S!	""  , 4a
34s   B	B0B++B0c                 V    | j                   j                  r| j                  d       yy)zT
        Make sure we are in the operational cli mode
        :return: None
        z)#)config_contextN)_connection	connected_update_cli_prompt_context)r   s    r   set_cli_prompt_contextzCliconf.set_cli_prompt_contextn   s)    
 %%++4+@ &r   )r'   NN)NNFTF)NT)__name__
__module____qualname__r   r   r%   r0   r    r7   rG   rM   __classcell__)r;   s   @r   r   r   *   sF    
 
 
 & & I"0Ar   r   )
__future__r   r   r   type__metaclass__DOCUMENTATIONr8   ansible.errorsr   ansible.module_utils._textr   r   /ansible.module_utils.common._collections_compatr	   Oansible_collections.ansible.netcommon.plugins.module_utils.network.common.utilsr
   ansible.plugins.cliconfr   r   r   r   r   r   <module>r[      s>   * C B  3 8 C c <JAk JAr   