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 /plugins/modules/vyos_lldp_global.py | |
| parent | 6276e9afd7b2aba709733a19bf5ce0221d42070d (diff) | |
| download | rest.vyos-92b7323c353f473c9d5bdb7930e9490a5dafcd41.tar.gz rest.vyos-92b7323c353f473c9d5bdb7930e9490a5dafcd41.zip | |
lldp_global
Diffstat (limited to 'plugins/modules/vyos_lldp_global.py')
| -rw-r--r-- | plugins/modules/vyos_lldp_global.py | 32 |
1 files changed, 25 insertions, 7 deletions
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 |
