From 7e7fad974ae5744ee2f37057e330108ab3a473c1 Mon Sep 17 00:00:00 2001 From: Nikhil Date: Tue, 23 Jan 2024 17:53:03 -0800 Subject: [PATCH 1/4] version check and model update for user --- vmngclient/endpoints/administration_user_and_group.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/vmngclient/endpoints/administration_user_and_group.py b/vmngclient/endpoints/administration_user_and_group.py index 8d67e580a..3ab6b5b01 100644 --- a/vmngclient/endpoints/administration_user_and_group.py +++ b/vmngclient/endpoints/administration_user_and_group.py @@ -4,7 +4,7 @@ from pydantic.v1 import BaseModel, Field -from vmngclient.endpoints import APIEndpoints, delete, get, post, put +from vmngclient.endpoints import APIEndpoints, delete, get, post, put, versions from vmngclient.typed_list import DataSequence @@ -15,6 +15,7 @@ class User(BaseModel): locale: Optional[str] description: Optional[str] resource_group: Optional[str] = Field(alias="resGroupName") + resource_domain: Optional[str] = Field(alias="resourceDomainName") class UserUpdateRequest(BaseModel): @@ -27,7 +28,10 @@ class UserUpdateRequest(BaseModel): group: Optional[List[str]] locale: Optional[str] description: Optional[str] - resource_group: Optional[str] = Field(alias="resGroupName") + if versions("<=20.13"): + resource_group: Optional[str] = Field(alias="resGroupName") + else: + resource_domain: Optional[str] = Field(alias="resourceDomainName") class UserRole(BaseModel): From ec80813ee8ba77742c093f85bd0c7d15069617d1 Mon Sep 17 00:00:00 2001 From: Nikhil Date: Wed, 10 Apr 2024 15:11:47 -0700 Subject: [PATCH 2/4] admin tech - wait for file ready --- catalystwan/api/admin_tech_api.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/catalystwan/api/admin_tech_api.py b/catalystwan/api/admin_tech_api.py index 06e95c9fe..17b14d745 100644 --- a/catalystwan/api/admin_tech_api.py +++ b/catalystwan/api/admin_tech_api.py @@ -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 @@ -120,7 +120,8 @@ def generate( except HTTPError as http_error: response = http_error.response # type: ignore if response.status_code == 200: - return response.json()["fileName"] + filename = response.json()["fileName"] + return self._wait_for_file_ready(filename) if response.status_code == 400 and create_admin_tech_error_msgs in response.json().get("error", {}).get( "details", "" ): @@ -131,6 +132,17 @@ def generate( polling_timer -= polling_interval raise GenerateAdminTechLogError(f"It is not possible to generate admintech log for {device_id}") + def _wait_for_file_ready(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 GenerateAdminTechLogError(f"Timeout waiting for admin tech log to be ready for {filename}") + def _get_token_id(self, filename: str) -> str: admin_techs = self.get_all() for admin_tech in admin_techs: From ea16f46bc9b77e46c0b64506e9d7e7069569f88c Mon Sep 17 00:00:00 2001 From: Nikhil Date: Wed, 10 Apr 2024 20:39:51 -0700 Subject: [PATCH 3/4] get token --- catalystwan/api/admin_tech_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/catalystwan/api/admin_tech_api.py b/catalystwan/api/admin_tech_api.py index 17b14d745..134640830 100644 --- a/catalystwan/api/admin_tech_api.py +++ b/catalystwan/api/admin_tech_api.py @@ -146,7 +146,7 @@ def _wait_for_file_ready(self, filename: str, timeout: int = 3600, interval: int def _get_token_id(self, filename: str) -> str: admin_techs = self.get_all() for admin_tech in admin_techs: - if filename == admin_tech.filename: + if filename == admin_tech.filename and admin_tech.state == "done": return admin_tech.token_id raise RequestTokenIdNotFound( f"requestTokenId of admin tech generation request not found for file name: {filename}" From ab23db06d6b139ccbb01391b0eb77cdd0e331227 Mon Sep 17 00:00:00 2001 From: Nikhil Date: Wed, 10 Apr 2024 20:57:48 -0700 Subject: [PATCH 4/4] correct logic --- catalystwan/api/admin_tech_api.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/catalystwan/api/admin_tech_api.py b/catalystwan/api/admin_tech_api.py index 134640830..088251f21 100644 --- a/catalystwan/api/admin_tech_api.py +++ b/catalystwan/api/admin_tech_api.py @@ -120,8 +120,7 @@ def generate( except HTTPError as http_error: response = http_error.response # type: ignore if response.status_code == 200: - filename = response.json()["fileName"] - return self._wait_for_file_ready(filename) + return response.json()["fileName"] if response.status_code == 400 and create_admin_tech_error_msgs in response.json().get("error", {}).get( "details", "" ): @@ -132,7 +131,7 @@ def generate( polling_timer -= polling_interval raise GenerateAdminTechLogError(f"It is not possible to generate admintech log for {device_id}") - def _wait_for_file_ready(self, filename: str, timeout: int = 3600, interval: int = 30) -> str: + 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: @@ -141,13 +140,6 @@ def _wait_for_file_ready(self, filename: str, timeout: int = 3600, interval: int if filename == admin_tech.filename and admin_tech.state == "done": return admin_tech.token_id time.sleep(interval) - raise GenerateAdminTechLogError(f"Timeout waiting for admin tech log to be ready for {filename}") - - def _get_token_id(self, filename: str) -> str: - 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 raise RequestTokenIdNotFound( f"requestTokenId of admin tech generation request not found for file name: {filename}" )