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_l2_interface.pyo

�
�Udac@`saddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	ddl
Z
ddlmZdd
l
mZmZmZddl
mZmZddlmZddlmZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#d�Z$d�Z%e&d kr]e%�ndS(!i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiont
deprecatedtstatustnetworktsupported_bys�
---
module: nxos_l2_interface
extends_documentation_fragment: nxos
version_added: "2.5"
short_description: Manage Layer-2 interface on Cisco NXOS devices.
description:
  - This module provides declarative management of Layer-2 interface on
    Cisco NXOS devices.
deprecated:
  removed_in: '2.13'
  alternative: nxos_l2_interfaces
  why: Updated modules released with more functionality
author:
  - Trishna Guha (@trishnaguha)
notes:
  - Tested against NXOSv 7.0(3)I5(1).
options:
  name:
    description:
      - Full name of the interface excluding any logical
        unit number, i.e. Ethernet1/1.
    required: true
    aliases: ['interface']
  mode:
    description:
      - Mode in which interface needs to be configured.
    choices: ['access','trunk']
  access_vlan:
    description:
      - Configure given VLAN in access port.
        If C(mode=access), used as the access VLAN ID.
  native_vlan:
    description:
      - Native VLAN to be configured in trunk port.
        If C(mode=trunk), used as the trunk native VLAN ID.
  trunk_vlans:
    description:
      - List of VLANs to be configured in trunk port.
        If C(mode=trunk), used as the VLAN range to ADD or REMOVE
        from the trunk.
    aliases: ['trunk_add_vlans']
  trunk_allowed_vlans:
    description:
      - List of allowed VLANs in a given trunk port.
        If C(mode=trunk), these are the only VLANs that will be
        configured on the trunk, i.e. "2-10,15".
  aggregate:
    description:
      - List of Layer-2 interface definitions.
  state:
    description:
      - Manage the state of the Layer-2 Interface configuration.
    default:  present
    choices: ['present','absent', 'unconfigured']
s	
- name: Ensure Eth1/5 is in its default l2 interface state
  nxos_l2_interface:
    name: Ethernet1/5
    state: unconfigured

- name: Ensure Eth1/5 is configured for access vlan 20
  nxos_l2_interface:
    name: Ethernet1/5
    mode: access
    access_vlan: 20

- name: Ensure Eth1/5 only has vlans 5-10 as trunk vlans
  nxos_l2_interface:
    name: Ethernet1/5
    mode: trunk
    native_vlan: 10
    trunk_vlans: 5-10

- name: Ensure eth1/5 is a trunk port and ensure 2-50 are being tagged (doesn't mean others aren't also being tagged)
  nxos_l2_interface:
    name: Ethernet1/5
    mode: trunk
    native_vlan: 10
    trunk_vlans: 2-50

- name: Ensure these VLANs are not being tagged on the trunk
  nxos_l2_interface:
    name: Ethernet1/5
    mode: trunk
    trunk_vlans: 51-4094
    state: absent

-  name: Aggregate Configure interfaces for access_vlan with aggregate
   nxos_l2_interface:
     aggregate:
       - { name: "Ethernet1/2", access_vlan: 6 }
       - { name: "Ethernet1/7", access_vlan: 15 }
     mode: access
s
commands:
  description: The list of configuration mode commands to send to the device
  returned: always, except for the platforms that use Netconf transport to manage the device.
  type: list
  sample:
    - interface eth1/5
    - switchport access vlan 20
N(tdeepcopy(t
get_configtload_configtrun_commands(tnxos_argument_spectget_interface_type(t
AnsibleModule(tremove_default_speccC`s�dj|�}t|�}d}i}y(t||g�d}|dd}Wntttfk
rl|SX|r�|dkr�t|jdd	��}|dkr�d}n|d
kr�d	}q�q�|dks�|dkr�d	}q�n|S(sfGets current mode of interface: layer2 or layer3
    Args:
        device (Device): This is the device object of an NX-API enabled device
            using the Device class within device.py
        interface (string): full name of interface, i.e. Ethernet1/1,
            loopback10, port-channel20, vlan20
    Returns:
        str: 'layer2' or 'layer3'
    sshow interface {0} | jsontunknownitTABLE_interfacet
ROW_interfacetethernettportchannelteth_modetlayer3taccessttrunktlayer2troutedtloopbacktsvi(RR(saccessR(tformatR
RtKeyErrortAttributeErrort
IndexErrortstrtget(tnametmoduletcommandt	intf_typetmodetinterface_tabletbody((sS/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_l2_interface.pytget_interface_mode�s&
	cC`s�t|�}|dkr�dj|�}y(t||g�d}|dd}Wn tttfk
rqd}nX|r�|jd�}|r�tSt	Sq�nt	S(s�Checks to see if an interface is part of portchannel bundle
    Args:
        interface (str): full name of interface, i.e. Ethernet1/1
    Returns:
        True/False based on if interface is a member of a portchannel bundle
    Rsshow interface {0} | jsoniRRt
eth_bundleN(
R
RRRRR tNoneR"tTruetFalse(R#R$R&R%R)R(tstate((sS/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_l2_interface.pytinterface_is_portchannel�s

cC`s�dj|�}y(t||g�d}|dd}Wn tttfk
rYd}nX|r�idd6dd6d	d	6d
d
6dd6dd6d
d
6dd6}t||�}|SiSdS(s5Gets current config of L2 switchport
    Args:
        device (Device): This is the device object of an NX-API enabled device
            using the Device class within device.py
        port (str): full name of interface, i.e. Ethernet1/1
    Returns:
        dictionary with k/v pairs for L2 vlan config
    s$show interface {0} switchport | jsoniRRR#t	interfaceR't	oper_modet
switchporttaccess_vlantaccess_vlan_nametnative_vlantnative_vlan_namettrunk_vlansN(RRRRR R,t
apply_key_map(tportR$R%R)tsp_tabletkey_maptsp((sS/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_l2_interface.pytget_switchport�s&


cC`sz|jd�}g}d}|dkrv|jd�|jd�k}|rYdj|jd��}|j|�qYn�|dkrY|jd�}|jd�}	t|	�j|�}
|
r�|jd�}|jd|�}d	j|�}|j|�n|jd
�|jd
�k}
|
rY|jd
�rYdj|jd
��}|j|�qYn|rv|jdd
|�n|S(NR'RR4sno switchport access vlan {0}Rttrunk_vlans_listttrunk_allowed_vlansR8s(switchport trunk allowed vlan remove {0}R6s#no switchport trunk native vlan {0}is
interface (R"R,Rtappendtsettintersectiontinsert(R#texistingtproposedR$R'tcommandsR%tav_checktexisting_vlanstproposed_vlanstvlans_to_removetproposed_allowed_vlanstremove_trunk_allowed_vlanstnative_check((sS/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_l2_interface.pyt!remove_switchport_config_commands�s0cC`s7|jd�}|jd�}g}d}||krc|dkrKd}qc|dkrcd}qcn|ry|j|�n|dkr�t|jd��t|jd��k}|sdj|jd��}|j|�qn6|dkr|jd�|jd�k}	|	s�|jd	�rGd
j|jd��}|j|�q�|jd�}
|jd�}t|�j|
�}|r�dj|jd
��}|j|�q�nt|jd��t|jd��k}
|
r|jd�rdj|jd��}|j|�qn|r3|jdd|�n|S(sBGets commands required to config a given switchport interface
    R'Rsswitchport mode trunkRsswitchport mode accessR4sswitchport access vlan {0}R?talloweds!switchport trunk allowed vlan {0}R@s%switchport trunk allowed vlan add {0}R8R6s switchport trunk native vlan {0}is
interface N(R"R,RAR!RRBt
differenceRD(R#RERFR$t
proposed_modet
existing_modeRGR%RHttv_checkRIRJtvlans_to_addRN((sS/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_l2_interface.pytget_switchport_config_commandssF	**cC`sht|d�dk}t|d�dk}|ddk}|ddk}|oa|oa|oa|}|S(sDetermines if switchport has a default config based on mode
    Args:
        existing (dict): existing switchport configuration from Ansible mod
    Returns:
        boolean: True if switchport has OOB Layer 2 config, i.e.
           vlan 1 and trunk all and mode is access
    R4t1R6R8s1-4094R'R(R!(REtc1tc2tc3tc4tdefault((sS/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_l2_interface.pytis_switchport_default7s	cC`sOg}|jd|�|jd�|jd�|jd�|jd�|S(Ns
interface sswitchport mode accesssswitch access vlan 1sswitchport trunk native vlan 1s!switchport trunk allowed vlan all(RA(R#RG((sS/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_l2_interface.pytdefault_switchport_configJs



cC`s�g}|r�x�|jd�D]�}|dkr2Pnd|kr�|jd�\}}t|�t|�}}|jt||d��qt|�}|j|�qWt|�S|S(Nt,tnonet-i(tsplittinttextendtrangeRAtnumerical_sort(tvlanstresulttparttatb((sS/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_l2_interface.pytvlan_range_to_listTs
cC`s�d}g}y(t||g�d}|dd}Wntttfk
rQgSXt|t�r�x5|D]}|jt|d��qhWn
|jd�|S(Nsshow vlan | jsonitTABLE_vlanbrieft
ROW_vlanbriefsvlanshowbr-vlanid-utfRW(RRRR t
isinstancetlistRAR!(R$R%t	vlan_listR)t
vlan_tabletvlan((sS/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_l2_interface.pytget_list_of_vlanses

cC`sbg}g}x!|D]}|jt|��qW|j�x!|D]}|jt|��qAW|S(sGSorts list of strings/integers that are digits in numerical order.
    (RARctsortR!(tstring_int_listtas_int_listtas_str_listRs((sS/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_l2_interface.pyRfys


cC`sOi}xB|j�D]4\}}|j|�}|rt|�||<qqW|S(N(titemsR"R!(R<ttabletnew_dicttkeytvaluetnew_key((sS/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_l2_interface.pyR9�scC`s8x1|j�D]#\}}||j|�||<q
W|S(N(RyR"(t	value_maptresourceR|R}((sS/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_l2_interface.pytapply_value_map�scC`sGg}x:|D]2}t|t�r2|j|�q
|j|�q
W|S(N(RoRpRdRA(t
command_liststflat_command_listR%((sS/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_l2_interface.pytflatten_list�s
cC`s�g}|jjd�}|r�x�|D]Y}x7|D]/}|j|�dkr2|j|||<q2q2W|j�}|j|�q%Wno|ji|jdd6|jdd6|jdd6|jdd6|jdd6|jdd6|jdd6�|S(	Nt	aggregateR#R'R4R6R8R@R/(tparamsR"R,tcopyRA(R$tobjR�titemR|td((sS/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_l2_interface.pytmap_params_to_obj�s$

	cC`stdtddddg�dtddd	g�d
tdd�dtdd�dtdddd
g�dtdd�dtddddgdd��}t|�}t|�tdtddddd|��}|j|�|jt�td|dd
dgd
dgd
dggdt�}t�}g}itd6}|rR||d<nt	|�}x|D]
}|d}	|d}
|d
}|d}|d}
|d}|d}td|	d|
d
|d|d|
d|�}td�|j
�D��}|	j�}	|
dkr8|dkr8|r8|jdd �n|
d	kr]|r]|jdd!�nt
|	|�}|d"ks�|d#kr�|jdd$�nt|	|�r�|jdd%�nt|	|�}|s�|jdd&�n|
s�|rH|
rt|
�}n|r!t|�}t|d'<nt|d�}||d(<||d(<nt|�}|dkr�|r�||kr�|jdd)d*|�qI|r�||kr�|jdd)d*|�qIt|	|||�}|j|�nn|dkrt|�}|sIt|	�}|j|�qIn1|dkrIt|	|||�}|j|�n|
sU|re|jd(�|jd(�qeqeWt|�}|r�|jr�|jdtd+|�q�t|d<t||�d,|kr�|jd-�q�n||d+<||d<|j|�d.S(/s+ main entry point for module execution
    R#ttypeR!taliasesR1R'tchoicesRRR4R6R8ttrunk_add_vlansR@R/tabsenttpresenttunconfiguredR\R�Rptelementstdicttoptionst
argument_spectmutually_exclusivetsupports_check_modetchangedtwarningscs`s-|]#\}}|dk	r||fVqdS(N(R,(t.0tktv((sS/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_l2_interface.pys	<genexpr>�stmsgs?access_vlan param is required when mode=access && state=presents5access_vlan param not supported when using mode=trunkRRs~Ensure interface is configured to be a L2
port first before using this module. You can use
the nxos_interface module for this.stCannot change L2 config on physical 
port because it is in a portchannel. 
You should update the portchannel config.s/Make sure you are using the FULL interface nameRPR?sZYou are trying to configure a VLAN on an interface that
does not exist on the  switch yet!RsRGt	configureiN(R�RRtupdateRRR-RpR.R�Rytlowert	fail_jsonR*R0R>RlRtRVRAR]R^ROtpopR�t
check_modet	exit_jsonR
(telement_spectaggregate_specR�R$R�RGRhtwanttwR#R'R4R/R8R6R@targsRFtcurrent_modeRER?texisting_trunks_listt
current_vlansR%t
is_defaulttcmds((sS/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_l2_interface.pytmain�s�!


				









	





	



t__main__('t
__future__RRRR�t
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNtreR�Rt&ansible.module_utils.network.nxos.nxosR	R
RRR
tansible.module_utils.basicRt)ansible.module_utils.network.common.utilsRR*R0R>RORVR]R^RlRtRfR9R�R�R�R�t__name__(((sS/usr/lib/python2.7/site-packages/ansible/modules/network/nxos/_nxos_l2_interface.pyt<module>s<


9)
	"		$	 	2		
							
		�

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