Update argspec to normalize across platforms (#59596)

Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>
pull/58954/head
Nilashish Chakraborty 5 years ago committed by GitHub
parent cf9999692a
commit 3da4c0dd3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -43,7 +43,12 @@ class LacpArgs(object): # pylint: disable=R0903
'system': {
'options': {
'mac': {
'type': 'str'
'type': 'dict',
'options': {
'address': {
'type': 'str'
}
}
},
'priority': {
'type': 'int'

@ -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

@ -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

@ -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

@ -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
# }
# }

@ -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

@ -10,7 +10,8 @@
config:
system:
priority: 11
mac: 00c1.4c00.bd15
mac:
address: 00c1.4c00.bd15
state: merged
register: result

@ -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:

@ -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

@ -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"

Loading…
Cancel
Save