
    Vhs                         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 d d	lmZmZ  G d
 de      Zy)    )absolute_importdivisionprint_functiona  
---
author: Ansible Security Team (@ansible-security)
name: asa
short_description: Use asa cliconf to run command on Cisco ASA platform
description:
- This asa plugin provides low level abstraction apis for sending and receiving CLI
  commands from Cisco ASA network devices.
version_added: 1.0.0
options:
  config_commands:
    description:
    - Specifies a list of commands that can make configuration changes
      to the target device.
    - When `ansible_network_single_user_mode` is enabled, if a command sent
      to the device is present in this list, the existing cache is invalidated.
    version_added: 2.0.0
    type: list
    elements: str
    default: []
    vars:
    - name: ansible_asa_config_commands
N)chain)AnsibleConnectionFailure)to_text)Mapping)to_list)CliconfBaseenable_modec                   l     e Zd Z fdZd Zedd       Zed	d       Z	 	 	 	 	 d
dZ fdZ	ddZ
 xZS )Cliconfc                 :    t        t        | 
  |i | i | _        y N)superr   __init___device_info)selfargskwargs	__class__s      a/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cisco/asa/plugins/cliconf/asa.pyr   zCliconf.__init__@   s    gt%t6v6    c                 j   | j                   si }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<   t	        j
                  d|t        j                        }|r|j                  d      |d<   t	        j
                  d|t        j                        }|r|j                  d      |d<   t	        j
                  d|t        j                        }|r|j                  d      |d<   t	        j
                  d|      }|r|j                  d      |d<   || _         | j                   S )Nasa
network_oszshow versionsurrogate_or_strict)errorszVersion (\S+)   network_os_versionzFirepower .+ Version (\S+)network_os_firepower_versionzDevice .+ Version (\S+)network_os_device_mgr_versionz^Model Id:\s+(.+) \(revisionnetwork_os_modelzHardware:\s+ ([\w-]+)z^(.+) upnetwork_os_hostnamezimage file is "(.+)"network_os_image)r   getr   stripresearchgroupM)r   device_inforeplydatamatchs        r   get_device_infozCliconf.get_device_infoD   st     K(-K%HH^,E5)>?EEGDII.5E49KKN01II;TBE>Ckk!n:;II8$?E?D{{1~;<II=tRTTJE27++a../II6bddCE27++a../IIk46E5:[[^12II5t<E27++a../ +D   r   c                 h    |dvr| j                  d|z        S |dk(  rd}nd}| j                  |      S )N)runningstartupz/fetching configuration from %s is not supportedr2   zshow running-config allzshow startup-config)invalid_paramssend_command)r   sourceflagsformatcmds        r   
get_configzCliconf.get_configl   sK    //&&AFJ  Y+C'C  %%r   c                 `    t        dgt        |      dg      D ]  }| j                  |        y )Nzconfigure terminalend)r   r
   r5   )r   	candidatecommitreplacecommentr9   s         r   edit_configzCliconf.edit_configx   s3    ./1CeWM 	#Cc"	#r   c                 0    | j                  ||||||      S )N)commandpromptanswersendonlynewline	check_all)r5   )r   rC   rD   rE   rF   rG   rH   s          r   r&   zCliconf.get}   s.        ! 
 	
r   c                 R    t         t        |          }t        j                  |      S r   )r   r   get_capabilitiesjsondumps)r   resultr   s     r   rJ   zCliconf.get_capabilities   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 requiredrC   outputz3'output' value %s is not supported for run_commandserr )
ValueErrorlistr
   
isinstancer	   popr5   r   getattrr   append)r   commandscheck_rc	responsesr9   rO   outes           r   run_commandszCliconf.run_commands   s    ;<<F	8$ 	"Cc7+ #&WWXt,F IFR 4'd''.#. S!#	"&  , 4a
34s   B	B0B++B0)r2   Ntext)NTNN)NNFTF)NT)__name__
__module____qualname__r   r0   r   r:   rA   r&   rJ   r]   __classcell__)r   s   @r   r   r   ?   sV    &!P 	& 	& # # 
$"r   r   )
__future__r   r   r   type__metaclass__DOCUMENTATIONrK   r(   	itertoolsr   ansible.errorsr   ansible.module_utils._textr   /ansible.module_utils.common._collections_compatr	   Oansible_collections.ansible.netcommon.plugins.module_utils.network.common.utilsr
   Gansible_collections.ansible.netcommon.plugins.plugin_utils.cliconf_baser   r   r   rQ   r   r   <module>rm      sF   & A @ 0  	  3 . C clk lr   