From e375b4c61c60d3aae27c4ef6ce7e58d8afb53312 Mon Sep 17 00:00:00 2001 From: GGabriele Date: Tue, 13 Sep 2016 22:59:44 +0200 Subject: [PATCH] Fixing nxos_feature --- .../modules/network/nxos/nxos_feature.py | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/ansible/modules/network/nxos/nxos_feature.py b/lib/ansible/modules/network/nxos/nxos_feature.py index 04b7a6ce64e..bcf03003644 100644 --- a/lib/ansible/modules/network/nxos/nxos_feature.py +++ b/lib/ansible/modules/network/nxos/nxos_feature.py @@ -835,34 +835,39 @@ def apply_key_map(key_map, table): def get_available_features(feature, module): available_features = {} + feature_regex = '(?P\S+)\s+\d+\s+(?P.*)' command = 'show feature' - body = execute_show_command(command, module) - try: - body = body[0]['TABLE_cfcFeatureCtrlTable']['ROW_cfcFeatureCtrlTable'] - except (TypeError, IndexError): - return available_features + body = execute_show_command(command, module, command_type='cli_show_ascii') + split_body = body[0].splitlines() - for each_feature in body: - feature = each_feature['cfcFeatureCtrlName2'] - state = each_feature['cfcFeatureCtrlOpStatus2'] + for line in split_body: + try: + match_feature = re.match(feature_regex, line, re.DOTALL) + feature_group = match_feature.groupdict() + feature = feature_group['feature'] + state = feature_group['state'] + except AttributeError: + feature = '' + state = '' - if 'enabled' in state: - state = 'enabled' + if feature and state: + if 'enabled' in state: + state = 'enabled' - if feature not in available_features.keys(): - available_features[feature] = state - else: - if (available_features[feature] == 'disabled' and - state == 'enabled'): + if feature not in available_features.keys(): available_features[feature] = state + else: + if (available_features[feature] == 'disabled' and + state == 'enabled'): + available_features[feature] = state return available_features + def get_commands(proposed, existing, state, module): feature = validate_feature(module, mode='config') - commands = [] feature_check = proposed == existing if not feature_check: