Skip to content

Commit

Permalink
fix nxos_vrf and migrate get_interface_type to module_utils (ansible#…
Browse files Browse the repository at this point in the history
…40825)

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
  • Loading branch information
trishnaguha authored and gothicx committed May 29, 2018
1 parent 72076db commit 4bb99bd
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 180 deletions.
21 changes: 21 additions & 0 deletions lib/ansible/module_utils/network/nxos/nxos.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,24 @@ def _get_number(name):
proper_interface = name

return proper_interface


def get_interface_type(interface):
"""Gets the type of interface
"""
if interface.upper().startswith('ET'):
return 'ethernet'
elif interface.upper().startswith('VL'):
return 'svi'
elif interface.upper().startswith('LO'):
return 'loopback'
elif interface.upper().startswith('MG'):
return 'management'
elif interface.upper().startswith('MA'):
return 'management'
elif interface.upper().startswith('PO'):
return 'portchannel'
elif interface.upper().startswith('NV'):
return 'nve'
else:
return 'unknown'
18 changes: 1 addition & 17 deletions lib/ansible/modules/network/nxos/_nxos_ip_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@

from ansible.module_utils.network.nxos.nxos import load_config, run_commands
from ansible.module_utils.network.nxos.nxos import get_capabilities, nxos_argument_spec
from ansible.module_utils.network.nxos.nxos import get_interface_type
from ansible.module_utils.basic import AnsibleModule


Expand Down Expand Up @@ -209,23 +210,6 @@ def execute_show_command(command, module):
return body


def get_interface_type(interface):
if interface.upper().startswith('ET'):
return 'ethernet'
elif interface.upper().startswith('VL'):
return 'svi'
elif interface.upper().startswith('LO'):
return 'loopback'
elif interface.upper().startswith('MG'):
return 'management'
elif interface.upper().startswith('MA'):
return 'management'
elif interface.upper().startswith('PO'):
return 'portchannel'
else:
return 'unknown'


def is_default(interface, module):
command = 'show run interface {0}'.format(interface)

Expand Down
26 changes: 1 addition & 25 deletions lib/ansible/modules/network/nxos/_nxos_switchport.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,34 +119,10 @@

from ansible.module_utils.network.nxos.nxos import load_config, run_commands
from ansible.module_utils.network.nxos.nxos import get_capabilities, nxos_argument_spec
from ansible.module_utils.network.nxos.nxos import get_interface_type
from ansible.module_utils.basic import AnsibleModule


def get_interface_type(interface):
"""Gets the type of interface
Args:
interface (str): full name of interface, i.e. Ethernet1/1, loopback10,
port-channel20, vlan20
Returns:
type of interface: ethernet, svi, loopback, management, portchannel,
or unknown
"""
if interface.upper().startswith('ET'):
return 'ethernet'
elif interface.upper().startswith('VL'):
return 'svi'
elif interface.upper().startswith('LO'):
return 'loopback'
elif interface.upper().startswith('MG'):
return 'management'
elif interface.upper().startswith('MA'):
return 'management'
elif interface.upper().startswith('PO'):
return 'portchannel'
else:
return 'unknown'


def get_interface_mode(interface, module):
"""Gets current mode of interface: layer2 or layer3
Args:
Expand Down
18 changes: 1 addition & 17 deletions lib/ansible/modules/network/nxos/nxos_hsrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@

from ansible.module_utils.network.nxos.nxos import load_config, run_commands
from ansible.module_utils.network.nxos.nxos import get_capabilities, nxos_argument_spec
from ansible.module_utils.network.nxos.nxos import get_interface_type
from ansible.module_utils.basic import AnsibleModule


Expand Down Expand Up @@ -187,23 +188,6 @@ def apply_key_map(key_map, table):
return new_dict


def get_interface_type(interface):
if interface.upper().startswith('ET'):
return 'ethernet'
elif interface.upper().startswith('VL'):
return 'svi'
elif interface.upper().startswith('LO'):
return 'loopback'
elif interface.upper().startswith('MG'):
return 'management'
elif interface.upper().startswith('MA'):
return 'management'
elif interface.upper().startswith('PO'):
return 'portchannel'
else:
return 'unknown'


def get_interface_mode(interface, intf_type, module):
command = 'show interface {0}'.format(interface)
interface = {}
Expand Down
18 changes: 1 addition & 17 deletions lib/ansible/modules/network/nxos/nxos_igmp_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@

from ansible.module_utils.network.nxos.nxos import get_config, load_config, run_commands
from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, check_args
from ansible.module_utils.network.nxos.nxos import get_interface_type
from ansible.module_utils.basic import AnsibleModule

import re
Expand Down Expand Up @@ -227,23 +228,6 @@ def get_interface_mode(interface, intf_type, module):
return mode


def get_interface_type(interface):
if interface.upper().startswith('ET'):
return 'ethernet'
elif interface.upper().startswith('VL'):
return 'svi'
elif interface.upper().startswith('LO'):
return 'loopback'
elif interface.upper().startswith('MG'):
return 'management'
elif interface.upper().startswith('MA'):
return 'management'
elif interface.upper().startswith('PO'):
return 'portchannel'
else:
return 'unknown'


def apply_key_map(key_map, table):
new_dict = {}
for key, value in table.items():
Expand Down
22 changes: 1 addition & 21 deletions lib/ansible/modules/network/nxos/nxos_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@

from ansible.module_utils.network.nxos.nxos import load_config, run_commands
from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, normalize_interface
from ansible.module_utils.network.nxos.nxos import get_interface_type
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.common.utils import conditional, remove_default_spec

Expand Down Expand Up @@ -231,27 +232,6 @@ def search_obj_in_list(name, lst):
return None


def get_interface_type(interface):
"""Gets the type of interface
"""
if interface.upper().startswith('ET'):
return 'ethernet'
elif interface.upper().startswith('VL'):
return 'svi'
elif interface.upper().startswith('LO'):
return 'loopback'
elif interface.upper().startswith('MG'):
return 'management'
elif interface.upper().startswith('MA'):
return 'management'
elif interface.upper().startswith('PO'):
return 'portchannel'
elif interface.upper().startswith('NV'):
return 'nve'
else:
return 'unknown'


def get_interfaces_dict(module):
"""Gets all active interfaces on a given switch
"""
Expand Down
27 changes: 1 addition & 26 deletions lib/ansible/modules/network/nxos/nxos_l2_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,36 +120,11 @@
from copy import deepcopy

from ansible.module_utils.network.nxos.nxos import get_config, load_config, run_commands
from ansible.module_utils.network.nxos.nxos import nxos_argument_spec
from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, get_interface_type
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.common.utils import remove_default_spec


def get_interface_type(name):
"""Gets the type of interface
Args:
interface (str): full name of interface, i.e. Ethernet1/1, loopback10,
port-channel20, vlan20
Returns:
type of interface: ethernet, svi, loopback, management, portchannel,
or unknown
"""
if name.upper().startswith('ET'):
return 'ethernet'
elif name.upper().startswith('VL'):
return 'svi'
elif name.upper().startswith('LO'):
return 'loopback'
elif name.upper().startswith('MG'):
return 'management'
elif name.upper().startswith('MA'):
return 'management'
elif name.upper().startswith('PO'):
return 'portchannel'
else:
return 'unknown'


def get_interface_mode(name, module):
"""Gets current mode of interface: layer2 or layer3
Args:
Expand Down
18 changes: 1 addition & 17 deletions lib/ansible/modules/network/nxos/nxos_pim_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.nxos.nxos import get_config, load_config, run_commands
from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, check_args
from ansible.module_utils.network.nxos.nxos import get_interface_type
from ansible.module_utils.six import string_types


Expand Down Expand Up @@ -200,23 +201,6 @@ def local_existing(gexisting):
return gexisting, jp_bidir, isauth


def get_interface_type(interface):
if interface.upper().startswith('ET'):
return 'ethernet'
elif interface.upper().startswith('VL'):
return 'svi'
elif interface.upper().startswith('LO'):
return 'loopback'
elif interface.upper().startswith('MG'):
return 'management'
elif interface.upper().startswith('MA'):
return 'management'
elif interface.upper().startswith('PO'):
return 'portchannel'
else:
return 'unknown'


def get_interface_mode(interface, intf_type, module):
mode = 'unknown'
command = 'show interface {0}'.format(interface)
Expand Down
17 changes: 11 additions & 6 deletions lib/ansible/modules/network/nxos/nxos_vrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.nxos.nxos import load_config, run_commands
from ansible.module_utils.network.nxos.nxos import nxos_argument_spec
from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, get_interface_type
from ansible.module_utils.network.common.utils import remove_default_spec


Expand Down Expand Up @@ -262,7 +262,8 @@ def map_obj_to_commands(updates, module):
if interfaces and interfaces[0] != 'default':
for i in interfaces:
commands.append('interface {0}'.format(i))
commands.append('no switchport')
if get_interface_type(i) in ('ethernet', 'portchannel'):
commands.append('no switchport')
commands.append('vrf member {0}'.format(name))

else:
Expand Down Expand Up @@ -296,7 +297,8 @@ def map_obj_to_commands(updates, module):
commands.append('vrf context {0}'.format(name))
commands.append('exit')
commands.append('interface {0}'.format(i))
commands.append('no switchport')
if get_interface_type(i) in ('ethernet', 'portchannel'):
commands.append('no switchport')
commands.append('vrf member {0}'.format(name))

elif set(interfaces) != set(obj_in_have['interfaces']):
Expand All @@ -305,23 +307,26 @@ def map_obj_to_commands(updates, module):
commands.append('vrf context {0}'.format(name))
commands.append('exit')
commands.append('interface {0}'.format(i))
commands.append('no switchport')
if get_interface_type(i) in ('ethernet', 'portchannel'):
commands.append('no switchport')
commands.append('vrf member {0}'.format(name))

superfluous_interfaces = list(set(obj_in_have['interfaces']) - set(interfaces))
for i in superfluous_interfaces:
commands.append('vrf context {0}'.format(name))
commands.append('exit')
commands.append('interface {0}'.format(i))
commands.append('no switchport')
if get_interface_type(i) in ('ethernet', 'portchannel'):
commands.append('no switchport')
commands.append('no vrf member {0}'.format(name))
elif interfaces and interfaces[0] == 'default':
if obj_in_have['interfaces']:
for i in obj_in_have['interfaces']:
commands.append('vrf context {0}'.format(name))
commands.append('exit')
commands.append('interface {0}'.format(i))
commands.append('no switchport')
if get_interface_type(i) in ('ethernet', 'portchannel'):
commands.append('no switchport')
commands.append('no vrf member {0}'.format(name))

if purge:
Expand Down
18 changes: 1 addition & 17 deletions lib/ansible/modules/network/nxos/nxos_vrf_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@

from ansible.module_utils.network.nxos.nxos import load_config, run_commands
from ansible.module_utils.network.nxos.nxos import get_capabilities, nxos_argument_spec
from ansible.module_utils.network.nxos.nxos import get_interface_type
from ansible.module_utils.basic import AnsibleModule


Expand All @@ -97,23 +98,6 @@ def execute_show_command(command, module):
return run_commands(module, cmds)[0]


def get_interface_type(interface):
if interface.upper().startswith('ET'):
return 'ethernet'
elif interface.upper().startswith('VL'):
return 'svi'
elif interface.upper().startswith('LO'):
return 'loopback'
elif interface.upper().startswith('MG'):
return 'management'
elif interface.upper().startswith('MA'):
return 'management'
elif interface.upper().startswith('PO'):
return 'portchannel'
else:
return 'unknown'


def get_interface_mode(interface, intf_type, module):
command = 'show interface {0}'.format(interface)
interface = {}
Expand Down
18 changes: 1 addition & 17 deletions lib/ansible/modules/network/nxos/nxos_vrrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@

from ansible.module_utils.network.nxos.nxos import load_config, run_commands
from ansible.module_utils.network.nxos.nxos import get_capabilities, nxos_argument_spec
from ansible.module_utils.network.nxos.nxos import get_interface_type
from ansible.module_utils.basic import AnsibleModule


Expand Down Expand Up @@ -154,23 +155,6 @@ def apply_key_map(key_map, table):
return new_dict


def get_interface_type(interface):
if interface.upper().startswith('ET'):
return 'ethernet'
elif interface.upper().startswith('VL'):
return 'svi'
elif interface.upper().startswith('LO'):
return 'loopback'
elif interface.upper().startswith('MG'):
return 'management'
elif interface.upper().startswith('MA'):
return 'management'
elif interface.upper().startswith('PO'):
return 'portchannel'
else:
return 'unknown'


def is_default(interface, module):
command = 'show run interface {0}'.format(interface)

Expand Down

0 comments on commit 4bb99bd

Please sign in to comment.