diff options
| author | omnom62 <omnom62@outlook.com> | 2026-05-19 05:35:04 +1000 |
|---|---|---|
| committer | omnom62 <omnom62@outlook.com> | 2026-05-19 05:35:04 +1000 |
| commit | 92b7323c353f473c9d5bdb7930e9490a5dafcd41 (patch) | |
| tree | 7ddb25693340b9f57090b73147daef0560a54dbb | |
| parent | 6276e9afd7b2aba709733a19bf5ce0221d42070d (diff) | |
| download | rest.vyos-92b7323c353f473c9d5bdb7930e9490a5dafcd41.tar.gz rest.vyos-92b7323c353f473c9d5bdb7930e9490a5dafcd41.zip | |
lldp_global
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | docs/vyos.rest.vyos_info_module.rst | 222 | ||||
| -rw-r--r-- | plugins/modules/vyos_info.py | 115 | ||||
| -rw-r--r-- | plugins/modules/vyos_lldp_global.py | 32 |
4 files changed, 25 insertions, 345 deletions
@@ -23,7 +23,6 @@ Name | Description [vyos.rest.vyos_generate](https://github.com/vyos/vyos.rest/blob/main/docs/vyos.rest.vyos_generate_module.rst)|Execute generate commands on a VyOS device via REST API. [vyos.rest.vyos_hostname](https://github.com/vyos/vyos.rest/blob/main/docs/vyos.rest.vyos_hostname_module.rst)|Manage the system hostname on a VyOS device via the REST API. [vyos.rest.vyos_image](https://github.com/vyos/vyos.rest/blob/main/docs/vyos.rest.vyos_image_module.rst)|Manage VyOS system images via the REST API. -[vyos.rest.vyos_info](https://github.com/vyos/vyos.rest/blob/main/docs/vyos.rest.vyos_info_module.rst)|Retrieve system information from a VyOS device via the REST API. [vyos.rest.vyos_interfaces](https://github.com/vyos/vyos.rest/blob/main/docs/vyos.rest.vyos_interfaces_module.rst)|Manage interface attributes on a VyOS device via the REST API. [vyos.rest.vyos_l3_interfaces](https://github.com/vyos/vyos.rest/blob/main/docs/vyos.rest.vyos_l3_interfaces_module.rst)|Manage L3 interface attributes on VyOS via the REST API. [vyos.rest.vyos_lag_interfaces](https://github.com/vyos/vyos.rest/blob/main/docs/vyos.rest.vyos_lag_interfaces_module.rst)|LAG/bonding interfaces resource module via REST API. diff --git a/docs/vyos.rest.vyos_info_module.rst b/docs/vyos.rest.vyos_info_module.rst deleted file mode 100644 index 60cf87d..0000000 --- a/docs/vyos.rest.vyos_info_module.rst +++ /dev/null @@ -1,222 +0,0 @@ -.. _vyos.rest.vyos_info_module: - - -******************* -vyos.rest.vyos_info -******************* - -**Retrieve system information from a VyOS device via the REST API.** - - -Version added: 1.0.0 - -.. contents:: - :local: - :depth: 1 - - -Synopsis --------- -- Queries the public ``/info`` endpoint (HTTP GET) which requires no authentication and returns the VyOS version, hostname, and a welcome banner. - - - -Requirements ------------- -The below requirements are needed on the host that executes this module. - -- VyOS 1.3+ - - -Parameters ----------- - -.. raw:: html - - <table border=0 cellpadding=0 class="documentation-table"> - <tr> - <th colspan="1">Parameter</th> - <th>Choices/<font color="blue">Defaults</font></th> - <th width="100%">Comments</th> - </tr> - <tr> - <td colspan="1"> - <div class="ansibleOptionAnchor" id="parameter-"></div> - <b>api_key</b> - <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> - <div style="font-size: small"> - <span style="color: purple">string</span> - </div> - </td> - <td> - </td> - <td> - <div>API key. Not required for this module (the /info endpoint is public) but kept in the spec for consistency with other modules in this collection.</div> - </td> - </tr> - <tr> - <td colspan="1"> - <div class="ansibleOptionAnchor" id="parameter-"></div> - <b>hostname</b> - <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> - <div style="font-size: small"> - <span style="color: purple">string</span> - / <span style="color: red">required</span> - </div> - </td> - <td> - </td> - <td> - <div>IP address or FQDN of the VyOS device.</div> - </td> - </tr> - <tr> - <td colspan="1"> - <div class="ansibleOptionAnchor" id="parameter-"></div> - <b>port</b> - <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> - <div style="font-size: small"> - <span style="color: purple">integer</span> - </div> - </td> - <td> - <b>Default:</b><br/><div style="color: blue">443</div> - </td> - <td> - <div>HTTPS port for the REST API.</div> - </td> - </tr> - <tr> - <td colspan="1"> - <div class="ansibleOptionAnchor" id="parameter-"></div> - <b>timeout</b> - <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> - <div style="font-size: small"> - <span style="color: purple">integer</span> - </div> - </td> - <td> - <b>Default:</b><br/><div style="color: blue">10</div> - </td> - <td> - <div>Request timeout in seconds.</div> - </td> - </tr> - <tr> - <td colspan="1"> - <div class="ansibleOptionAnchor" id="parameter-"></div> - <b>verify_ssl</b> - <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> - <div style="font-size: small"> - <span style="color: purple">boolean</span> - </div> - </td> - <td> - <ul style="margin: 0; padding: 0"><b>Choices:</b> - <li><div style="color: blue"><b>no</b> ←</div></li> - <li>yes</li> - </ul> - </td> - <td> - <div>Validate the device's TLS certificate.</div> - </td> - </tr> - </table> - <br/> - - - - - - - -Return Values -------------- -Common return values are documented `here <https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#common-return-values>`_, the following are the fields unique to this module: - -.. raw:: html - - <table border=0 cellpadding=0 class="documentation-table"> - <tr> - <th colspan="1">Key</th> - <th>Returned</th> - <th width="100%">Description</th> - </tr> - <tr> - <td colspan="1"> - <div class="ansibleOptionAnchor" id="return-"></div> - <b>banner</b> - <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> - <div style="font-size: small"> - <span style="color: purple">string</span> - </div> - </td> - <td>success</td> - <td> - <div>Welcome banner text.</div> - <br/> - <div style="font-size: smaller"><b>Sample:</b></div> - <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">Welcome to VyOS</div> - </td> - </tr> - <tr> - <td colspan="1"> - <div class="ansibleOptionAnchor" id="return-"></div> - <b>hostname</b> - <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> - <div style="font-size: small"> - <span style="color: purple">string</span> - </div> - </td> - <td>success</td> - <td> - <div>System hostname.</div> - <br/> - <div style="font-size: smaller"><b>Sample:</b></div> - <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">vyos-router</div> - </td> - </tr> - <tr> - <td colspan="1"> - <div class="ansibleOptionAnchor" id="return-"></div> - <b>info</b> - <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> - <div style="font-size: small"> - <span style="color: purple">dictionary</span> - </div> - </td> - <td>success</td> - <td> - <div>Full info dict as returned by the device.</div> - <br/> - </td> - </tr> - <tr> - <td colspan="1"> - <div class="ansibleOptionAnchor" id="return-"></div> - <b>version</b> - <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> - <div style="font-size: small"> - <span style="color: purple">string</span> - </div> - </td> - <td>success</td> - <td> - <div>VyOS version string.</div> - <br/> - <div style="font-size: smaller"><b>Sample:</b></div> - <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">1.4-rolling-202401010000</div> - </td> - </tr> - </table> - <br/><br/> - - -Status ------- - - -Authors -~~~~~~~ - -- VyOS Community (@vyos) diff --git a/plugins/modules/vyos_info.py b/plugins/modules/vyos_info.py deleted file mode 100644 index 8946868..0000000 --- a/plugins/modules/vyos_info.py +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -from __future__ import absolute_import, division, print_function - - -__metaclass__ = type - -DOCUMENTATION = r""" ---- -module: vyos_info -short_description: Retrieve system information from a VyOS device via the REST API. -description: - - Queries the public C(/info) endpoint (HTTP GET) which requires no - authentication and returns the VyOS version, hostname, and a welcome banner. -version_added: "1.0.0" -author: - - VyOS Community (@vyos) -options: - hostname: - description: IP address or FQDN of the VyOS device. - type: str - required: true - port: - description: HTTPS port for the REST API. - type: int - default: 443 - api_key: - description: > - API key. Not required for this module (the /info endpoint is public) - but kept in the spec for consistency with other modules in this collection. - type: str - no_log: true - timeout: - description: Request timeout in seconds. - type: int - default: 10 - verify_ssl: - description: Validate the device's TLS certificate. - type: bool - default: false -requirements: - - VyOS 1.3+ -examples: | - - name: Get VyOS system info - vyos.rest.vyos_info: - hostname: 192.168.1.1 - register: sys_info - - - name: Print VyOS version - ansible.builtin.debug: - msg: "Running VyOS {{ sys_info.version }}" -""" - -RETURN = r""" -version: - description: VyOS version string. - returned: success - type: str - sample: "1.4-rolling-202401010000" -hostname: - description: System hostname. - returned: success - type: str - sample: vyos-router -banner: - description: Welcome banner text. - returned: success - type: str - sample: "Welcome to VyOS" -info: - description: Full info dict as returned by the device. - returned: success - type: dict -""" - -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.vyos.rest.plugins.module_utils.vyos_rest import ( - VYOS_REST_CONNECTION_ARGSPEC, - VyOSRestClient, - VyOSRestError, -) - - -def main(): - argument_spec = dict() - argument_spec.update(VYOS_REST_CONNECTION_ARGSPEC) - # api_key not strictly required for /info - argument_spec["api_key"]["required"] = False - argument_spec["api_key"]["default"] = "" - - module = AnsibleModule( - argument_spec=argument_spec, - supports_check_mode=True, - ) - - client = VyOSRestClient(module) - try: - result = client.info() - except VyOSRestError as exc: - module.fail_json(msg=str(exc)) - - data = result.get("data", {}) - module.exit_json( - changed=False, - version=data.get("version", ""), - hostname=data.get("hostname", ""), - banner=data.get("banner", ""), - info=data, - ) - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/vyos_lldp_global.py b/plugins/modules/vyos_lldp_global.py index 0a9618d..1eb10bd 100644 --- a/plugins/modules/vyos_lldp_global.py +++ b/plugins/modules/vyos_lldp_global.py @@ -74,35 +74,53 @@ def _get(vyos): if "management-address" in raw: v = raw["management-address"] result["addresses"] = ( - list(v.keys()) if isinstance(v, dict) else ([v] if isinstance(v, str) else list(v)) + sorted(list(v.keys())) + if isinstance(v, dict) + else ([v] if isinstance(v, str) else sorted(list(v))) ) if "snmp" in raw: result["snmp"] = "enable" if "legacy-protocols" in raw: v = raw["legacy-protocols"] result["legacy_protocols"] = ( - list(v.keys()) if isinstance(v, dict) else ([v] if isinstance(v, str) else list(v)) + sorted(list(v.keys())) + if isinstance(v, dict) + else ([v] if isinstance(v, str) else sorted(list(v))) ) return result def _build(want, have, state): cmds = [] + if state in ("replaced", "deleted") and have: cmds.append(("delete", _BASE)) if state == "deleted": return cmds - if want.get("enable") is not False: + + # enable — only set if not already enabled + if want.get("enable") is not False and not have.get("enable"): cmds.append(("set", _BASE)) + + # addresses — only add missing ones + have_addrs = set(have.get("addresses") or []) for addr in want.get("addresses") or []: - cmds.append(("set", _BASE + ["management-address", addr])) + if addr not in have_addrs: + cmds.append(("set", _BASE + ["management-address", addr])) + + # snmp if want.get("snmp"): - if want["snmp"] == "disable": + if want["snmp"] == "disable" and have.get("snmp"): cmds.append(("delete", _BASE + ["snmp"])) - else: + elif want["snmp"] != "disable" and not have.get("snmp"): cmds.append(("set", _BASE + ["snmp"])) + + # legacy_protocols — only add missing ones + have_protos = set(have.get("legacy_protocols") or []) for p in want.get("legacy_protocols") or []: - cmds.append(("set", _BASE + ["legacy-protocols", p])) + if p not in have_protos: + cmds.append(("set", _BASE + ["legacy-protocols", p])) + return cmds |
