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

�
�Udac@`skddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	ddl
Z
ddlZddlm
Z
dd
lmZmZddlmZmZddlmZddlmZddlmZmZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#d�Z$d�Z%e&dkrge%�ndS( i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiont
deprecatedtstatustnetworktsupported_bys,
---
module: nxos_interface
extends_documentation_fragment: nxos
version_added: "2.1"
short_description: Manages physical attributes of interfaces.
description:
  - Manages physical attributes of interfaces of NX-OS switches.
deprecated:
  removed_in: '2.13'
  alternative: nxos_interfaces
  why: Updated modules released with more functionality
author:
  - Jason Edelman (@jedelman8)
  - Trishna Guha (@trishnaguha)
notes:
  - Tested against NXOSv 7.3.(0)D1(1) on VIRL
  - This module is also used to create logical interfaces such as
    svis and loopbacks.
  - Be cautious of platform specific idiosyncrasies. For example,
    when you default a loopback interface, the admin state toggles
    on certain versions of NX-OS.
  - The M(nxos_overlay_global) C(anycast_gateway_mac) attribute must be
    set before setting the C(fabric_forwarding_anycast_gateway) property.
options:
  name:
    description:
      - Full name of interface, i.e. Ethernet1/1, port-channel10.
    required: true
    aliases: [interface]
  interface_type:
    description:
      - Interface type to be unconfigured from the device.
    choices: ['loopback', 'portchannel', 'svi', 'nve']
    version_added: 2.2
  speed:
    description:
      - Interface link speed. Applicable for ethernet interface only.
    version_added: 2.5
  admin_state:
    description:
      - Administrative state of the interface.
    default: up
    choices: ['up','down']
  description:
    description:
      - Interface description.
  mode:
    description:
      - Manage Layer 2 or Layer 3 state of the interface.
        This option is supported for ethernet and portchannel interface.
        Applicable for ethernet and portchannel interface only.
    choices: ['layer2','layer3']
  mtu:
    description:
      - MTU for a specific interface. Must be an even number between 576 and 9216.
        Applicable for ethernet interface only.
    version_added: 2.5
  ip_forward:
    description:
      - Enable/Disable ip forward feature on SVIs.
    choices: ['enable','disable']
    version_added: 2.2
  fabric_forwarding_anycast_gateway:
    description:
      - Associate SVI with anycast gateway under VLAN configuration mode.
        Applicable for SVI interface only.
    type: bool
    version_added: 2.2
  duplex:
    description:
      - Interface link status. Applicable for ethernet interface only.
    default: auto
    choices: ['full', 'half', 'auto']
    version_added: 2.5
  tx_rate:
    description:
      - Transmit rate in bits per second (bps).
      - This is state check parameter only.
      - Supports conditionals, see L(Conditionals in Networking Modules,../network/user_guide/network_working_with_command_output.html)
    version_added: 2.5
  rx_rate:
    description:
      - Receiver rate in bits per second (bps).
      - This is state check parameter only.
      - Supports conditionals, see L(Conditionals in Networking Modules,../network/user_guide/network_working_with_command_output.html)
    version_added: 2.5
  neighbors:
    description:
      - Check the operational state of given interface C(name) for LLDP neighbor.
      - The following suboptions are available. This is state check parameter only.
    suboptions:
        host:
          description:
            - "LLDP neighbor host for given interface C(name)."
        port:
          description:
            - "LLDP neighbor port to which given interface C(name) is connected."
    version_added: 2.5
  aggregate:
    description: List of Interfaces definitions.
    version_added: 2.5
  state:
    description:
      - Specify desired state of the resource.
    default: present
    choices: ['present','absent','default']
  delay:
    description:
      - Time in seconds to wait before checking for the operational state on remote
        device. This wait is applicable for operational state arguments.
    default: 10
s�
- name: Ensure an interface is a Layer 3 port and that it has the proper description
  nxos_interface:
    name: Ethernet1/1
    description: 'Configured by Ansible'
    mode: layer3

- name: Admin down an interface
  nxos_interface:
    name: Ethernet2/1
    admin_state: down

- name: Remove all loopback interfaces
  nxos_interface:
    name: loopback
    state: absent

- name: Remove all logical interfaces
  nxos_interface:
    interface_type: "{{ item }} "
    state: absent
  loop:
    - loopback
    - portchannel
    - svi
    - nve

- name: Admin up all loopback interfaces
  nxos_interface:
    name: loopback 0-1023
    admin_state: up

- name: Admin down all loopback interfaces
  nxos_interface:
    name: loopback 0-1023
    admin_state: down

- name: Check neighbors intent arguments
  nxos_interface:
    name: Ethernet2/3
    neighbors:
    - port: Ethernet2/3
      host: abc.mycompany.com

- name: Add interface using aggregate
  nxos_interface:
    aggregate:
    - { name: Ethernet0/1, mtu: 256, description: test-interface-1 }
    - { name: Ethernet0/2, mtu: 516, description: test-interface-2 }
    duplex: full
    speed: 100
    state: present

- name: Delete interface using aggregate
  nxos_interface:
    aggregate:
    - name: Loopback9
    - name: Loopback10
    state: absent

- name: Check intent arguments
  nxos_interface:
    name: Ethernet0/2
    state: up
    tx_rate: ge(0)
    rx_rate: le(0)
s�
commands:
    description: command list sent to the device
    returned: always
    type: list
    sample:
      - interface Ethernet2/3
      - mtu 1500
      - speed 10
N(tdeepcopy(tload_configtrun_commands(tnxos_argument_spectnormalize_interface(tget_interface_type(t
AnsibleModule(tconditionaltremove_default_speccC`sid|krd}nd}i|d6|d6g}t||dt�}|rad|dkragS|SdS(	Nsshow runtjsonttexttcommandtoutputtcheck_rctInvalidi(R
tFalse(RtmoduleRtcmdstbody((sP/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_interface.pytexecute_show_command�s	
cC`s)x"|D]}|d|kr|SqWdS(Ntname(tNone(Rtlstto((sP/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_interface.pytsearch_obj_in_list�s
cC`s�ytd|�d}Wntk
r+iSXigd6gd6gd6gd6gd6gd6gd	6}|r�|d
d}x8|D]-}|d}t|�}||j|�q~Wn|S(
s1Gets all active interfaces on a given switch
    sshow interfaceitethernettsvitloopbackt
managementtportchanneltnvetunknowntTABLE_interfacet
ROW_interfacet	interface(Rt
IndexErrorR
tappend(RRt
interfacestinterface_listtindextintft	intf_type((sP/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_interface.pytget_interfaces_dict�s&



c	C`s�dj|�}yt||�d}Wnttfk
r@d
SX|r�|jd�}d
}d}xQ|D]I}d|kr�|j�jd�dj�}qid|krid}qiqiWtd|d	|�Sd
Sd
S(sn Returns dictionary that has two k/v pairs:
        admin_state & description if not an svi, returns None
    sshow run interface {0} allis
tdowntdescriptionisno shutdowntuptadmin_stateN(tformatRR+t	TypeErrorRtsplittlstriptdict(	RR1RRRtcommand_listtdescR6teach((sP/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_interface.pytget_vlan_interface_attributess 
"
cC`s@g}x3|D]+}|dkr
|jdj|��q
q
W|S(NtVlan1sno interface {0}(R,R7(R-tcommandsR*((sP/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_interface.pytget_interface_type_removed_cmds%s

cC`s4d}|dkrd}n|dkr0d}n|S(NtR5sno shutdownR3tshutdown((R6R((sP/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_interface.pytget_admin_state/s		cC`s�dj|�}yt||�d}Wnttfk
rG}d}nX|r�|jd�}t}xF|D]>}|jd�r�t}n|rj|rj|jd�rjtSqjWtSdSdS(sDChecks to see if interface exists and if it is a default config
    sshow run interface {0}iRCs
R*tDNEN(R7RR+R8R9Rt
startswithtTrue(RRRRtetraw_listtfoundtline((sP/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_interface.pytis_default_interface8s

	cC`s-||kr|j|�n|j|�dS(N(R,(R*tcmdRA((sP/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_interface.pytadd_command_to_interfacePscC`s�t�}t�}|\}}d(}x�|D]�}|d}|d}	|d}
|d}|d	}|d
}
|d}|d
=|r�d|d<n|r�i}|
d)kr�|jdd�q�nt||�}t||�}|r�d|}n|
dkrW|r|jdj|��q�|r�|r�t|�|}t|�}|j	|�q�q+|
dkre|rt
|�d*kr�|	dkr�|	|jd�kr�t|d|�q�|	dkr�|	|jd�kr�t|d|�q�n|dkr||jd	�krt|d|�n4|dkrN||jd	�krNt|d|�n|
dkr�|
|jd�kr�t|d|�n4|
dkr�|
|jd�kr�t|d |�n|t
kr�|jd�tkr�t|d!|�n4|tkr|jd�t
krt|d"|�nx_|D]W}|j|�}|r%||j|�kr%|d#t|�}t|||�q%q%W|rbt
|�dkrb|	|jd�kr|jd	�p�|jd	�}|rd$jt|d��}t|�}|j|�|j|�qqqbq�|j|�t
|�d+krv|	dkrW|jd�qv|	dkrv|jd�qvn|dkr�|jd�n|dkr�|jd�n|
dkr�|jd�n|
dkr�|jd �n|t
kr|jd!�n|tkr|jd"�nx�|D]9}|j|�}|r%|j|d#t|��q%q%Wq+|
d
kr+|tkr�|jd%j|��q�|d&kr�|jdd'�q�q+q+W||fS(,NtspeedR4tduplextmtuRtmodet
ip_forwardt!fabric_forwarding_anycast_gatewayR6tstatetinterface_typetpresenttdefaulttmsgs<The interface_type param can be used only with state absent.s
interface tabsentsno interface {0}R!R%tlayer2t
switchporttlayer3s
no switchportR5sno shutdownR3RDtenables
ip forwardtdisables
no ip forwards&fabric forwarding mode anycast-gateways)no fabric forwarding mode anycast-gatewayt s
interface {0}sdefault interface {0}RFs2interface you are trying to default does not exist(sspeedsdescriptionsduplexsmtu(RXsdefault(sethernetsportchannel(sethernetsportchannel(tlistRt	fail_jsonR RMR,R7R2RBtextendR
tgetRORHRtstrRREt	exit_json(tupdatesRRAt	commands2twantthavetargstwRRSRTRUR6RVRWtobj_in_havet
is_defaultR*tintfsRtitemt	candidateRNtc1tc2((sP/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_interface.pytmap_obj_to_commandsVs�		










!!!!!!



%cC`szg}|jjd�}|r�xU|D]s}x7|D]/}|j|�dkr2|j|||<q2q2W|j�}|d}t|�|d<|j|�q%Wn�|jit|jd�d6|jdd6|jdd6|jdd6|jdd6|jdd6|jdd6|jd	d	6|jd
d
6|jdd6|jdd6|jd
d
6|jdd6|jdd6�|S(Nt	aggregateRR4RPRSRRRQRTRUR6RVRWttx_ratetrx_ratet	neighbors(tparamsReRtcopyRR,(RtobjRvRqtkeytdR((sP/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_interface.pytmap_params_to_obj�s6


	cC`st�}x�|D]�}tddddddddddddddddd	dd
d�
}|dsi|Sdj|d�}yt||�d}Wntk
r�t�SX|r�y|d
d}Wnttfk
r�t�SX|r�|jd�dkr|j	dd�nt
|d�}|d5kry|jd�}	|	d6krSd|d<qy|	d7krld|d<qyd|d<n|dkr�t|jd��|d<|jd�|d<|jd�|d<|jd�|d<|jd�|d<|jd�}
d j|d�}t||�d}tj
d!|�}|dkrJd"|d<n|jd#�|d<tj
d$|�}|dkr�d"|d<n|jd#�|d<d%|kr�d&|d	<q�d'|d	<n�|d(kr�t|jd��|d<t|d||�}
t|
jdd)��|d<t|
jdd*��|d<|jd+�|d<d j|d�}t||�d}d%|kr�d&|d	<n
d'|d	<d,|kr�t|d
<q�t|d
<n�|d8kr6t|jd��|d<|jd�|d<|ddkr |d-kr |jd0�|d<n|jd�|d<na|dkr�t|jd��|d<|jd�|d<|jd�|d<|jd�|d<n|ddkr�|jd1�}|d2kr�d3|d<q�|dk	r�d4|d<q�q�q�n|j|�qW|S(9NRR4R6RPRRRSRQRWRTRUsshow interface {0}iR(R)teth_modes
fex-fabricRZsAnxos_interface does not support interfaces with mode "fex-fabric"R%R!taccessttrunksdot1q-tunnelR\troutedR^R*R=teth_mtut
eth_duplext	eth_speedsshow run interface {0}sspeed (\d+)tautoisduplex (\S+)s
ip forwardR_R`R"tnxapibugt	nxapi_bugtsvi_mtus&fabric forwarding mode anycast-gatewayR#R$R&RVtstate_rsn_descsAdministratively downR3R5(sportchannelsethernet(saccessR�sdot1q-tunnel(R�slayer3(sloopbacks
managementsnve(RbR;RR7RR+tKeyErrorR8ReRcR
RtretsearchtgroupR?RfRHRR,(RjRtobjsRmR|RRtinterface_tableR1RSRPtspeed_matchtduplex_matcht
attributeststate_description((sP/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_interface.pytmap_config_to_obj�s�	














cC`sbg}d}xO|D]G}|dr)qn|jd�}|jd�}|jd�}|pe|pe|snqntj|jd�idj|d�d6d	d
6g}yt||dt�d}	Wn tt	t
fk
r�d
}	nX|ratjd|	tj
�}
d}|
r"|
jd�}n|dksJt||j�dt�ra|jd|�qan|r�tjd|	tj
�}
d}|
r�|
jd�}n|dks�t||j�dt�r�|jd|�q�n|rg}
g}|dkr�idj|d�d6d	d
6g}t||dt�}|rF|d}nd
}|r�d|kr�xx|j�jd�D]^}|jd�r�|j|jd�d�n|jd�rt|
j|jd�d�qtqtWq�nx{|D]p}|jd�}|jd�}|r-||
kr-|jd|�n|r�||kr�|jd|�q�q�WqqW|S(NRWRwRxRytdelaysshow interface {0}RRRRRiRCsoutput rate (\d+)itcaststx_rate sinput rate (\d+)srx_rate s(show lldp neighbors interface {0} detailsTotal entries displayed: 0s
sPort Descriptions: sSystem Namethosttportshost sport (RRettimetsleepRzR7R
RtAttributeErrorR+R8R�R�tMR�RtstriptintR,R9RG(RRjtfailed_conditionsthave_neighborsRmtwant_tx_ratetwant_rx_ratetwant_neighborsRNtouttmatchthave_tx_ratethave_rx_ratet	have_hostt	have_portRRLRqR�R�((sP/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_interface.pytcheck_declarative_intent_paramscsj

$
(($
'
c#C`s;tdt�dt��}tdtddg�dtddd	dd
g�dt�dt�d
td	ddg�dt�dtd	dddg�dtd	ddddg�dtd	ddg�dtdd�d t�d!t�d"tdd#d$d%d&|�d'tdd(dd)�d*td	d+d,dgdd,��}t|�}td-t�|d<t|�td.tdd#d$d%d&|d/ddgg��}|j|�|jt�dd.dgg}dd.gddgg}td0|d1|d/|d2t�}t�}itd36}|r"||d4<nt	|�}	t
|	|�}
g}t|	|
f|�\}}
|j|�|r�|j
s�t||�t|d3<|
r�t||
�|j|
�ng|D]}|d5kr�|^q�}q�n||d6<|d3r*t||	�}|r*d7}|jd8|d9|�q*n|j|�d:S(;s+ main entry point for module execution
    R�R�RtaliasesR*R6RYR5tchoicesR3R4RPRSR\R^RRRQtfullthalfR�RWR#R%R"R&RTR_R`RUttypetboolRwRxRyRbtelementsR;toptionsR�i
R�RVR[RXtrequiredRvtmutually_exclusivet
argument_spectrequired_one_oftsupports_check_modetchangedtwarningst	configureRAs:One or more conditional statements have not been satisfiedRZR�N(R;RRHRtupdateRRRbRRR�RuRdt
check_modeR	R�RcRg(tneighbors_spectelement_spectaggregate_specR�R�R�RR�tresultRjRkRAt	commands1RiRNR�RZ((sP/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_interface.pytmain�st						!


			


	


+

t__main__('t
__future__RRRR�t
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNR�R�R{Rt&ansible.module_utils.network.nxos.nxosR	R
RRR
tansible.module_utils.basicRt)ansible.module_utils.network.common.utilsRRRR R2R?RBRERMRORuRR�R�R�t__name__(((sP/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_interface.pyt<module>s<


rD					
					v	#	t	E	T

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