From b9e80b611715a739221f59ccb95a67fb09c5359a Mon Sep 17 00:00:00 2001 From: Nathaniel Case Date: Mon, 7 Aug 2017 10:57:45 -0400 Subject: [PATCH] nxos_vrf_interface cleanup (#27642) * Update RETURN, results, & execute_show_command --- .../network/nxos/nxos_vrf_interface.py | 63 ++++--------------- test/sanity/pep8/legacy-files.txt | 1 - 2 files changed, 12 insertions(+), 52 deletions(-) diff --git a/lib/ansible/modules/network/nxos/nxos_vrf_interface.py b/lib/ansible/modules/network/nxos/nxos_vrf_interface.py index a7c9b4e7d3..f6a3973ada 100644 --- a/lib/ansible/modules/network/nxos/nxos_vrf_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_vrf_interface.py @@ -61,43 +61,21 @@ EXAMPLES = ''' nxos_vrf_interface: vrf: ntc interface: Ethernet1/1 - host: 68.170.147.165 state: present - name: Ensure ntc VRF does not exist on Eth1/1 nxos_vrf_interface: vrf: ntc interface: Ethernet1/1 - host: 68.170.147.165 state: absent ''' RETURN = ''' -proposed: - description: k/v pairs of parameters passed into module - returned: always - type: dict - sample: {"interface": "loopback16", "vrf": "ntc"} -existing: - description: k/v pairs of existing vrf on the interface - returned: always - type: dict - sample: {"interface": "loopback16", "vrf": ""} -end_state: - description: k/v pairs of vrf after module execution - returned: always - type: dict - sample: {"interface": "loopback16", "vrf": "ntc"} -updates: +commands: description: commands sent to the device returned: always type: list sample: ["interface loopback16", "vrf member ntc"] -changed: - description: check to see if a change was made on the device - returned: always - type: boolean - sample: true ''' import re @@ -106,10 +84,7 @@ from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -WARNINGS = [] - - -def execute_show_command(command, module, command_type='cli_show'): +def execute_show_command(command, module): if 'show run' not in command: output = 'json' else: @@ -118,8 +93,7 @@ def execute_show_command(command, module, command_type='cli_show'): 'command': command, 'output': output, }] - body = run_commands(module, cmds) - return body + return run_commands(module, cmds)[0] def get_interface_type(interface): @@ -145,7 +119,7 @@ def get_interface_mode(interface, intf_type, module): mode = 'unknown' if intf_type in ['ethernet', 'portchannel']: - body = execute_show_command(command, module)[0] + body = execute_show_command(command, module) interface_table = body['TABLE_interface']['ROW_interface'] mode = str(interface_table.get('eth_mode', 'layer3')) if mode == 'access' or mode == 'trunk': @@ -158,7 +132,7 @@ def get_interface_mode(interface, intf_type, module): def get_vrf_list(module): command = 'show vrf all' vrf_list = [] - body = execute_show_command(command, module)[0] + body = execute_show_command(command, module) try: vrf_table = body['TABLE_vrf']['ROW_vrf'] @@ -179,8 +153,7 @@ def get_interface_info(interface, module): vrf_regex = ".*vrf\s+member\s+(?P\S+).*" try: - body = execute_show_command(command, module, - command_type='cli_show_ascii')[0] + body = execute_show_command(command, module) match_vrf = re.match(vrf_regex, body, re.DOTALL) group_vrf = match_vrf.groupdict() vrf = group_vrf["vrf"] @@ -194,8 +167,7 @@ def is_default(interface, module): command = 'show run interface {0}'.format(interface) try: - body = execute_show_command(command, module, - command_type='cli_show_ascii')[0] + body = execute_show_command(command, module) raw_list = body.split('\n') if raw_list[-1].startswith('interface'): return True @@ -210,20 +182,16 @@ def main(): argument_spec = dict( vrf=dict(required=True), interface=dict(type='str', required=True), - state=dict(default='present', choices=['present', 'absent'], - required=False), - include_defaults=dict(default=False), - config=dict(), - save=dict(type='bool', default=False) + state=dict(default='present', choices=['present', 'absent'], required=False), ) argument_spec.update(nxos_argument_spec) - module = AnsibleModule(argument_spec=argument_spec, - supports_check_mode=True) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) warnings = list() check_args(module, warnings) + results = {'changed': False, 'commands': [], 'warnings': warnings} vrf = module.params['vrf'] interface = module.params['interface'].lower() @@ -231,7 +199,7 @@ def main(): current_vrfs = get_vrf_list(module) if vrf not in current_vrfs: - WARNINGS.append("The VRF is not present/active on the device. " + warnings.append("The VRF is not present/active on the device. " "Use nxos_vrf to fix this.") intf_type = get_interface_type(interface) @@ -287,16 +255,9 @@ def main(): if 'configure' in commands: commands.pop(0) - results = {} - results['proposed'] = proposed - results['existing'] = existing - results['end_state'] = end_state - results['updates'] = commands + results['commands'] = commands results['changed'] = changed - if WARNINGS: - results['warnings'] = WARNINGS - module.exit_json(**results) diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index abd3e5e363..085a07b9fc 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -344,7 +344,6 @@ lib/ansible/modules/network/nxos/nxos_udld.py lib/ansible/modules/network/nxos/nxos_udld_interface.py lib/ansible/modules/network/nxos/nxos_user.py lib/ansible/modules/network/nxos/nxos_vrf.py -lib/ansible/modules/network/nxos/nxos_vrf_interface.py lib/ansible/modules/network/nxos/nxos_vtp_domain.py lib/ansible/modules/network/nxos/nxos_vtp_password.py lib/ansible/modules/network/nxos/nxos_vtp_version.py