feat: interface enable/description config + fix SNMP auto-fix and detection
- set_interface(): support enabled (shutdown/no shutdown) and description - get_snmp_config(): detect "no community entry exists" as not-configured instead of reporting running=True with no community - _action_fix_snmp(): use config-mode prompt for in-config commands (previously timed out waiting for the exec prompt) and return its result
This commit is contained in:
@@ -1584,12 +1584,20 @@ class TPLinkJetstreamDriver(SwitchDriver):
|
||||
self._save_config()
|
||||
|
||||
def set_interface(self, interface: str, config: InterfaceConfigDict) -> None:
|
||||
"""Configure a switch interface (mode, VLAN membership)."""
|
||||
"""Configure a switch interface (mode, VLAN membership, admin state)."""
|
||||
mode = config.get("mode")
|
||||
iface = self._to_cli_interface(interface)
|
||||
self._enter_config_mode()
|
||||
try:
|
||||
lines: List[str] = [f"interface {iface}"]
|
||||
if "enabled" in config:
|
||||
lines.append(" no shutdown" if config["enabled"] else " shutdown")
|
||||
if "description" in config:
|
||||
desc = config["description"]
|
||||
if desc:
|
||||
lines.append(f" description {desc}")
|
||||
else:
|
||||
lines.append(" no description")
|
||||
if mode == "trunk":
|
||||
for vid in config.get("trunk_vlans", []):
|
||||
lines.append(f" switchport general allowed vlan {vid} tagged")
|
||||
@@ -1755,8 +1763,8 @@ class TPLinkJetstreamDriver(SwitchDriver):
|
||||
return None
|
||||
|
||||
out = self._send_command("show snmp community")
|
||||
if not out or "disabled" in out.lower():
|
||||
return None
|
||||
if not out or "disabled" in out.lower() or "no community entry exists" in out.lower():
|
||||
return SNMPConfigDict(running=False, community="", port=161, version="2c")
|
||||
|
||||
# Parse first read-only community
|
||||
community = "public"
|
||||
@@ -1822,17 +1830,26 @@ class TPLinkJetstreamDriver(SwitchDriver):
|
||||
lines.append("[detect] Could not auto-detect management VLAN.")
|
||||
|
||||
# Configure SNMP in config mode
|
||||
conf_prompt = self._conf_prompt()
|
||||
self._enter_config_mode()
|
||||
self._send_command("snmp-server")
|
||||
self.device.send_command("snmp-server", expect_string=conf_prompt, read_timeout=self.timeout)
|
||||
lines.append("[config] SNMP enabled.")
|
||||
|
||||
# Community: TP-Link syntax is snmp-server community "<name>" read-only "<view>"
|
||||
self._send_command('snmp-server community "public" read-only "viewDefault"')
|
||||
self.device.send_command(
|
||||
'snmp-server community "public" read-only "viewDefault"',
|
||||
expect_string=conf_prompt,
|
||||
read_timeout=self.timeout,
|
||||
)
|
||||
lines.append("[config] Community 'public' (read-only, viewDefault) configured.")
|
||||
|
||||
# Set source-interface so responses come from the management VLAN
|
||||
if mgmt_vlan:
|
||||
self._send_command(f"snmp-server source-interface vlan {mgmt_vlan}")
|
||||
self.device.send_command(
|
||||
f"snmp-server source-interface vlan {mgmt_vlan}",
|
||||
expect_string=conf_prompt,
|
||||
read_timeout=self.timeout,
|
||||
)
|
||||
lines.append(f"[config] Source-interface set to vlan {mgmt_vlan}.")
|
||||
|
||||
# Exit config mode and save
|
||||
@@ -1848,6 +1865,8 @@ class TPLinkJetstreamDriver(SwitchDriver):
|
||||
else:
|
||||
lines.append(f"[warn] Verification failed: {out[:100]}")
|
||||
|
||||
return {"success": success, "output": "\n".join(lines)}
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Health metrics (SNMP)
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user