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:
parent
706bdbf284
commit
5a8ebf5953
16 changed files with 86 additions and 94 deletions
|
@ -109,8 +109,9 @@ responses:
|
||||||
type: list
|
type: list
|
||||||
sample: ['...', '...']
|
sample: ['...', '...']
|
||||||
"""
|
"""
|
||||||
|
import ansible.module_utils.nxos
|
||||||
from ansible.module_utils.netcfg import NetworkConfig, dumps
|
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):
|
def get_config(module):
|
||||||
config = module.params['config'] or dict()
|
config = module.params['config'] or dict()
|
||||||
|
|
|
@ -354,12 +354,11 @@ import collections
|
||||||
import itertools
|
import itertools
|
||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule, env_fallback, get_exception
|
import ansible.module_utils.nxos
|
||||||
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
|
from ansible.module_utils.basic import get_exception
|
||||||
from ansible.module_utils.shell import Shell, ShellError, HAS_PARAMIKO
|
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
|
||||||
from ansible.module_utils.netcfg import parse
|
from ansible.module_utils.network import NetworkModule
|
||||||
from ansible.module_utils.urls import fetch_url
|
from ansible.module_utils.shell import ShellError
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_COMMENT_TOKENS = ['#', '!']
|
DEFAULT_COMMENT_TOKENS = ['#', '!']
|
||||||
|
|
||||||
|
|
|
@ -308,11 +308,11 @@ import collections
|
||||||
import itertools
|
import itertools
|
||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule, env_fallback, get_exception
|
import ansible.module_utils.nxos
|
||||||
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
|
from ansible.module_utils.basic import get_exception
|
||||||
from ansible.module_utils.shell import Shell, ShellError, HAS_PARAMIKO
|
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
|
||||||
from ansible.module_utils.netcfg import parse
|
from ansible.module_utils.network import NetworkModule
|
||||||
from ansible.module_utils.urls import fetch_url
|
from ansible.module_utils.shell import ShellError
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_COMMENT_TOKENS = ['#', '!']
|
DEFAULT_COMMENT_TOKENS = ['#', '!']
|
||||||
|
|
|
@ -253,12 +253,11 @@ import collections
|
||||||
import itertools
|
import itertools
|
||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule, env_fallback, get_exception
|
import ansible.module_utils.nxos
|
||||||
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
|
from ansible.module_utils.basic import get_exception
|
||||||
from ansible.module_utils.shell import Shell, ShellError, HAS_PARAMIKO
|
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
|
||||||
from ansible.module_utils.netcfg import parse
|
from ansible.module_utils.network import NetworkModule
|
||||||
from ansible.module_utils.urls import fetch_url
|
from ansible.module_utils.shell import ShellError
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_COMMENT_TOKENS = ['#', '!']
|
DEFAULT_COMMENT_TOKENS = ['#', '!']
|
||||||
|
|
||||||
|
|
|
@ -330,12 +330,11 @@ import collections
|
||||||
import itertools
|
import itertools
|
||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule, env_fallback, get_exception
|
import ansible.module_utils.nxos
|
||||||
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
|
from ansible.module_utils.basic import get_exception
|
||||||
from ansible.module_utils.shell import Shell, ShellError, HAS_PARAMIKO
|
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
|
||||||
from ansible.module_utils.netcfg import parse
|
from ansible.module_utils.network import NetworkModule
|
||||||
from ansible.module_utils.urls import fetch_url
|
from ansible.module_utils.shell import ShellError
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_COMMENT_TOKENS = ['#', '!']
|
DEFAULT_COMMENT_TOKENS = ['#', '!']
|
||||||
|
|
||||||
|
|
|
@ -208,11 +208,11 @@ backup_path:
|
||||||
type: path
|
type: path
|
||||||
sample: /playbooks/ansible/backup/nxos_config.2016-07-16@22:28:34
|
sample: /playbooks/ansible/backup/nxos_config.2016-07-16@22:28:34
|
||||||
"""
|
"""
|
||||||
import time
|
|
||||||
|
|
||||||
from ansible.module_utils.netcfg import NetworkConfig, dumps
|
import ansible.module_utils.nxos
|
||||||
from ansible.module_utils.nxos import NetworkModule, NetworkError
|
|
||||||
from ansible.module_utils.basic import get_exception
|
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):
|
def check_args(module, warnings):
|
||||||
if module.params['force']:
|
if module.params['force']:
|
||||||
|
|
|
@ -84,9 +84,12 @@ import itertools
|
||||||
import shlex
|
import shlex
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
|
|
||||||
|
|
||||||
DEFAULT_COMMENT_TOKENS = ['#', '!']
|
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):
|
class ConfigLine(object):
|
||||||
|
|
||||||
|
|
|
@ -135,12 +135,11 @@ import collections
|
||||||
import itertools
|
import itertools
|
||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule, env_fallback, get_exception
|
import ansible.module_utils.nxos
|
||||||
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
|
from ansible.module_utils.basic import get_exception
|
||||||
from ansible.module_utils.shell import Shell, ShellError, HAS_PARAMIKO
|
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
|
||||||
from ansible.module_utils.netcfg import parse
|
from ansible.module_utils.shell import ShellError
|
||||||
from ansible.module_utils.urls import fetch_url
|
from ansible.module_utils.network import NetworkModule
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_COMMENT_TOKENS = ['#', '!']
|
DEFAULT_COMMENT_TOKENS = ['#', '!']
|
||||||
|
|
||||||
|
|
|
@ -172,9 +172,11 @@ vlan_list:
|
||||||
"""
|
"""
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
import ansible.module_utils.nxos
|
||||||
from ansible.module_utils.basic import get_exception
|
from ansible.module_utils.basic import get_exception
|
||||||
from ansible.module_utils.netcli import CommandRunner, AddCommandError
|
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):
|
def add_command(runner, command, output=None):
|
||||||
|
@ -193,6 +195,9 @@ class FactsBase(object):
|
||||||
self.facts = dict()
|
self.facts = dict()
|
||||||
self.commands()
|
self.commands()
|
||||||
|
|
||||||
|
def commands(self):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
def transform_dict(self, data, keymap):
|
def transform_dict(self, data, keymap):
|
||||||
transform = dict()
|
transform = dict()
|
||||||
for key, fact in keymap:
|
for key, fact in keymap:
|
||||||
|
@ -255,7 +260,7 @@ class Interfaces(FactsBase):
|
||||||
('state', 'state'),
|
('state', 'state'),
|
||||||
('desc', 'description'),
|
('desc', 'description'),
|
||||||
('eth_bw', 'bandwidth'),
|
('eth_bw', 'bandwidth'),
|
||||||
('eth_duplex','duplex'),
|
('eth_duplex', 'duplex'),
|
||||||
('eth_speed', 'speed'),
|
('eth_speed', 'speed'),
|
||||||
('eth_mode', 'mode'),
|
('eth_mode', 'mode'),
|
||||||
('eth_hw_addr', 'macaddress'),
|
('eth_hw_addr', 'macaddress'),
|
||||||
|
@ -511,7 +516,7 @@ def main():
|
||||||
module.exit_json(out=module.from_json(runner.items))
|
module.exit_json(out=module.from_json(runner.items))
|
||||||
|
|
||||||
ansible_facts = dict()
|
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
|
# this is to maintain capability with nxos_facts 2.1
|
||||||
if key.startswith('_'):
|
if key.startswith('_'):
|
||||||
ansible_facts[key[1:]] = value
|
ansible_facts[key[1:]] = value
|
||||||
|
|
|
@ -118,23 +118,16 @@ changed:
|
||||||
sample: true
|
sample: true
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# COMMON CODE FOR MIGRATION
|
DEFAULT_COMMENT_TOKENS = ['#', '!']
|
||||||
|
|
||||||
import re
|
|
||||||
import time
|
|
||||||
import collections
|
|
||||||
import itertools
|
|
||||||
import shlex
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule, env_fallback, get_exception
|
# COMMON CODE FOR MIGRATION
|
||||||
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
|
||||||
DEFAULT_COMMENT_TOKENS = ['#', '!']
|
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):
|
class ConfigLine(object):
|
||||||
|
|
||||||
|
@ -922,7 +915,7 @@ def get_interface_mode(interface, intf_type, module):
|
||||||
return mode
|
return mode
|
||||||
|
|
||||||
|
|
||||||
def get_hsrp_groups_on_interfaces(device):
|
def get_hsrp_groups_on_interfaces(device, module):
|
||||||
command = 'show hsrp all'
|
command = 'show hsrp all'
|
||||||
body = execute_show_command(command, module)
|
body = execute_show_command(command, module)
|
||||||
hsrp = {}
|
hsrp = {}
|
||||||
|
|
|
@ -135,20 +135,15 @@ changed:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import collections
|
|
||||||
|
|
||||||
# COMMON CODE FOR MIGRATION
|
# COMMON CODE FOR MIGRATION
|
||||||
import re
|
|
||||||
|
|
||||||
|
import ansible.module_utils.nxos
|
||||||
from ansible.module_utils.basic import get_exception
|
from ansible.module_utils.basic import get_exception
|
||||||
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
|
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
|
||||||
|
from ansible.module_utils.network import NetworkModule
|
||||||
from ansible.module_utils.shell import ShellError
|
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):
|
def to_list(val):
|
||||||
if isinstance(val, (list, tuple)):
|
if isinstance(val, (list, tuple)):
|
||||||
|
@ -308,7 +303,7 @@ def is_default_interface(interface, module):
|
||||||
body = execute_show_command(command, module,
|
body = execute_show_command(command, module,
|
||||||
command_type='cli_show_ascii')[0]
|
command_type='cli_show_ascii')[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
body = []
|
body = ''
|
||||||
|
|
||||||
if body:
|
if body:
|
||||||
raw_list = body.split('\n')
|
raw_list = body.split('\n')
|
||||||
|
|
|
@ -175,14 +175,13 @@ import collections
|
||||||
import itertools
|
import itertools
|
||||||
import shlex
|
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 = ['#', '!']
|
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):
|
class ConfigLine(object):
|
||||||
|
|
||||||
|
|
|
@ -91,9 +91,12 @@ import itertools
|
||||||
import shlex
|
import shlex
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
|
|
||||||
|
|
||||||
DEFAULT_COMMENT_TOKENS = ['#', '!']
|
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):
|
class ConfigLine(object):
|
||||||
|
|
||||||
|
|
|
@ -183,12 +183,11 @@ import collections
|
||||||
import itertools
|
import itertools
|
||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule, env_fallback, get_exception
|
import ansible.module_utils.nxos
|
||||||
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
|
from ansible.module_utils.basic import get_exception
|
||||||
from ansible.module_utils.shell import Shell, ShellError, HAS_PARAMIKO
|
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
|
||||||
from ansible.module_utils.netcfg import parse
|
from ansible.module_utils.network import NetworkModule
|
||||||
from ansible.module_utils.urls import fetch_url
|
from ansible.module_utils.shell import ShellError
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_COMMENT_TOKENS = ['#', '!']
|
DEFAULT_COMMENT_TOKENS = ['#', '!']
|
||||||
|
|
||||||
|
|
|
@ -120,12 +120,10 @@ import collections
|
||||||
import itertools
|
import itertools
|
||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule, env_fallback, get_exception
|
import ansible.module_utils.nxos
|
||||||
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
|
from ansible.module_utils.basic import get_exception
|
||||||
from ansible.module_utils.shell import Shell, ShellError, HAS_PARAMIKO
|
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine, dumps
|
||||||
from ansible.module_utils.netcfg import parse
|
from ansible.module_utils.network import NetworkModule
|
||||||
from ansible.module_utils.urls import fetch_url
|
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_COMMENT_TOKENS = ['#', '!']
|
DEFAULT_COMMENT_TOKENS = ['#', '!']
|
||||||
|
|
||||||
|
@ -309,7 +307,7 @@ class CustomNetworkConfig(object):
|
||||||
try:
|
try:
|
||||||
section = self.get_section_objects(path)
|
section = self.get_section_objects(path)
|
||||||
if self._device_os == 'junos':
|
if self._device_os == 'junos':
|
||||||
return self.to_lines(section)
|
return dumps(section, output='lines')
|
||||||
return self.to_block(section)
|
return self.to_block(section)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return list()
|
return list()
|
||||||
|
@ -928,10 +926,10 @@ def network_from_string(address, mask, module):
|
||||||
def normalize_prefix(module, prefix):
|
def normalize_prefix(module, prefix):
|
||||||
splitted_prefix = prefix.split('/')
|
splitted_prefix = prefix.split('/')
|
||||||
|
|
||||||
|
address = splitted_prefix[0]
|
||||||
if len(splitted_prefix) > 2:
|
if len(splitted_prefix) > 2:
|
||||||
module.fail_json(msg='Incorrect address format.', address=address)
|
module.fail_json(msg='Incorrect address format.', address=address)
|
||||||
elif len(splitted_prefix) == 2:
|
elif len(splitted_prefix) == 2:
|
||||||
address = splitted_prefix[0]
|
|
||||||
mask = splitted_prefix[1]
|
mask = splitted_prefix[1]
|
||||||
network = network_from_string(address, mask, module)
|
network = network_from_string(address, mask, module)
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,8 @@ changed:
|
||||||
sample: true
|
sample: true
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
# COMMON CODE FOR MIGRATION
|
# COMMON CODE FOR MIGRATION
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
@ -121,12 +123,11 @@ import itertools
|
||||||
import shlex
|
import shlex
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule, env_fallback, get_exception
|
import ansible.module_utils.nxos
|
||||||
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
|
from ansible.module_utils.basic import get_exception
|
||||||
from ansible.module_utils.shell import Shell, ShellError, HAS_PARAMIKO
|
from ansible.module_utils.netcfg import NetworkConfig, ConfigLine
|
||||||
from ansible.module_utils.netcfg import parse
|
from ansible.module_utils.shell import ShellError
|
||||||
from ansible.module_utils.urls import fetch_url
|
from ansible.module_utils.network import NetworkModule
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_COMMENT_TOKENS = ['#', '!']
|
DEFAULT_COMMENT_TOKENS = ['#', '!']
|
||||||
|
|
||||||
|
@ -903,11 +904,10 @@ def get_commands_to_config_vrf(delta, vrf):
|
||||||
|
|
||||||
def get_vrf_description(vrf, module):
|
def get_vrf_description(vrf, module):
|
||||||
command_type = 'cli_show_ascii'
|
command_type = 'cli_show_ascii'
|
||||||
command = ('show run section vrf | begin ^vrf\scontext\s{0} '
|
command = (r'show run section vrf | begin ^vrf\scontext\s{0} | end ^vrf.*'.format(vrf))
|
||||||
'| end ^vrf.*'.format(vrf))
|
|
||||||
|
|
||||||
description = ''
|
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)
|
body = execute_show_command(command, module, command_type)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -1022,7 +1022,7 @@ def main():
|
||||||
if existing.get('vni') and existing.get('vni') != '':
|
if existing.get('vni') and existing.get('vni') != '':
|
||||||
commands.insert(1, 'no vni {0}'.format(existing['vni']))
|
commands.insert(1, 'no vni {0}'.format(existing['vni']))
|
||||||
if module.check_mode:
|
if module.check_mode:
|
||||||
module.exit_json(changed=True, commands=cmds)
|
module.exit_json(changed=True, commands=commands)
|
||||||
else:
|
else:
|
||||||
execute_config_command(commands, module)
|
execute_config_command(commands, module)
|
||||||
changed = True
|
changed = True
|
||||||
|
|
Loading…
Reference in a new issue