
    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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: voss
short_description: Use voss cliconf to run command on Extreme VOSS platform
description:
  - This voss plugin provides low level abstraction apis for
    sending and receiving CLI commands from Extreme VOSS network devices.
N)AnsibleConnectionFailure)to_text)Mapping)NetworkConfigdumps)to_list)VossNetworkConfig)CliconfBaseenable_modec                   r     e Zd Zedd       ZddZedd       ZddZd Zd Z	d Z
 fdZdd	Zd
 Z xZS )Cliconfc                     |dvrt        d|z        |rt        d|z        |sg }|dk(  r0d}|dj                  t        |            z  }|j                         }nd}| j	                  |      S )N)runningstartupz/fetching configuration from %s is not supportedz1'format' value %s is not supported for get_configr   zshow running-config  zmore /intflash/config.cfg)
ValueErrorjoinr   stripsend_command)selfsourceflagsformatcmds        j/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/network/plugins/cliconf/voss.py
get_configzCliconf.get_config2   s    //NQWWXXPSYYZZEY(C388GEN++C))+C-C  %%    c           	         i }| j                         }| j                         }	||d   rt        d      ||	d   vr#t        d|ddj                  |	d               ||	d   vr#t        d|ddj                  |	d               t	        d	|
      }
|
j                  |       |r)|dk7  r$t	        d	||      }|
j                  ||||      }n|
j                  }|rt        |d      nd|d<   ||d<   ||d<   |S )a.	  
        Generate diff between candidate and running configuration. If the
        remote host supports onbox diff capabilities ie. supports_onbox_diff in that case
        candidate and running configurations are not required to be passed as argument.
        In case if onbox diff capability is not supported candidate argument is mandatory
        and running argument is optional.
        :param candidate: The configuration which is expected to be present on remote host.
        :param running: The base configuration which is used to generate diff.
        :param diff_match: Instructs how to match the candidate configuration with current device configuration
                      Valid values are 'line', 'strict', 'exact', 'none'.
                      'line' - commands are matched line by line
                      'strict' - command lines are matched with respect to position
                      'exact' - command lines must be an equal match
                      'none' - will not compare the candidate configuration with the running configuration
        :param diff_ignore_lines: Use this argument to specify one or more lines that should be
                                  ignored during the diff.  This is used for lines in the configuration
                                  that are automatically updated by the system.  This argument takes
                                  a list of regular expressions or exact line matches.
        :param path: The ordered set of parents that uniquely identify the section or hierarchy
                     the commands should be checked against.  If the parents argument
                     is omitted, the commands are checked against the set of top
                    level or global commands.
        :param diff_replace: Instructs on the way to perform the configuration on the device.
                        If the replace argument is set to I(line) then the modified lines are
                        pushed to the device in configuration mode.  If the replace argument is
                        set to I(block) then the entire command block is pushed to the device in
                        configuration mode if any line is not correct.
        :return: Configuration diff in  json format.
               {
                   'config_diff': '',
               }

        supports_generate_diffz4candidate configuration is required to generate diff
diff_matchz'match' value z in invalid, valid values are z, diff_replacez'replace' value r   )indentignore_linesnone)r%   contentsr&   )pathmatchreplacecommands config_diff	diff_path)	get_device_operationsget_option_valuesr   r   r   load
differenceitemsr
   )r   	candidater   r#   diff_ignore_linesr)   r$   diffdevice_operationsoption_valuescandidate_objrunning_objconfigdiffobjss                r   get_diffzCliconf.get_diffE   s[   D  668..0!23K!LSTT]<88S]_c_h_hiv  xD  jE  `F  G  H  H}^<<Uacgclclmz  |J  nK  dL  M  N  N *ARS9%zV++1wUfgK*55kT^ht5uN +00NCQeNJ?WY] [+^r    c                    i }| j                         }| j                  |||||       g }g }|r| j                  d       t        |      D ]\  }	t	        |	t
              sd|	i}	|	d   }
|
dk7  s"|
d   dk7  s+|j                   | j                  d	i |	       |j                  |
       ^ | j                  d       nt        d      ||d<   ||d<   |S )
Nzconfigure terminalcommandendr   !zcheck mode is not supportedrequestresponse )r0   check_edit_config_capabilityr   r   
isinstancer   appendr   )r   r5   commitr+   commentresp
operationsresultsrequestsliner   s              r   edit_configzCliconf.edit_config   s    //1
))*iRYZ23	* )!$0%t,D9o%<CFcMNN#44#4#4#<t#<=OOC() e$:;;"Y"Zr    c                 0    | j                  ||||||      S )N)r?   promptanswersendonlynewline	check_all)r   )r   r?   rQ   rR   rS   rT   rU   s          r   getzCliconf.get   s-      Yakr  H   I  	Ir    c                 v   i }d|d<   | j                  d      }t        |d      j                         }t        j                  d|      }|r|j                  d      |d	<   t        j                  d
|      }|r|j                  d      |d<   t        j                  d|      }|r|j                  d      |d<   |S )Nvoss
network_oszshow sys-info)r?   surrogate_or_strict)errorszSysDescr\s+: \S+ \((\S+)\)   network_os_versionzChassis\s+: (\S+)network_os_modelzSysName\s+: (\S+)network_os_hostname)rV   r   r   researchgroup)r   device_inforeplydatar*   s        r   get_device_infozCliconf.get_device_info   s    $*L!1u%:;AAC		7>05AK,-		.5.3kk!nK*+		.516QK-.r    c                     ddddddddddddS )NTF)supports_diff_replacesupports_commitsupports_rollbacksupports_defaultssupports_onbox_diffsupports_commit_commentsupports_multiline_delimitersupports_diff_matchsupports_diff_ignore_linesr"   supports_replacerD   r   s    r   r0   zCliconf.get_device_operations   s-    %)$!&!%#(',,1#'*.&* %
 	
r    c                     dgg dddgg dS )Ntext)rN   strictexactr'   rN   block)r   r#   r$   outputrD   rr   s    r   r1   zCliconf.get_option_values   s    h=#W-	
 	
r    c                     t         t        |          }|dxx   g dz  cc<   | j                         |d<   |j	                  | j                                t        j                  |      S )Nrpc)r=   run_commandsget_defaults_flagr8   )superr   get_capabilitiesr0   updater1   jsonr
   )r   result	__class__s     r   r~   zCliconf.get_capabilities   sY    w68uJJ&*&@&@&B"#d,,./zz&!!r    c                 T   |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|      }Y d }~3d }~ww xY w)Nz'commands' value is requiredr?   rx   z3'output' value %s is not supported for run_commandserrrD   )
r   listr   rF   r   popr   r   getattrrG   )r   r,   check_rc	responsesr   rx   outes           r   r{   zCliconf.run_commands   s    ;<<F	8$ 	"Cc7+ #&WWXt,F !VY_!_``+'d''.#. S!	""  , +a*+s   B	B'B""B'c                      y)NverboserD   rr   s    r   r|   zCliconf.get_defaults_flag   s    r    )r   NN)NNrN   NNrN   )NTNN)NNFTF)NT)__name__
__module____qualname__r   r   r=   rO   rV   rf   r0   r1   r~   r{   r|   __classcell__)r   s   @r   r   r   0   sS    & &$?B  4I*

"0r    r   )
__future__r   r   r   type__metaclass__DOCUMENTATIONr`   r   ansible.errorsr   ansible.module_utils._textr   /ansible.module_utils.common._collections_compatr   Pansible_collections.ansible.netcommon.plugins.module_utils.network.common.configr	   r
   Oansible_collections.ansible.netcommon.plugins.module_utils.network.common.utilsr   Lansible_collections.community.network.plugins.module_utils.network.voss.vossr   ansible.plugins.cliconfr   r   r   rD   r    r   <module>r      sE   & C B 
  3 . C q c j <@k @r    