1#!/usr/local/bin/python3.8
2# -*- coding: utf-8 -*-
3
4# (c) 2017, Ansible by Red Hat, inc
5# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7from __future__ import absolute_import, division, print_function
8
9__metaclass__ = type
10
11
12DOCUMENTATION = """
13module: nxos_lldp
14author: Ganesh Nalawade (@ganeshrn)
15short_description: (deprecated, removed after 2022-06-01) Manage LLDP
16  configuration on Cisco NXOS network devices.
17description:
18- This module provides declarative management of LLDP service on Cisco NXOS network
19  devices.
20version_added: 1.0.0
21deprecated:
22  alternative: nxos_lldp_global
23  why: Updated modules released with more functionality
24  removed_at_date: '2022-06-01'
25notes:
26- Tested against NXOSv 7.0(3)I5(1).
27- Unsupported for Cisco MDS
28options:
29  state:
30    description:
31    - State of the LLDP configuration. If value is I(present) lldp will be enabled
32      else if it is I(absent) it will be disabled.
33    default: present
34    choices:
35    - present
36    - absent
37    - enabled
38    - disabled
39    type: str
40extends_documentation_fragment:
41- cisco.nxos.nxos
42
43
44"""
45
46EXAMPLES = """
47- name: Enable LLDP service
48  cisco.nxos.nxos_lldp:
49    state: present
50
51- name: Disable LLDP service
52  cisco.nxos.nxos_lldp:
53    state: absent
54"""
55
56RETURN = """
57commands:
58  description: The list of configuration mode commands to send to the device
59  returned: always, except for the platforms that use Netconf transport to manage the device.
60  type: list
61  sample:
62    - feature lldp
63"""
64from ansible.module_utils.basic import AnsibleModule
65from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import (
66    get_config,
67    load_config,
68)
69from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import (
70    nxos_argument_spec,
71)
72
73
74def has_lldp(module):
75    output = get_config(module, ["| section lldp"])
76    is_lldp_enable = False
77    if output and "feature lldp" in output:
78        is_lldp_enable = True
79
80    return is_lldp_enable
81
82
83def main():
84    """ main entry point for module execution
85    """
86    argument_spec = dict(
87        state=dict(
88            default="present",
89            choices=["present", "absent", "enabled", "disabled"],
90        )
91    )
92
93    argument_spec.update(nxos_argument_spec)
94
95    module = AnsibleModule(
96        argument_spec=argument_spec, supports_check_mode=True
97    )
98
99    warnings = list()
100
101    result = {"changed": False}
102
103    if warnings:
104        result["warnings"] = warnings
105
106    HAS_LLDP = has_lldp(module)
107
108    commands = []
109
110    if module.params["state"] == "absent" and HAS_LLDP:
111        commands.append("no feature lldp")
112    elif module.params["state"] == "present" and not HAS_LLDP:
113        commands.append("feature lldp")
114
115    result["commands"] = commands
116
117    if commands:
118        # On N35 A8 images, some features return a yes/no prompt
119        # on enablement or disablement. Bypass using terminal dont-ask
120        commands.insert(0, "terminal dont-ask")
121        if not module.check_mode:
122            load_config(module, commands)
123
124        result["changed"] = True
125
126    module.exit_json(**result)
127
128
129if __name__ == "__main__":
130    main()
131