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

Commit

Permalink
Fix: admintech wait (#17)
Browse files Browse the repository at this point in the history
* version check and model update for user

* admin tech - wait for file ready

* get token

* correct logic

* Add default None values to the Tier model (#16)

---------

Co-authored-by: Nikhil <[email protected]>
Co-authored-by: PrzeG <[email protected]>
  • Loading branch information
3 people committed Apr 22, 2024
1 parent 6ecdf14 commit 3ef254e
Showing 1 changed file with 11 additions and 7 deletions.
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

0 comments on commit 3ef254e

Please sign in to comment.