fix: AOS-Switch REST API session cookie auth and VLAN PUT body

connect() never sent back the sessionId returned in the login response
body, so all writes (POST/PUT/DELETE) were silently rejected with
"Access is unauthorized" while reads worked fine. Also fix
_api_set_vlan to PUT the full VLAN object (AOS-Switch v3 rejects
partial PUT bodies with HTTP 400).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Christian Manivong
2026-06-10 01:38:02 +02:00
co-authored by Claude Sonnet 4.6
parent 22b83cf174
commit 76a1939af9
2 changed files with 12 additions and 2 deletions
+7
View File
@@ -127,6 +127,13 @@ class ProcurveApiClient:
raise ConnectAuthError( raise ConnectAuthError(
f"REST API login failed (HTTP {resp.status_code}) for {self.hostname}" f"REST API login failed (HTTP {resp.status_code}) for {self.hostname}"
) )
# AOS-Switch returns the session cookie in the JSON body rather than
# via Set-Cookie — it must be sent back as a Cookie header on every
# subsequent request, otherwise writes (POST/PUT/DELETE) are rejected
# with "Access is unauthorized" while reads still succeed.
cookie = resp.json().get("cookie")
if cookie:
self._session.headers.update({"Cookie": cookie})
logger.debug("REST API login OK for %s", self.hostname) logger.debug("REST API login OK for %s", self.hostname)
def setup(self, api_version: str, proto: str) -> None: def setup(self, api_version: str, proto: str) -> None:
+5 -2
View File
@@ -765,8 +765,11 @@ class ProcurveDriver(SwitchDriver):
resp = self._api.post("vlans", json=payload) resp = self._api.post("vlans", json=payload)
if not resp.ok: if not resp.ok:
if resp.status_code in (400, 409): if resp.status_code in (400, 409):
# VLAN already exists — update name via PUT # VLAN already exists — PUT requires the full VLAN object
resp2 = self._api.put(f"vlans/{vlan_id}", json={"name": name}) existing = self._api.get(f"vlans/{vlan_id}")
existing.pop("uri", None)
existing["name"] = name
resp2 = self._api.put(f"vlans/{vlan_id}", json=existing)
if not resp2.ok: if not resp2.ok:
raise ConnectionException( raise ConnectionException(
f"set_vlan({vlan_id}): API PUT returned HTTP {resp2.status_code}" f"set_vlan({vlan_id}): API PUT returned HTTP {resp2.status_code}"