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

fix session load time #629

Merged
merged 1 commit into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -171,15 +174,27 @@ 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
self._validate_responses = validate_responses

@cached_property
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool

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