
    Vh                         d dl mZmZmZ eZdZd dlZd dlZd dl	m
Z
 d dl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_functiona  
---
deprecated:
  removed_in: 6.0.0
  why: This collection and all content in it is unmaintained and deprecated.
  alternative: Unknown.
author: Unknown (!UNKNOWN)
name: ce
short_description: Use ce cliconf to run command on HUAWEI CloudEngine platform
description:
  - This ce plugin provides low level abstraction apis for
    sending and receiving CLI commands from HUAWEI CloudEngine network devices.
N)chain)AnsibleConnectionFailure)to_text)to_list)CliconfBaseenable_modec                   T     e Zd Zd Zedd       Zed        ZddZ fdZd Z	 xZ
S )	Cliconfc                    i }d|d<   | j                  d      }t        |d      j                         }t        j                  d|      }|r#|j                  d      j                  d      |d	<   t        j                  d
|t        j                        }|r|j                  d      |d<   t        j                  d|t        j                        }|r|j                  d      |d<   |S )Nce
network_oszdisplay versionsurrogate_or_stricterrorsz^Huawei.+\n.+\Version\s+(\S+)   ,network_os_versionz^Huawei(.+)\n.+\(\S+\s+\S+\)network_os_modelzHUAWEI\s+(\S+)\s+uptimenetwork_os_hostname)getr   stripresearchgroupM)selfdevice_inforeplydatamatchs        h/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/network/plugins/cliconf/ce.pyget_device_infozCliconf.get_device_info1   s    $(L!*+u%:;AAC		:DA05A0D0DS0IK,-		94F.3kk!nK*+		4dBDDA16QK-.    c                 `    |dvr| j                  d|z        S |sg }d}| j                  |      S )Nrunningz/fetching configuration from %s is not supportedzdisplay current-configuration)invalid_paramssend_command)r   sourceflagsformatcmds        r$   
get_configzCliconf.get_configF   s@    )$&&'X[a'abbE-  %%r&   c           
         g }t        dgt        |      dg      D ]`  }t        |t              r"|d   }|d   }|d   }|j	                  dd      }n|}d }d }d}|j                  | j                  |||d|             b |d	d
 S )Nzconfigure terminalendcommandpromptanswernewlineTFr   )r   r	   
isinstancedictr   appendr*   )r   r2   resultsr.   r3   r4   r5   s          r$   edit_configzCliconf.edit_configR   s    ./1AE7K 	WC#t$i.XX'')T2NN4,,WffeWUV	W q}r&   c                 0    | j                  ||||||      S )N)r2   r3   r4   sendonlyr5   	check_all)r*   )r   r2   r3   r4   r=   r5   r>   s          r$   r   zCliconf.getd   s-      Yakr  H   I  	Ir&   c                 R    t         t        |          }t        j                  |      S )N)superr   get_capabilitiesjsondumps)r   result	__class__s     r$   rA   zCliconf.get_capabilitiesg   s!    w68zz&!!r&   c                 `   | j                   j                  r| j                   j                         }|#t        d| j                   j                  z        t        |d      j                         }|j                  d      r| j                   j                  dd       |j                  d	      r| j                   j                  d
       | j                   j                  d       | j                   j                         }t        |d      j                         }|j                  d      ryyy)zT
        Make sure we are in the operational cli mode
        :return: None
        NzGcli prompt is not identified from the last received response window: %s)messagesurrogate_then_replacer   ]vvvvz'wrong context, sending return to devicez[*zclear configuration candidatereturn)_connection	connected
get_promptr   _last_recv_windowr   r   endswithqueue_message
startswithexec_command)r   outr3   s      r$   set_cli_prompt_contextzCliconf.set_cli_prompt_contextk   s   
 %%""--/C{. 8OQUQaQaQsQs8t u u S)ABHHJF//#&  ..v7`a$$T*$$112QR  --h7&&113 -EFLLN //#& &r&   )r(   Ntext)NNFTF)__name__
__module____qualname__r%   r   r/   r;   r   rA   rU   __classcell__)rE   s   @r$   r   r   /   sA    * 	& 	&  "I"Or&   r   )
__future__r   r   r   type__metaclass__DOCUMENTATIONr   rB   	itertoolsr   ansible.errorsr   ansible.module_utils._textr   Oansible_collections.ansible.netcommon.plugins.module_utils.network.common.utilsr	   ansible.plugins.cliconfr
   r   r    r&   r$   <module>re      sA   & C B 
   3 . c <OOk OOr&   