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_hsrp.pyc

�
�Udac@s	idd6dgd6dd6ZdZdZdZd	d
lmZmZd	dlmZmZd	dlm	Z	d	d
l
mZidd6dd6dd6dd6Z
d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zedkre�ndS( s1.1tmetadata_versiontpreviewtstatustnetworktsupported_bysu
---
module: nxos_hsrp
extends_documentation_fragment: nxos
version_added: "2.2"
short_description: Manages HSRP configuration on NX-OS switches.
description:
  - Manages HSRP configuration on NX-OS switches.
author:
  - Jason Edelman (@jedelman8)
  - Gabriele Gerbino (@GGabriele)
notes:
  - Tested against NXOSv 7.3.(0)D1(1) on VIRL
  - HSRP feature needs to be enabled first on the system.
  - SVIs must exist before using this module.
  - Interface must be a L3 port before using this module.
  - HSRP cannot be configured on loopback interfaces.
  - MD5 authentication is only possible with HSRPv2 while it is ignored if
    HSRPv1 is used instead, while it will not raise any error. Here we allow
    MD5 authentication only with HSRPv2 in order to enforce better practice.
options:
  group:
    description:
      - HSRP group number.
    required: true
  interface:
    description:
      - Full name of interface that is being managed for HSRP.
    required: true
  version:
    description:
      - HSRP version.
    default: 1
    choices: ['1','2']
  priority:
    description:
      - HSRP priority or keyword 'default'.
  preempt:
    description:
      - Enable/Disable preempt.
    choices: ['enabled', 'disabled']
  vip:
    description:
      - HSRP virtual IP address or keyword 'default'
  auth_string:
    description:
      - Authentication string. If this needs to be hidden(for md5 type), the string
        should be 7 followed by the key string. Otherwise, it can be 0 followed by
        key string or just key string (for backward compatibility). For text type,
        this should be just be a key string. if this is 'default', authentication
        is removed.
  auth_type:
    description:
      - Authentication type.
    choices: ['text','md5']
  state:
    description:
      - Specify desired state of the resource.
    choices: ['present','absent']
    default: 'present'
s�
- name: Ensure HSRP is configured with following params on a SVI
  nxos_hsrp:
    group: 10
    vip: 10.1.1.1
    priority: 150
    interface: vlan10
    preempt: enabled
    host: 68.170.147.165

- name: Ensure HSRP is configured with following params on a SVI
        with clear text authentication
  nxos_hsrp:
    group: 10
    vip: 10.1.1.1
    priority: 150
    interface: vlan10
    preempt: enabled
    host: 68.170.147.165
    auth_type: text
    auth_string: CISCO

- name: Ensure HSRP is configured with md5 authentication and clear
        authentication string
  nxos_hsrp:
    group: 10
    vip: 10.1.1.1
    priority: 150
    interface: vlan10
    preempt: enabled
    host: 68.170.147.165
    auth_type: md5
    auth_string: "0 1234"

- name: Ensure HSRP is configured with md5 authentication and hidden
        authentication string
  nxos_hsrp:
    group: 10
    vip: 10.1.1.1
    priority: 150
    interface: vlan10
    preempt: enabled
    host: 68.170.147.165
    auth_type: md5
    auth_string: "7 1234"

- name: Remove HSRP config for given interface, group, and VIP
  nxos_hsrp:
    group: 10
    interface: vlan10
    vip: 10.1.1.1
    host: 68.170.147.165
    state: absent
s�
commands:
    description: commands sent to the device
    returned: always
    type: list
    sample: ["interface vlan10", "hsrp version 2", "hsrp 30", "ip 10.30.1.1"]
i����(tload_configtrun_commands(tget_capabilitiestnxos_argument_spec(tget_interface_type(t
AnsibleModuletvipt100tpriorityttextt	auth_typetciscotauth_stringcCsei}xX|D]P}|j|�}|r
|j|�}|rPt|�||<q]|||<q
q
W|S(N(tgettstr(tkey_mapttabletnew_dicttkeytnew_keytvalue((sJ/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_hsrp.pyt
apply_key_map�s
cCs�dj|�}i}d}yt||g�d}Wntk
rIdSX|dkr�|dd}t|jdd	��}|d
ks�|dkr�d}q�n|d
kr�d	}n|S(Nsshow interface {0} | jsontunknownitethernettportchanneltTABLE_interfacet
ROW_interfaceteth_modetlayer3taccessttrunktlayer2tsvi(RR(tformatRt
IndexErrortNoneRR(t	interfacet	intf_typetmoduletcommandtmodetbodytinterface_table((sJ/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_hsrp.pytget_interface_mode�s
	c
Cs�dj|�}i}i	dd6dd6dd6dd	6d
d6dd
6dd6dd6dd6}yet||g�d}|dd}d|kr�|d=ndt|�kr�t|||�}nWnttttfk
r�iSXt|t	�r�|g}nx�|D]�}t
||�}	|	dj�|	d<|	ddkrHd|	d<n|	ddkred|	d<n|	ddkr�|	ddkr�d|	d<q�d|	d<n|	d|kr|	SqW|S( Nsshow hsrp group {0} all | jsonR)tsh_if_indextgrouptsh_group_numtversiontsh_group_versionR
tsh_cfg_priotpreemptt
sh_preemptRtsh_vipRtsh_authentication_typetauth_enctsh_keystring_attrRtsh_authentication_dataitTABLE_grp_detailtROW_grp_details
unknown enum:tv1t1tv2t2tmd5thiddent7t0(R&RRtget_hsrp_group_unknown_enumtAttributeErrorR't	TypeErrortKeyErrort
isinstancetdictRtlower(
R2R)R+R,thsrpthsrp_keyR.t
hsrp_tablet
hsrp_grouptparsed_hsrp((sJ/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_hsrp.pytget_hsrp_group�sJ






cCsgd|dkrcidd6|jd�dd6}t||�d}d|krVd	nd
|d<n|S(sWSome older NXOS images fail to set the attr values when using structured output and
    instead set the values to <unknown enum>. This fallback method is a workaround that
    uses an unstructured (text) request to query the device a second time.
    'sh_preempt' is currently the only attr affected. Add checks for other attrs as needed.
    s
unknown enum:R8Rtoutputt|iR,smay preempttenabledtdisabled(tsplitR(R+R,RQtcmdtout((sJ/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_hsrp.pyRH�s
!cCs"dj|�dj|�g}|S(Ns
interface {0}sno hsrp {0}(R&(R2R)tcommands((sJ/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_hsrp.pytget_commands_remove_hsrp�sc
Cs�g}idd6dd6dd6dd6}|jdd�}|jdd�}|jdd�}|jdd�}	|r�|d	kr�d|d<q�|d
kr�d|d<q�n|	r|	dkr�|r�|jd�tjd�kr�d
|d<q|d=qdj|d�|d<n|ry|dkr_|rU|jd�tjd�krUd|d<qv|d=qydj|d�|d<nxp|D]h}
|j|
d�j|�}|r�|dkr�|
dkr�|jd|�q�|j|�nd}q�W|jdd�}|jdd�}
|jdd�}|s.|
r�|sA|d}n|
sT|d}
n|
dkr�|dkr�dj||
�}|j|�q�|dkr�dj|
�}|j|�q�q�|r�|jd�tjd�kr�|jd�q�n|r |r |jddj|d��n|jdd�}|r�|dkrMd}n|dkrbd }n|jd|�|jdd!j|��n|r�|djd"�s�|jdd!j|��q�n|S(#Nshsrp {group}R2s
{priority}R
s	{preempt}R7s{vip}RRWRXs
no preempttdefaultsno priorityspriority {0}sno ipsip {0}tDNEiRRR;RDs%authentication md5 key-string {0} {1}Rsauthentication text {0}sno authenticationshsrp {0}R4RCshsrp version 2RAshsrp version 1s
interface {0}R)(RR(tPARAM_TO_DEFAULT_KEYMAPR&tinserttappendt
startswith(tdeltaR)targstexistingR\tconfig_argsR7R2RR
RR,RRR;R4((sJ/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_hsrp.pytget_commands_config_hsrp�s�

$

$





$
 		cCs�dj|�}y`t||gdt�d}d|j�krDdS|jd�}|djd�rjtStSWntk
r�dSXdS(	Nsshow run interface {0}tcheck_rcitinvalidR_s
i����R)(R&RtFalseRNRYRctTrueRK(R)R+R,R.traw_list((sJ/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_hsrp.pyt
is_defaultOs
cCs>dj|�}d|j�kr:|jddd|�ndS(Ntsinvalid ip addresstmsgs+Invalid VIP. Possible duplicate IP address.R(tjoinRNt	fail_json(R.RR+tnew_body((sJ/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_hsrp.pytvalidate_config`scCs�tdtdtdd�dtdt�dtddd	gd
ddt�dtdddt�dtdddd
dgdt�dtdddt�dtdddgdt�dtdddt�dtdddgdtd
d��	}|jt�td|dt�}t�}tdtd|�}|jdj�}|jd}|jd}|jd}|jd}|jd}	|jd}
|jd}|jd}d}
d}|rI|j
�}t|�dkr�|d}
|d}n/t|�dkr|d}n|jdd �|
dkrI|
d!krI|jdd"�qInt
|�}|jd#d$�}t|�}|d%kr�|d&kr�t||�d'kr�|jdd(d|�n|d)kr�|jdd*d|�q�nt|||�}|d+kr|jdd,d|�n|s$|rF|o-|sF|jdd-�qFntd|d|d|d|	d|
d|d|d.|
�}td/�|j�D��}t|||�}|jdd�dkr�|ddkrF|jdd0�qFn[|jdd�rF|rF|ddkrF|ddkrF|dkrF|jdd1�qFng}|dkr�tt|j��j|j���}|r�t||||�}|j|�q�n4|dkr�|r�t||�}|j|�q�n|r�|jr|j|�q�t||�|d&krW|dkrW|jdd2�t||�}t||
|�nt|d<d3|kr�|jd�q�n||d4<|j|�dS(5NR2trequiredttypeRR)R4tchoicesRARCR^R
R7RXRWRRRRDRtstatetabsenttpresentt
argument_spectsupports_check_modetchangedtwarningsRGiiiRpsInvalid auth_stringRFs(Invalid auth_string, only 0 or 7 allowedtnetwork_apitnxapiRtcliconfR_s3That interface does not exist yet. Create it first.tloopbacks'Loopback interfaces don't support HSRP.R$s>That interface is a layer2 port.
Make it a layer 3 port first.sDWhen using auth parameters, you need BOTH auth_type AND auth_string.R;css-|]#\}}|dk	r||fVqdS(N(R((t.0tktv((sJ/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_hsrp.pys	<genexpr>�ss2It's recommended to use HSRP v2 when auth_type=md5sIExisting auth_type is md5. It's recommended to use HSRP v2 when using md5sconfig tt	configureR\( RMRlRktupdateRR
tlisttparamsRNR(RYtlenRrRRR	RnR0titemsRTtsett
differenceRhtextendR]t
check_modet	exit_jsonRRaRRttpop(R{R+R~tresultsR)R2R4RxR
R7RRtauth_full_stringR;Rtkstrtdevice_infoRR*R-RetproposedRfR\RdR,R.((sJ/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_hsrp.pytmaings�!!$
	













$	


t__main__N(tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNt&ansible.module_utils.network.nxos.nxosRRRRR	tansible.module_utils.basicR
R(R`RR0RTRHR]RhRnRtR�t__name__(((sJ/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_hsrp.pyt<module>s2


>7
	
		3	
		V			w

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