From 7351ee9a762bd2156135391144ac06ed03adb296 Mon Sep 17 00:00:00 2001 From: Trishna Guha Date: Thu, 27 Jul 2017 19:23:35 +0530 Subject: [PATCH] fix nxos_interface multiple issues (#27106) * fix execute_show_command * fix pep8 issues * fix AttributeError #26562 * legacy-file remove * modify execute_show_command output * fix admin_state up doc * fix admin_state for all interfaces doc Signed-off-by: Trishna Guha --- .../modules/network/nxos/nxos_interface.py | 44 +++++++++---------- test/sanity/pep8/legacy-files.txt | 1 - 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/lib/ansible/modules/network/nxos/nxos_interface.py b/lib/ansible/modules/network/nxos/nxos_interface.py index 19a48310671..66ffd46324f 100644 --- a/lib/ansible/modules/network/nxos/nxos_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_interface.py @@ -123,16 +123,14 @@ EXAMPLES = ''' - svi - nve -- name: Admin up all ethernet interfaces +- name: Admin up all loopback interfaces nxos_interface: - interface: ethernet - host: 68.170.147.165 + interface: loopback 0-1023 admin_state: up -- name: Admin down ALL interfaces (physical and logical) +- name: Admin down all loopback interfaces nxos_interface: - interface: all - host: 68.170.147.165 + interface: looback 0-1023 admin_state: down ''' @@ -149,8 +147,6 @@ from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule - - def is_default_interface(interface, module): """Checks to see if interface exists and if it is a default config Args: @@ -386,14 +382,15 @@ def get_interfaces_dict(module): 'portchannel': [], 'nve': [], 'unknown': [] - } + } - interface_list = body.get('TABLE_interface')['ROW_interface'] - for index in interface_list: - intf = index['interface'] - intf_type = get_interface_type(intf) + if body: + interface_list = body['TABLE_interface']['ROW_interface'] + for index in interface_list: + intf = index['interface'] + intf_type = get_interface_type(intf) - interfaces[intf_type].append(intf) + interfaces[intf_type].append(intf) return interfaces @@ -547,9 +544,15 @@ def smart_existing(module, intf_type, normalized_interface): def execute_show_command(command, module): - if module.params['transport'] == 'cli': - command += ' | json' - cmds = [command] + if 'show run' not in command: + output = 'json' + else: + output = 'text' + cmds = [{ + 'command': command, + 'output': output, + }] + body = run_commands(module, cmds) return body @@ -584,10 +587,7 @@ def main(): interface_type=dict(required=False, choices=['loopback', 'portchannel', 'svi', 'nve']), ip_forward=dict(required=False, choices=['enable', 'disable']), fabric_forwarding_anycast_gateway=dict(required=False, type='bool'), - state=dict(choices=['absent', 'present', 'default'], default='present', required=False), - include_defaults=dict(default=True), - config=dict(), - save=dict(type='bool', default=False) + state=dict(choices=['absent', 'present', 'default'], default='present', required=False) ) argument_spec.update(nxos_argument_spec) @@ -687,7 +687,7 @@ def main(): load_config(module, cmds) results['changed'] = True if module.params['interface']: - if delta.get('mode'): # or delta.get('admin_state'): + if delta.get('mode'): # if the mode changes from L2 to L3, the admin state # seems to change after the API call, so adding a second API # call to ensure it's in the desired state. diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index 37550d417f7..29608f040e8 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -348,7 +348,6 @@ lib/ansible/modules/network/nxos/nxos_igmp.py lib/ansible/modules/network/nxos/nxos_igmp_interface.py lib/ansible/modules/network/nxos/nxos_igmp_snooping.py lib/ansible/modules/network/nxos/nxos_install_os.py -lib/ansible/modules/network/nxos/nxos_interface.py lib/ansible/modules/network/nxos/nxos_ntp.py lib/ansible/modules/network/nxos/nxos_ntp_auth.py lib/ansible/modules/network/nxos/nxos_ntp_options.py