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

Fix: admintech wait #17

Merged
merged 9 commits into from
Apr 11, 2024
18 changes: 11 additions & 7 deletions catalystwan/api/admin_tech_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from pathlib import Path
from typing import TYPE_CHECKING, List, Optional

from requests import Response
from requests.exceptions import HTTPError
from requests import Response # type: ignore
from requests.exceptions import HTTPError # type: ignore

from catalystwan.dataclasses import AdminTech, DeviceAdminTech
from catalystwan.exceptions import CatalystwanException
Expand Down Expand Up @@ -131,11 +131,15 @@ def generate(
polling_timer -= polling_interval
raise GenerateAdminTechLogError(f"It is not possible to generate admintech log for {device_id}")

def _get_token_id(self, filename: str) -> str:
admin_techs = self.get_all()
for admin_tech in admin_techs:
if filename == admin_tech.filename:
return admin_tech.token_id
def _get_token_id(self, filename: str, timeout: int = 3600, interval: int = 30) -> str:
# Wait for the file to be ready and obtain the token_id
end_time = time.time() + timeout
while time.time() < end_time:
admin_techs = self.get_all()
for admin_tech in admin_techs:
if filename == admin_tech.filename and admin_tech.state == "done":
return admin_tech.token_id
time.sleep(interval)
raise RequestTokenIdNotFound(
f"requestTokenId of admin tech generation request not found for file name: {filename}"
)
Expand Down