Update argspec to normalize across platforms (#59596)

Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>
This commit is contained in:
Nilashish Chakraborty 2019-07-26 12:30:26 +05:30 committed by GitHub
parent cf9999692a
commit 3da4c0dd3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 77 additions and 21 deletions

View file

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

View file

@ -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.iosxr.facts.facts import Facts
from ansible.module_utils.network.common.utils import dict_diff from ansible.module_utils.network.common.utils import dict_diff
from ansible.module_utils.six import iteritems 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): class Lacp(ConfigBase):
@ -147,9 +149,8 @@ class Lacp(ConfigBase):
updates = dict_diff(have, want) updates = dict_diff(have, want)
if updates: if updates:
for key, value in iteritems(updates['system']): for key, value in iteritems(flatten_dict(remove_empties(updates['system']))):
if value: commands.append('lacp system {0} {1}'.format(key.replace('address', 'mac'), value))
commands.append('lacp system {0} {1}'.format(key, value))
return commands return commands
@ -163,7 +164,7 @@ class Lacp(ConfigBase):
""" """
commands = [] 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)) commands.append('no lacp system {0}'.format(x))
return commands return commands

View file

@ -77,6 +77,6 @@ class LacpFacts(object):
system_priority = utils.parse_conf_arg(conf, 'priority') system_priority = utils.parse_conf_arg(conf, 'priority')
config['system']['priority'] = int(system_priority) if system_priority else system_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 return config

View file

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

View file

@ -59,9 +59,14 @@ options:
- Refer to vendor documentation for valid values. - Refer to vendor documentation for valid values.
type: int type: int
mac: mac:
type: dict
description: description:
- The system ID to use in LACP negotiations. - The system MAC related configuration for LACP.
type: str suboptions:
address:
description:
- The system ID to use in LACP negotiations.
type: str
state: state:
description: description:
- The state the configuration should be left in. - The state the configuration should be left in.
@ -92,7 +97,8 @@ EXAMPLES = """
config: config:
system: system:
priority: 10 priority: 10
mac: 00c1.4c00.bd15 mac:
address: 00c1.4c00.bd15
state: merged state: merged
# #
@ -112,7 +118,9 @@ EXAMPLES = """
# #
# "after": { # "after": {
# "system": { # "system": {
# "mac": "00c1.4c00.bd15", # "mac": {
# "address": "00c1.4c00.bd15"
# },
# "priority": 10 # "priority": 10
# } # }
# } # }
@ -156,7 +164,9 @@ EXAMPLES = """
# ----------------------- # -----------------------
# "before": { # "before": {
# "system": { # "system": {
# "mac": "00c1.4c00.bd15", # "mac": {
# "address": "00c1.4c00.bd15"
# },
# "priority": 10 # "priority": 10
# } # }
# } # }
@ -211,7 +221,9 @@ EXAMPLES = """
# ----------------------- # -----------------------
# "before": { # "before": {
# "system": { # "system": {
# "mac": "00c1.4c00.bd15", # "mac": {
# "address": "00c1.4c00.bd15"
# },
# "priority": 11 # "priority": 11
# } # }
# } # }

View file

@ -7,7 +7,7 @@
- include_tasks: _populate.yaml - include_tasks: _populate.yaml
- block: - block:
- name: Delete attributes of given interfaces - name: Delete LACP attributes
iosxr_lacp: &deleted iosxr_lacp: &deleted
state: deleted state: deleted
register: result register: result

View file

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

View file

@ -7,7 +7,7 @@
- include_tasks: _populate.yaml - include_tasks: _populate.yaml
- block: - block:
- name: Replace device configurations of listed interfaces with provided configurations - name: Replace LACP configuration with provided configurations
iosxr_lacp: &replaced iosxr_lacp: &replaced
config: config:
system: system:

View file

@ -10,7 +10,8 @@
config: config:
system: system:
priority: 15 priority: 15
mac: 00c1.4c00.bd16 mac:
address: 00c1.4c00.bd16
state: merged state: merged
register: base_config register: base_config
@ -27,7 +28,8 @@
config: config:
system: system:
priority: 10 priority: 10
mac: 00c1.4c00.bd10 mac:
address: 00c1.4c00.bd10
state: merged state: merged
register: result register: result

View file

@ -9,12 +9,14 @@ merged:
after: after:
system: system:
priority: 11 priority: 11
mac: "00c1.4c00.bd15" mac:
address: "00c1.4c00.bd15"
populate: populate:
system: system:
priority: 12 priority: 12
mac: "00c1.4c00.bd16" mac:
address: "00c1.4c00.bd16"
replaced: replaced:
commands: commands:
@ -36,5 +38,6 @@ round_trip:
after: after:
system: system:
priority: 10 priority: 10
mac: "00c1.4c00.bd10" mac:
address: "00c1.4c00.bd10"