diff --git a/network/nxos/_nxos_template.py b/network/nxos/_nxos_template.py index 371b93b0077..fe379629394 100644 --- a/network/nxos/_nxos_template.py +++ b/network/nxos/_nxos_template.py @@ -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() diff --git a/network/nxos/nxos_bgp.py b/network/nxos/nxos_bgp.py index 594e48aa9d3..9f7dd16a537 100644 --- a/network/nxos/nxos_bgp.py +++ b/network/nxos/nxos_bgp.py @@ -360,13 +360,11 @@ changed: # 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 - -try: - from ansible.module_utils.nxos import get_module -except ImportError: - from ansible.module_utils.nxos import NetworkModule +from ansible.module_utils.network import NetworkModule +from ansible.module_utils.shell import ShellError def to_list(val): diff --git a/network/nxos/nxos_bgp_af.py b/network/nxos/nxos_bgp_af.py index 728515f70d0..38e9ba0350d 100644 --- a/network/nxos/nxos_bgp_af.py +++ b/network/nxos/nxos_bgp_af.py @@ -299,13 +299,12 @@ changed: # 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): diff --git a/network/nxos/nxos_bgp_neighbor.py b/network/nxos/nxos_bgp_neighbor.py index 56a6c2923ff..a9080ae2f28 100644 --- a/network/nxos/nxos_bgp_neighbor.py +++ b/network/nxos/nxos_bgp_neighbor.py @@ -244,13 +244,11 @@ changed: # 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 - -try: - from ansible.module_utils.nxos import get_module -except ImportError: - from ansible.module_utils.nxos import NetworkModule +from ansible.module_utils.network import NetworkModule +from ansible.module_utils.shell import ShellError def to_list(val): diff --git a/network/nxos/nxos_bgp_neighbor_af.py b/network/nxos/nxos_bgp_neighbor_af.py index b6406674f3c..06ced09e7ce 100644 --- a/network/nxos/nxos_bgp_neighbor_af.py +++ b/network/nxos/nxos_bgp_neighbor_af.py @@ -321,13 +321,11 @@ changed: # 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 - -try: - from ansible.module_utils.nxos import get_module -except ImportError: - from ansible.module_utils.nxos import NetworkModule +from ansible.module_utils.network import NetworkModule +from ansible.module_utils.shell import ShellError def to_list(val): diff --git a/network/nxos/nxos_config.py b/network/nxos/nxos_config.py index bd15e5d8d2f..19b15d06ef9 100644 --- a/network/nxos/nxos_config.py +++ b/network/nxos/nxos_config.py @@ -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']: diff --git a/network/nxos/nxos_evpn_global.py b/network/nxos/nxos_evpn_global.py index c2bbe4fdce6..650a19370e1 100644 --- a/network/nxos/nxos_evpn_global.py +++ b/network/nxos/nxos_evpn_global.py @@ -72,13 +72,11 @@ changed: # 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 - -try: - from ansible.module_utils.nxos import get_module -except ImportError: - from ansible.module_utils.nxos import NetworkModule +from ansible.module_utils.network import NetworkModule +from ansible.module_utils.shell import ShellError def to_list(val): diff --git a/network/nxos/nxos_evpn_vni.py b/network/nxos/nxos_evpn_vni.py index 4ffcfeefcdb..a2de61d0620 100644 --- a/network/nxos/nxos_evpn_vni.py +++ b/network/nxos/nxos_evpn_vni.py @@ -126,14 +126,11 @@ changed: # 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.shell import ShellError - -try: - from ansible.module_utils.nxos import get_module -except ImportError: - from ansible.module_utils.nxos import NetworkModule +from ansible.module_utils.network import NetworkModule def to_list(val): diff --git a/network/nxos/nxos_facts.py b/network/nxos/nxos_facts.py index ff9c454aaa6..9d5defb9a8c 100644 --- a/network/nxos/nxos_facts.py +++ b/network/nxos/nxos_facts.py @@ -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 diff --git a/network/nxos/nxos_hsrp.py b/network/nxos/nxos_hsrp.py index b218d295910..d21fcaa6dd1 100644 --- a/network/nxos/nxos_hsrp.py +++ b/network/nxos/nxos_hsrp.py @@ -118,20 +118,15 @@ changed: sample: true ''' -import collections import json # 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.shell import ShellError - -try: - from ansible.module_utils.nxos import get_module -except ImportError: - from ansible.module_utils.nxos import NetworkModule +from ansible.module_utils.network import NetworkModule def to_list(val): @@ -406,7 +401,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 = {} diff --git a/network/nxos/nxos_interface.py b/network/nxos/nxos_interface.py index 927e93d3a88..7c1186ee924 100644 --- a/network/nxos/nxos_interface.py +++ b/network/nxos/nxos_interface.py @@ -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') diff --git a/network/nxos/nxos_interface_ospf.py b/network/nxos/nxos_interface_ospf.py index 34ec566cf4d..5cf050e85cc 100644 --- a/network/nxos/nxos_interface_ospf.py +++ b/network/nxos/nxos_interface_ospf.py @@ -166,15 +166,12 @@ changed: # 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)): diff --git a/network/nxos/nxos_ospf.py b/network/nxos/nxos_ospf.py index ea566da000f..5942785476a 100644 --- a/network/nxos/nxos_ospf.py +++ b/network/nxos/nxos_ospf.py @@ -80,13 +80,11 @@ changed: # 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 - -try: - from ansible.module_utils.nxos import get_module -except ImportError: - from ansible.module_utils.nxos import NetworkModule +from ansible.module_utils.network import NetworkModule +from ansible.module_utils.shell import ShellError def to_list(val): diff --git a/network/nxos/nxos_ospf_vrf.py b/network/nxos/nxos_ospf_vrf.py index 32fd7cfcba8..8b4d330c995 100644 --- a/network/nxos/nxos_ospf_vrf.py +++ b/network/nxos/nxos_ospf_vrf.py @@ -171,13 +171,11 @@ changed: # 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 - -try: - from ansible.module_utils.nxos import get_module -except ImportError: - from ansible.module_utils.nxos import NetworkModule +from ansible.module_utils.network import NetworkModule +from ansible.module_utils.shell import ShellError def to_list(val): diff --git a/network/nxos/nxos_static_route.py b/network/nxos/nxos_static_route.py index eb0555067f1..10a1f849ada 100644 --- a/network/nxos/nxos_static_route.py +++ b/network/nxos/nxos_static_route.py @@ -111,13 +111,10 @@ changed: # 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 - -try: - from ansible.module_utils.nxos import get_module -except ImportError: - from ansible.module_utils.nxos import NetworkModule +from ansible.module_utils.netcfg import NetworkConfig, ConfigLine, dumps +from ansible.module_utils.network import NetworkModule def to_list(val): @@ -155,7 +152,7 @@ class CustomNetworkConfig(NetworkConfig): 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() @@ -398,10 +395,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) diff --git a/network/nxos/nxos_vrf.py b/network/nxos/nxos_vrf.py index 40e11a70b9f..8c8c2c17925 100644 --- a/network/nxos/nxos_vrf.py +++ b/network/nxos/nxos_vrf.py @@ -111,19 +111,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.shell import ShellError - -try: - from ansible.module_utils.nxos import get_module -except ImportError: - from ansible.module_utils.nxos import NetworkModule +from ansible.module_utils.network import NetworkModule def to_list(val): @@ -385,11 +381,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[\S+\s]+).*" + descr_regex = r".*description\s(?P[\S+\s]+).*" body = execute_show_command(command, module, command_type) try: @@ -507,7 +502,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 @@ -526,4 +521,4 @@ def main(): if __name__ == '__main__': - main() \ No newline at end of file + main()