diff --git a/lib/ansible/module_utils/network/iosxr/argspec/lacp/lacp.py b/lib/ansible/module_utils/network/iosxr/argspec/lacp/lacp.py index 4eb731f93ae..57d8090d7cd 100644 --- a/lib/ansible/module_utils/network/iosxr/argspec/lacp/lacp.py +++ b/lib/ansible/module_utils/network/iosxr/argspec/lacp/lacp.py @@ -43,7 +43,12 @@ class LacpArgs(object): # pylint: disable=R0903 'system': { 'options': { 'mac': { - 'type': 'str' + 'type': 'dict', + 'options': { + 'address': { + 'type': 'str' + } + } }, 'priority': { 'type': 'int' diff --git a/lib/ansible/module_utils/network/iosxr/config/lacp/lacp.py b/lib/ansible/module_utils/network/iosxr/config/lacp/lacp.py index bba7c4da785..7c32890a855 100644 --- a/lib/ansible/module_utils/network/iosxr/config/lacp/lacp.py +++ b/lib/ansible/module_utils/network/iosxr/config/lacp/lacp.py @@ -21,7 +21,9 @@ from ansible.module_utils.network.common.utils import to_list from ansible.module_utils.network.iosxr.facts.facts import Facts from ansible.module_utils.network.common.utils import dict_diff from ansible.module_utils.six import iteritems -from ansible.module_utils.network.common import utils +from ansible.module_utils.network.common.utils import remove_empties +from ansible.module_utils.network.iosxr. \ + utils.utils import flatten_dict class Lacp(ConfigBase): @@ -147,9 +149,8 @@ class Lacp(ConfigBase): updates = dict_diff(have, want) if updates: - for key, value in iteritems(updates['system']): - if value: - commands.append('lacp system {0} {1}'.format(key, value)) + for key, value in iteritems(flatten_dict(remove_empties(updates['system']))): + commands.append('lacp system {0} {1}'.format(key.replace('address', 'mac'), value)) return commands @@ -163,7 +164,7 @@ class Lacp(ConfigBase): """ commands = [] - for x in [k for k in have.get('system', {}) if k not in utils.remove_empties(want.get('system', {}))]: + for x in [k for k in have.get('system', {}) if k not in remove_empties(want.get('system', {}))]: commands.append('no lacp system {0}'.format(x)) return commands diff --git a/lib/ansible/module_utils/network/iosxr/facts/lacp/lacp.py b/lib/ansible/module_utils/network/iosxr/facts/lacp/lacp.py index 2d877680180..157251bd8b0 100644 --- a/lib/ansible/module_utils/network/iosxr/facts/lacp/lacp.py +++ b/lib/ansible/module_utils/network/iosxr/facts/lacp/lacp.py @@ -77,6 +77,6 @@ class LacpFacts(object): system_priority = utils.parse_conf_arg(conf, 'priority') config['system']['priority'] = int(system_priority) if system_priority else system_priority - config['system']['mac'] = utils.parse_conf_arg(conf, 'mac') + config['system']['mac']['address'] = utils.parse_conf_arg(conf, 'mac') return config diff --git a/lib/ansible/module_utils/network/iosxr/utils/__init__.py b/lib/ansible/module_utils/network/iosxr/utils/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/lib/ansible/module_utils/network/iosxr/utils/utils.py b/lib/ansible/module_utils/network/iosxr/utils/utils.py new file mode 100644 index 00000000000..5f132784f9d --- /dev/null +++ b/lib/ansible/module_utils/network/iosxr/utils/utils.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +# utils + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +from ansible.module_utils.six import iteritems + + +def search_obj_in_list(name, lst, key='name'): + for item in lst: + if item[key] == name: + return item + return None + + +def flatten_dict(x): + result = {} + if not isinstance(x, dict): + return result + + for key, value in iteritems(x): + if isinstance(value, dict): + result.update(flatten_dict(value)) + else: + result[key] = value + + return result diff --git a/lib/ansible/modules/network/iosxr/iosxr_lacp.py b/lib/ansible/modules/network/iosxr/iosxr_lacp.py index a15aab98b9f..386e841d84a 100644 --- a/lib/ansible/modules/network/iosxr/iosxr_lacp.py +++ b/lib/ansible/modules/network/iosxr/iosxr_lacp.py @@ -59,9 +59,14 @@ options: - Refer to vendor documentation for valid values. type: int mac: + type: dict description: - - The system ID to use in LACP negotiations. - type: str + - The system MAC related configuration for LACP. + suboptions: + address: + description: + - The system ID to use in LACP negotiations. + type: str state: description: - The state the configuration should be left in. @@ -92,7 +97,8 @@ EXAMPLES = """ config: system: priority: 10 - mac: 00c1.4c00.bd15 + mac: + address: 00c1.4c00.bd15 state: merged # @@ -112,7 +118,9 @@ EXAMPLES = """ # # "after": { # "system": { -# "mac": "00c1.4c00.bd15", +# "mac": { +# "address": "00c1.4c00.bd15" +# }, # "priority": 10 # } # } @@ -156,7 +164,9 @@ EXAMPLES = """ # ----------------------- # "before": { # "system": { -# "mac": "00c1.4c00.bd15", +# "mac": { +# "address": "00c1.4c00.bd15" +# }, # "priority": 10 # } # } @@ -211,7 +221,9 @@ EXAMPLES = """ # ----------------------- # "before": { # "system": { -# "mac": "00c1.4c00.bd15", +# "mac": { +# "address": "00c1.4c00.bd15" +# }, # "priority": 11 # } # } diff --git a/test/integration/targets/iosxr_lacp/tests/cli/deleted.yaml b/test/integration/targets/iosxr_lacp/tests/cli/deleted.yaml index 2d8e537d11f..72e584e270a 100644 --- a/test/integration/targets/iosxr_lacp/tests/cli/deleted.yaml +++ b/test/integration/targets/iosxr_lacp/tests/cli/deleted.yaml @@ -7,7 +7,7 @@ - include_tasks: _populate.yaml - block: - - name: Delete attributes of given interfaces + - name: Delete LACP attributes iosxr_lacp: &deleted state: deleted register: result diff --git a/test/integration/targets/iosxr_lacp/tests/cli/merged.yaml b/test/integration/targets/iosxr_lacp/tests/cli/merged.yaml index 2fbab882ef1..3d285c48304 100644 --- a/test/integration/targets/iosxr_lacp/tests/cli/merged.yaml +++ b/test/integration/targets/iosxr_lacp/tests/cli/merged.yaml @@ -10,7 +10,8 @@ config: system: priority: 11 - mac: 00c1.4c00.bd15 + mac: + address: 00c1.4c00.bd15 state: merged register: result diff --git a/test/integration/targets/iosxr_lacp/tests/cli/replaced.yaml b/test/integration/targets/iosxr_lacp/tests/cli/replaced.yaml index 9f147b8b1fe..8b1b0ca84b0 100644 --- a/test/integration/targets/iosxr_lacp/tests/cli/replaced.yaml +++ b/test/integration/targets/iosxr_lacp/tests/cli/replaced.yaml @@ -7,7 +7,7 @@ - include_tasks: _populate.yaml - block: - - name: Replace device configurations of listed interfaces with provided configurations + - name: Replace LACP configuration with provided configurations iosxr_lacp: &replaced config: system: diff --git a/test/integration/targets/iosxr_lacp/tests/cli/rtt.yaml b/test/integration/targets/iosxr_lacp/tests/cli/rtt.yaml index aa449ab6e66..3ba1f0be5f1 100644 --- a/test/integration/targets/iosxr_lacp/tests/cli/rtt.yaml +++ b/test/integration/targets/iosxr_lacp/tests/cli/rtt.yaml @@ -10,7 +10,8 @@ config: system: priority: 15 - mac: 00c1.4c00.bd16 + mac: + address: 00c1.4c00.bd16 state: merged register: base_config @@ -27,7 +28,8 @@ config: system: priority: 10 - mac: 00c1.4c00.bd10 + mac: + address: 00c1.4c00.bd10 state: merged register: result diff --git a/test/integration/targets/iosxr_lacp/vars/main.yaml b/test/integration/targets/iosxr_lacp/vars/main.yaml index 6c8e835ab43..8f445d17443 100644 --- a/test/integration/targets/iosxr_lacp/vars/main.yaml +++ b/test/integration/targets/iosxr_lacp/vars/main.yaml @@ -9,12 +9,14 @@ merged: after: system: priority: 11 - mac: "00c1.4c00.bd15" + mac: + address: "00c1.4c00.bd15" populate: system: priority: 12 - mac: "00c1.4c00.bd16" + mac: + address: "00c1.4c00.bd16" replaced: commands: @@ -36,5 +38,6 @@ round_trip: after: system: priority: 10 - mac: "00c1.4c00.bd10" + mac: + address: "00c1.4c00.bd10"