Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
disable relogin flag during logout (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbasan authored Mar 26, 2024
1 parent 91c84e4 commit 0f55aed
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions catalystwan/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,23 @@ def get_virtual_session_id(self, tenant_id: str) -> str:
return response.json()["VSessionId"]

def logout(self) -> Optional[ManagerResponse]:
response = None
if isinstance((version := self.api_version), NullVersion):
self.logger.warning("Cannot perform logout operation without known api_version.")
return None
return response
else:
return self.post("/logout") if version >= Version("20.12") else self.get("/logout")
# disable automatic relogin before performing logout request
_relogin = self.enable_relogin
try:
self.enable_relogin = False
if version >= Version("20.12"):
response = self.post("/logout")
else:
response = self.get("/logout")
finally:
# restore original setting after performing logout request
self.enable_relogin = _relogin
return response

def close(self) -> None:
"""Closes the ManagerSession.
Expand All @@ -443,7 +455,6 @@ def close(self) -> None:
using the `with` statement, which ensures that the session is properly
closed and resources are cleaned up even in case of exceptions.
"""
self.enable_relogin = False
self.logout()
super().close()

Expand Down

0 comments on commit 0f55aed

Please sign in to comment.