nxos module cleanup (#5065)

* Fix imports on nxos_bgp* modules

* Fix imports on nxos_evpn* modules

* Cleanup issues for nxos_facts

* Shuffle imports for nxos_template

* Fix imports on nxos_ospf* modules

* Fix nxos_hsrp

As get_hsrp_groups_in_devices is not actually called anywhere, I presume this
change is reasonable.

* Fix imports on nxos_interface* modules

* Update nxos_static_route imports

* update nxos_vrf

* Update nxos_config imports
This commit is contained in:
Nathaniel Case 2016-10-08 15:29:24 -04:00 committed by Matt Clay
parent 706bdbf284
commit 5a8ebf5953
16 changed files with 86 additions and 94 deletions

View file

@ -109,8 +109,9 @@ responses:
type: list
sample: ['...', '...']
"""
import ansible.module_utils.nxos
from ansible.module_utils.netcfg import NetworkConfig, dumps
from ansible.module_utils.nxos import NetworkModule, NetworkError
from ansible.module_utils.network import NetworkModule
def get_config(module):
config = module.params['config'] or dict()

View file

@ -354,12 +354,11 @@ import collections
import itertools
import shlex
from ansible.module_utils.basic import AnsibleModule, env_fallback, get_exception
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
from ansible.module_utils.shell import Shell, ShellError, HAS_PARAMIKO
from ansible.module_utils.netcfg import parse
from ansible.module_utils.urls import fetch_url
import ansible.module_utils.nxos
from ansible.module_utils.basic import get_exception
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
from ansible.module_utils.network import NetworkModule
from ansible.module_utils.shell import ShellError
DEFAULT_COMMENT_TOKENS = ['#', '!']

View file

@ -308,11 +308,11 @@ import collections
import itertools
import shlex
from ansible.module_utils.basic import AnsibleModule, env_fallback, get_exception
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
from ansible.module_utils.shell import Shell, ShellError, HAS_PARAMIKO
from ansible.module_utils.netcfg import parse
from ansible.module_utils.urls import fetch_url
import ansible.module_utils.nxos
from ansible.module_utils.basic import get_exception
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
from ansible.module_utils.network import NetworkModule
from ansible.module_utils.shell import ShellError
DEFAULT_COMMENT_TOKENS = ['#', '!']

View file

@ -253,12 +253,11 @@ import collections
import itertools
import shlex
from ansible.module_utils.basic import AnsibleModule, env_fallback, get_exception
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
from ansible.module_utils.shell import Shell, ShellError, HAS_PARAMIKO
from ansible.module_utils.netcfg import parse
from ansible.module_utils.urls import fetch_url
import ansible.module_utils.nxos
from ansible.module_utils.basic import get_exception
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
from ansible.module_utils.network import NetworkModule
from ansible.module_utils.shell import ShellError
DEFAULT_COMMENT_TOKENS = ['#', '!']

View file

@ -330,12 +330,11 @@ import collections
import itertools
import shlex
from ansible.module_utils.basic import AnsibleModule, env_fallback, get_exception
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
from ansible.module_utils.shell import Shell, ShellError, HAS_PARAMIKO
from ansible.module_utils.netcfg import parse
from ansible.module_utils.urls import fetch_url
import ansible.module_utils.nxos
from ansible.module_utils.basic import get_exception
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
from ansible.module_utils.network import NetworkModule
from ansible.module_utils.shell import ShellError
DEFAULT_COMMENT_TOKENS = ['#', '!']

View file

@ -208,11 +208,11 @@ backup_path:
type: path
sample: /playbooks/ansible/backup/nxos_config.2016-07-16@22:28:34
"""
import time
from ansible.module_utils.netcfg import NetworkConfig, dumps
from ansible.module_utils.nxos import NetworkModule, NetworkError
import ansible.module_utils.nxos
from ansible.module_utils.basic import get_exception
from ansible.module_utils.network import NetworkModule, NetworkError
from ansible.module_utils.netcfg import NetworkConfig, dumps
def check_args(module, warnings):
if module.params['force']:

View file

@ -84,9 +84,12 @@ import itertools
import shlex
import itertools
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
DEFAULT_COMMENT_TOKENS = ['#', '!']
import ansible.module_utils.nxos
from ansible.module_utils.basic import get_exception
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
from ansible.module_utils.network import NetworkModule
from ansible.module_utils.shell import ShellError
class ConfigLine(object):

View file

@ -135,12 +135,11 @@ import collections
import itertools
import shlex
from ansible.module_utils.basic import AnsibleModule, env_fallback, get_exception
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
from ansible.module_utils.shell import Shell, ShellError, HAS_PARAMIKO
from ansible.module_utils.netcfg import parse
from ansible.module_utils.urls import fetch_url
import ansible.module_utils.nxos
from ansible.module_utils.basic import get_exception
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
from ansible.module_utils.shell import ShellError
from ansible.module_utils.network import NetworkModule
DEFAULT_COMMENT_TOKENS = ['#', '!']

View file

@ -172,9 +172,11 @@ vlan_list:
"""
import re
import ansible.module_utils.nxos
from ansible.module_utils.basic import get_exception
from ansible.module_utils.netcli import CommandRunner, AddCommandError
from ansible.module_utils.nxos import NetworkModule, NetworkError
from ansible.module_utils.network import NetworkModule, NetworkError
from ansible.module_utils.six import iteritems
def add_command(runner, command, output=None):
@ -193,6 +195,9 @@ class FactsBase(object):
self.facts = dict()
self.commands()
def commands(self):
raise NotImplementedError
def transform_dict(self, data, keymap):
transform = dict()
for key, fact in keymap:
@ -255,7 +260,7 @@ class Interfaces(FactsBase):
('state', 'state'),
('desc', 'description'),
('eth_bw', 'bandwidth'),
('eth_duplex','duplex'),
('eth_duplex', 'duplex'),
('eth_speed', 'speed'),
('eth_mode', 'mode'),
('eth_hw_addr', 'macaddress'),
@ -511,7 +516,7 @@ def main():
module.exit_json(out=module.from_json(runner.items))
ansible_facts = dict()
for key, value in facts.iteritems():
for key, value in iteritems(facts):
# this is to maintain capability with nxos_facts 2.1
if key.startswith('_'):
ansible_facts[key[1:]] = value

View file

@ -118,23 +118,16 @@ changed:
sample: true
'''
# COMMON CODE FOR MIGRATION
import re
import time
import collections
import itertools
import shlex
DEFAULT_COMMENT_TOKENS = ['#', '!']
import json
from ansible.module_utils.basic import AnsibleModule, env_fallback, get_exception
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
from ansible.module_utils.shell import Shell, ShellError, HAS_PARAMIKO
from ansible.module_utils.netcfg import parse
from ansible.module_utils.urls import fetch_url
# COMMON CODE FOR MIGRATION
DEFAULT_COMMENT_TOKENS = ['#', '!']
import ansible.module_utils.nxos
from ansible.module_utils.basic import get_exception
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
from ansible.module_utils.shell import ShellError
from ansible.module_utils.network import NetworkModule
class ConfigLine(object):
@ -922,7 +915,7 @@ def get_interface_mode(interface, intf_type, module):
return mode
def get_hsrp_groups_on_interfaces(device):
def get_hsrp_groups_on_interfaces(device, module):
command = 'show hsrp all'
body = execute_show_command(command, module)
hsrp = {}

View file

@ -135,20 +135,15 @@ changed:
'''
import json
import collections
# COMMON CODE FOR MIGRATION
import re
import ansible.module_utils.nxos
from ansible.module_utils.basic import get_exception
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
from ansible.module_utils.network import NetworkModule
from ansible.module_utils.shell import ShellError
try:
from ansible.module_utils.nxos import get_module
except ImportError:
from ansible.module_utils.nxos import NetworkModule
def to_list(val):
if isinstance(val, (list, tuple)):
@ -308,7 +303,7 @@ def is_default_interface(interface, module):
body = execute_show_command(command, module,
command_type='cli_show_ascii')[0]
except IndexError:
body = []
body = ''
if body:
raw_list = body.split('\n')

View file

@ -175,14 +175,13 @@ import collections
import itertools
import shlex
from ansible.module_utils.basic import AnsibleModule, env_fallback, get_exception
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
from ansible.module_utils.shell import Shell, ShellError, HAS_PARAMIKO
from ansible.module_utils.netcfg import parse
from ansible.module_utils.urls import fetch_url
DEFAULT_COMMENT_TOKENS = ['#', '!']
import ansible.module_utils.nxos
from ansible.module_utils.basic import get_exception
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
from ansible.module_utils.network import NetworkModule
from ansible.module_utils.shell import ShellError
class ConfigLine(object):

View file

@ -91,9 +91,12 @@ import itertools
import shlex
import itertools
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
DEFAULT_COMMENT_TOKENS = ['#', '!']
import ansible.module_utils.nxos
from ansible.module_utils.basic import get_exception
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
from ansible.module_utils.network import NetworkModule
from ansible.module_utils.shell import ShellError
class ConfigLine(object):

View file

@ -183,12 +183,11 @@ import collections
import itertools
import shlex
from ansible.module_utils.basic import AnsibleModule, env_fallback, get_exception
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
from ansible.module_utils.shell import Shell, ShellError, HAS_PARAMIKO
from ansible.module_utils.netcfg import parse
from ansible.module_utils.urls import fetch_url
import ansible.module_utils.nxos
from ansible.module_utils.basic import get_exception
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
from ansible.module_utils.network import NetworkModule
from ansible.module_utils.shell import ShellError
DEFAULT_COMMENT_TOKENS = ['#', '!']

View file

@ -120,12 +120,10 @@ import collections
import itertools
import shlex
from ansible.module_utils.basic import AnsibleModule, env_fallback, get_exception
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
from ansible.module_utils.shell import Shell, ShellError, HAS_PARAMIKO
from ansible.module_utils.netcfg import parse
from ansible.module_utils.urls import fetch_url
import ansible.module_utils.nxos
from ansible.module_utils.basic import get_exception
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine, dumps
from ansible.module_utils.network import NetworkModule
DEFAULT_COMMENT_TOKENS = ['#', '!']
@ -309,7 +307,7 @@ class CustomNetworkConfig(object):
try:
section = self.get_section_objects(path)
if self._device_os == 'junos':
return self.to_lines(section)
return dumps(section, output='lines')
return self.to_block(section)
except ValueError:
return list()
@ -928,10 +926,10 @@ def network_from_string(address, mask, module):
def normalize_prefix(module, prefix):
splitted_prefix = prefix.split('/')
address = splitted_prefix[0]
if len(splitted_prefix) > 2:
module.fail_json(msg='Incorrect address format.', address=address)
elif len(splitted_prefix) == 2:
address = splitted_prefix[0]
mask = splitted_prefix[1]
network = network_from_string(address, mask, module)

View file

@ -112,6 +112,8 @@ changed:
sample: true
'''
import json
# COMMON CODE FOR MIGRATION
import re
@ -121,12 +123,11 @@ import itertools
import shlex
import json
from ansible.module_utils.basic import AnsibleModule, env_fallback, get_exception
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
from ansible.module_utils.shell import Shell, ShellError, HAS_PARAMIKO
from ansible.module_utils.netcfg import parse
from ansible.module_utils.urls import fetch_url
import ansible.module_utils.nxos
from ansible.module_utils.basic import get_exception
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
from ansible.module_utils.shell import ShellError
from ansible.module_utils.network import NetworkModule
DEFAULT_COMMENT_TOKENS = ['#', '!']
@ -903,11 +904,10 @@ def get_commands_to_config_vrf(delta, vrf):
def get_vrf_description(vrf, module):
command_type = 'cli_show_ascii'
command = ('show run section vrf | begin ^vrf\scontext\s{0} '
'| end ^vrf.*'.format(vrf))
command = (r'show run section vrf | begin ^vrf\scontext\s{0} | end ^vrf.*'.format(vrf))
description = ''
descr_regex = ".*description\s(?P<descr>[\S+\s]+).*"
descr_regex = r".*description\s(?P<descr>[\S+\s]+).*"
body = execute_show_command(command, module, command_type)
try:
@ -1022,7 +1022,7 @@ def main():
if existing.get('vni') and existing.get('vni') != '':
commands.insert(1, 'no vni {0}'.format(existing['vni']))
if module.check_mode:
module.exit_json(changed=True, commands=cmds)
module.exit_json(changed=True, commands=commands)
else:
execute_config_command(commands, module)
changed = True