Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/modules/network/nxos/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_snapshot.pyo

�
�Udac@s�idd6dgd6dd6ZdZdZdZd	d
lZd	d
lZd	dlmZd	dlm	Z	m
Z
d	d
lmZmZd�Z
d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zedkr�e�nd
S(s1.1tmetadata_versiontpreviewtstatustnetworktsupported_bys�
---
module: nxos_snapshot
extends_documentation_fragment: nxos
version_added: "2.2"
short_description: Manage snapshots of the running states of selected features.
description:
    - Create snapshots of the running states of selected features, add
      new show commands for snapshot creation, delete and compare
      existing snapshots.
author:
    - Gabriele Gerbino (@GGabriele)
notes:
    - Tested against NXOSv 7.3.(0)D1(1) on VIRL
    - C(transport=cli) may cause timeout errors.
    - The C(element_key1) and C(element_key2) parameter specify the tags used
      to distinguish among row entries. In most cases, only the element_key1
      parameter needs to specified to be able to distinguish among row entries.
    - C(action=compare) will always store a comparison report on a local file.
options:
    action:
        description:
            - Define what snapshot action the module would perform.
        required: true
        choices: [ add, compare, create, delete, delete_all ]
    snapshot_name:
        description:
            - Snapshot name, to be used when C(action=create)
              or C(action=delete).
    description:
        description:
            - Snapshot description to be used when C(action=create).
    snapshot1:
        description:
            - First snapshot to be used when C(action=compare).
    snapshot2:
        description:
            - Second snapshot to be used when C(action=compare).
    comparison_results_file:
        description:
            - Name of the file where snapshots comparison will be stored when C(action=compare).
    compare_option:
        description:
            - Snapshot options to be used when C(action=compare).
        choices: ['summary','ipv4routes','ipv6routes']
    section:
        description:
            - Used to name the show command output, to be used
              when C(action=add).
    show_command:
        description:
            - Specify a new show command, to be used when C(action=add).
    row_id:
        description:
            - Specifies the tag of each row entry of the show command's
              XML output, to be used when C(action=add).
    element_key1:
        description:
            - Specify the tags used to distinguish among row entries,
              to be used when C(action=add).
    element_key2:
        description:
            - Specify the tags used to distinguish among row entries,
              to be used when C(action=add).
    save_snapshot_locally:
        description:
            - Specify to locally store a new created snapshot,
              to be used when C(action=create).
        type: bool
        default: 'no'
    path:
        description:
            - Specify the path of the file where new created snapshot or
              snapshots comparison will be stored, to be used when
              C(action=create) and C(save_snapshot_locally=true) or
              C(action=compare).
        default: './'
s	
# Create a snapshot and store it locally
- nxos_snapshot:
    action: create
    snapshot_name: test_snapshot
    description: Done with Ansible
    save_snapshot_locally: true
    path: /home/user/snapshots/

# Delete a snapshot
- nxos_snapshot:
    action: delete
    snapshot_name: test_snapshot

# Delete all existing snapshots
- nxos_snapshot:
    action: delete_all

# Add a show command for snapshots creation
- nxos_snapshot:
    section: myshow
    show_command: show ip interface brief
    row_id: ROW_intf
    element_key1: intf-name

# Compare two snapshots
- nxos_snapshot:
    action: compare
    snapshot1: pre_snapshot
    snapshot2: post_snapshot
    comparison_results_file: compare_snapshots.txt
    compare_option: summary
    path: '../snapshot_reports/'
s�
commands:
    description: commands sent to the device
    returned: verbose mode
    type: list
    sample: ["snapshot create post_snapshot Post-snapshot"]
i����N(t
AnsibleModule(tload_configtrun_commands(tnxos_argument_spect
check_argscCs$i|d6dd6g}t||�S(Ntcommandttexttoutput(R(R
tmodule((sN/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_snapshot.pytexecute_show_command�s
c
Cs�g}d}t||�d}|r�|j�}d}x�|D]}i}y_tj||tj�}|j�}	|	d|d<|	d|d<|	d|d<|j|�Wq>tk
r�q>Xq>Wn|S(Nsshow snapshotsisS(?P<name>\S+)\s+(?P<date>\w+\s+\w+\s+\d+\s+\d+:\d+:\d+\s+\d+)\s+(?P<description>.*)tnametdatetdescription(Rt
splitlinestretmatchtDOTALLt	groupdicttappendtAttributeError(
R
texistingR
tbodyt
split_bodytsnapshot_regextsnapshotttemptmatch_snapshottsnapshot_group((sN/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_snapshot.pytget_existing�s$

cCszt�}t}x.|D]&}|jd|dkrt}qqW|tkrv|jdj|jd|jd��n|S(Nt
snapshot_nameRssnapshot create {0} {1}R(tlisttFalsetparamstTrueRtformat(R
texisting_snapshotstcommandstexistR((sN/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_snapshot.pyt
action_create�s	

c
	Csat�}d}g}t||�d}|rld}|jd�}x&|D]}i}	x�|j�D]�}
y0tj||tj�}|j�d|	d<Wntt	fk
r�nXd|
kr�|
jd�d|	d	<qcd
|
kr�|
jd�d|	d<qcd
|
kr%|
jd�d|	d<qcd|
krc|
jd�d|	d<qcqcW|	rJ|j
|	�qJqJWni|jdd6|jd	d	6|jdd6|jdd6|jdp�dd6}||kr]|jdr|j
dj|jd|jd	|jd|jd|jd��q]|j
dj|jd|jd	|jd|jd��n|S(Nsshow snapshot sectionsis.*\[(?P<section>\S+)\].*s

tsectionsshow commandsshow command: itshow_commandsrow idsrow id: trow_idtkey1skey1: telement_key1tkey2skey2: telement_key2t-s*snapshot section add {0} "{1}" {2} {3} {4}s&snapshot section add {0} "{1}" {2} {3}(
R#RtsplitRRRRRRtKeyErrorRR%R'(
R
R(R)R
tsectionsRt
section_regexRR,Rtlinet
match_sectiontproposed((sN/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_snapshot.pyt
action_add�sR	

cCsadj|jd|jd�}|jdrJ|dj|jd�7}nt||�d}|S(Nsshow snapshot compare {0} {1}t	snapshot1t	snapshot2tcompare_options {0}i(R'R%R(R
R(R
R((sN/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_snapshot.pytaction_compare�s
cCsjt�}t}x.|D]&}|jd|dkrt}qqW|rf|jdj|jd��n|S(NR"Rssnapshot delete {0}(R#R$R%R&RR'(R
R(R)R*R((sN/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_snapshot.pyt
action_delete�s	

cCs#t�}|r|jd�n|S(Nssnapshot delete all(R#R(R
R(R)((sN/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_snapshot.pytaction_delete_alls	cOs)t�j|�}|r%|||�SdS(N(tglobalstget(Rtargstkwargstfunc((sN/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_snapshot.pytinvokescCs�|jd}|ddkr*|d7}ndj||�}y*t|d�}|j|�|j�Wn!tk
r�|jdd�nX|S(Ntpathi����t/s{0}{1}twtmsgsError while writing on file.(R%R'topentwritetcloset	Exceptiont	fail_json(tcontenttfilenameR
RHtfilepathtreport((sN/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_snapshot.pyt
write_on_files



c!Cs�tdtdtddddddg�d	td
d�dtd
d�d
td
d�dtd
d�dtddddg�dtd
d�dtd
d�dtd
d�dtd
d�dtd
d�dtd
d�dtd
ddt�dtd
ddd��}|jt�ddd
ddgfddd	dgfddddddgfddd	gfg}td|d|d t�}t�}t||�|jd}|jd}t	j
j|jd�s�|jd!d"j
|jd��ntd#|�}td$|||�}itd%6gd&6}|js�|dkr�g|d&<|jdr�|r�|jd
}	|jd}
|jd}d'j
|	|
�}|r�|d(j
|�7}nt||�d)}
|
r�t|
||�q�q�q�|r	t||�||d&<t|d%<n|dkr�|jdr�|jdr�d*j
|jd	�}t||�d)}
|
r�tt|
�|jd	|�q�q�n|j|�dS(+Ntactiontrequiredtchoicestcreatetaddtcomparetdeletet
delete_allR"ttypetstrRR<R=R>tsummaryt
ipv4routest
ipv6routestcomparison_results_fileR,R-R.R0R2tsave_snapshot_locallytbooltdefaultRHs./t
argument_spectrequired_iftsupports_check_modeRKs"{0} is not a valid directory name.R!s	action_%stchangedR)sshow snapshot compare {0} {1}s {0}isshow snapshot dump {0} | json(tdictR&R$tupdateRRR#R	R%tosRHtisdirRPR'RGt
check_modeRRURR_t	exit_json(RgRhR
twarningsRVRcR(taction_resultstresultR<R=R>R
RQ((sN/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_snapshot.pytmain'sp$
		


	






&&t__main__(tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNRmRtansible.module_utils.basicRt&ansible.module_utils.network.nxos.nxosRRRR	RR!R+R;R?R@RARGRURtt__name__(((sN/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_snapshot.pyt<module>s,


P#					4						I

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]