From 21078d74623bc07eec6a95a307a1b247b864daf2 Mon Sep 17 00:00:00 2001 From: Gabriele Date: Fri, 30 Sep 2016 16:24:44 -0400 Subject: [PATCH] Fixing nxos_vlan (#5005) * Fixing nxos_vlan * Fixing docstring * Fixing docstring --- network/nxos/nxos_vlan.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/network/nxos/nxos_vlan.py b/network/nxos/nxos_vlan.py index c7071c10918..cb06bd84fbc 100644 --- a/network/nxos/nxos_vlan.py +++ b/network/nxos/nxos_vlan.py @@ -456,6 +456,15 @@ def execute_config_command(commands, module): clie = get_exception() module.fail_json(msg='Error sending CLI commands', error=str(clie), commands=commands) + except AttributeError: + try: + commands.insert(0, 'configure') + module.cli.add_commands(commands, output='config') + module.cli.run_commands() + except ShellError: + clie = get_exception() + module.fail_json(msg='Error sending CLI commands', + error=str(clie), commands=commands) def get_cli_body_ssh(command, response, module): @@ -500,7 +509,7 @@ def execute_show(cmds, module, command_type=None): module.cli.add_commands(cmds, output=command_type) response = module.cli.run_commands() else: - module.cli.add_commands(cmds, output=command_type) + module.cli.add_commands(cmds, raw=True) response = module.cli.run_commands() except ShellError: clie = get_exception() @@ -564,7 +573,6 @@ def main(): proposed_vlans_list = numerical_sort(vlan_range_to_list( vlan_id or vlan_range)) existing_vlans_list = numerical_sort(get_list_of_vlans(module)) - commands = [] existing = None @@ -599,7 +607,7 @@ def main(): end_state_vlans_list = existing_vlans_list if commands: - if existing: + if existing.get('mapped_vni'): if (existing.get('mapped_vni') != proposed.get('mapped_vni') and existing.get('mapped_vni') != '0' and proposed.get('mapped_vni') != 'default'): commands.insert(1, 'no vn-segment') @@ -610,6 +618,8 @@ def main(): execute_config_command(commands, module) changed = True end_state_vlans_list = numerical_sort(get_list_of_vlans(module)) + if 'configure' in commands: + commands.pop(0) if vlan_id: end_state = get_vlan(vlan_id, module)