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

Commit

Permalink
api and endpoints containers as cached properties
Browse files Browse the repository at this point in the history
  • Loading branch information
sbasan committed May 6, 2024
1 parent f8e64e8 commit e265fce
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions catalystwan/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

import logging
from enum import Enum
from functools import cached_property
from pathlib import Path
from time import monotonic, sleep
from typing import Any, Callable, ClassVar, Dict, List, Optional, Union
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Dict, List, Optional, Union
from urllib.parse import urljoin, urlparse, urlunparse

from packaging.version import Version # type: ignore
Expand All @@ -15,10 +16,8 @@
from requests.exceptions import ConnectionError, HTTPError, RequestException

from catalystwan import USER_AGENT
from catalystwan.api.api_container import APIContainer
from catalystwan.endpoints import APIEndpointClient
from catalystwan.endpoints.client import AboutInfo, ServerInfo
from catalystwan.endpoints.endpoints_container import APIEndpointContainter
from catalystwan.exceptions import (
DefaultPasswordError,
ManagerHTTPError,
Expand All @@ -35,6 +34,10 @@

JSON = Union[Dict[str, "JSON"], List["JSON"], str, int, float, bool, None]

if TYPE_CHECKING:
from catalystwan.api.api_container import APIContainer
from catalystwan.endpoints.endpoints_container import APIEndpointContainter


class UserMode(str, Enum):
PROVIDER = "provider"
Expand Down Expand Up @@ -170,14 +173,26 @@ def __init__(
super(ManagerSession, self).__init__()
self.headers.update({"User-Agent": USER_AGENT})
self.__prepare_session(verify, auth)
self.api = APIContainer(self)
self.endpoints = APIEndpointContainter(self)
self._platform_version: str = ""
self._api_version: Version
self._state: ManagerSessionState = ManagerSessionState.OPERATIVE
self.restart_timeout: int = 1200
self.polling_requests_timeout: int = 10

@cached_property
def api(self) -> APIContainer:
from catalystwan.api.api_container import APIContainer

self._api = APIContainer(self)
return self._api

@cached_property
def endpoints(self) -> APIEndpointContainter:
from catalystwan.endpoints.endpoints_container import APIEndpointContainter

self._endpoints = APIEndpointContainter(self)
return self._endpoints

@property
def state(self) -> ManagerSessionState:
return self._state
Expand Down

0 comments on commit e265fce

Please sign in to comment.