From 571968792052a6e720739b48ca67bdb5eb7919f0 Mon Sep 17 00:00:00 2001 From: Ricardo Carrillo Cruz Date: Thu, 13 Jul 2017 16:38:15 +0200 Subject: [PATCH] Split net_lldp into net_lldp (service) and net_lldp_interface (#26757) --- .../network/layer2/net_lldp_interface.py | 79 +++++++++++++++++++ .../modules/network/protocol/net_lldp.py | 26 ++---- .../plugins/action/net_lldp_interface.py | 27 +++++++ 3 files changed, 112 insertions(+), 20 deletions(-) create mode 100644 lib/ansible/modules/network/layer2/net_lldp_interface.py create mode 100644 lib/ansible/plugins/action/net_lldp_interface.py diff --git a/lib/ansible/modules/network/layer2/net_lldp_interface.py b/lib/ansible/modules/network/layer2/net_lldp_interface.py new file mode 100644 index 0000000000..004f927835 --- /dev/null +++ b/lib/ansible/modules/network/layer2/net_lldp_interface.py @@ -0,0 +1,79 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# (c) 2017, Ansible by Red Hat, inc +# +# This file is part of Ansible by Red Hat +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . +# + +ANSIBLE_METADATA = {'metadata_version': '1.0', + 'status': ['preview'], + 'supported_by': 'core'} + + +DOCUMENTATION = """ +--- +module: net_lldp_interface +version_added: "2.4" +author: "Ricardo Carrillo Cruz (@rcarrillocruz)" +short_description: Manage LLDP interfaces configuration on network devices +description: + - This module provides declarative management of LLDP interfaces configuration + on network devices. +options: + name: + description: Name of the interface LLDP should be configured on. + aggregate: + description: List of interfaces LLDP should be configured on. + purge: + description: + - Purge interfaces not defined in the interfaces parameter. + default: no + state: + description: + - State of the LLDP configuration. + default: present + choices: ['present', 'absent'] +""" + +EXAMPLES = """ +- name: Enable LLDP on specific interface + net_lldp_interface: + name: eth1 + state: present + +- name: Disable LLDP on specific interface + net_lldp_interface: + name: eth1 + state: absent + +- name: Enable LLDP on list of interfaces + net_lldp_interface: + aggregate: + - { name: eth1 } + - { name: eth2, state: absent } + state: present +""" + +RETURN = """ +commands: + description: The list of configuration mode commands to send to the device + returned: always, except for the platforms that use Netconf transport to manage the device. + type: list + sample: + - set service lldp eth1 + - set service lldp eth2 +""" diff --git a/lib/ansible/modules/network/protocol/net_lldp.py b/lib/ansible/modules/network/protocol/net_lldp.py index b12bd4bf1b..7f3f9e34a7 100644 --- a/lib/ansible/modules/network/protocol/net_lldp.py +++ b/lib/ansible/modules/network/protocol/net_lldp.py @@ -29,37 +29,24 @@ DOCUMENTATION = """ module: net_lldp version_added: "2.4" author: "Ricardo Carrillo Cruz (@rcarrillocruz)" -short_description: Manage LLDP configuration on network devices +short_description: Manage LLDP service configuration on network devices description: - - This module provides declarative management of LLDP configuration + - This module provides declarative management of LLDP service configuration on network devices. options: - interfaces: - description: List of interfaces LLDP should be configured on - purge: - description: - - Purge interfaces not defined in the interfaces parameter. - default: no state: description: - - State of the LLDP configuration. + - State of the LLDP service configuration. default: present choices: ['present', 'absent'] """ EXAMPLES = """ -- name: Enable LLDP globally +- name: Enable LLDP service net_lldp: state: present -- name: Enable LLDP on specific interfaces - net_lldp: - interfaces: - - eth1 - - eth2 - state: present - -- name: Disable LLDP globally +- name: Disable LLDP service net_lldp: state: lldp """ @@ -70,6 +57,5 @@ commands: returned: always, except for the platforms that use Netconf transport to manage the device. type: list sample: - - set service lldp eth1 - - set service lldp eth2 + - set service lldp """ diff --git a/lib/ansible/plugins/action/net_lldp_interface.py b/lib/ansible/plugins/action/net_lldp_interface.py new file mode 100644 index 0000000000..cad73f8a26 --- /dev/null +++ b/lib/ansible/plugins/action/net_lldp_interface.py @@ -0,0 +1,27 @@ +# (c) 2017, Ansible Inc, +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +from ansible.plugins.action.net_base import ActionModule as _ActionModule + + +class ActionModule(_ActionModule): + def run(self, tmp=None, task_vars=None): + result = super(ActionModule, self).run(tmp, task_vars) + + return result