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

Admintech wait for file #545

Closed
wants to merge 6 commits into from
Closed
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
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