From da3e61eccbfc1fd837685b3ed7a633122bced274 Mon Sep 17 00:00:00 2001 From: MOIS3Y Date: Sun, 9 Jun 2024 16:41:55 +0900 Subject: [PATCH] Hotfix: some instances use dashes rather than underscores in container names --- mgrctl/api/base.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/mgrctl/api/base.py b/mgrctl/api/base.py index a7fe3c8..8ea7f61 100644 --- a/mgrctl/api/base.py +++ b/mgrctl/api/base.py @@ -7,6 +7,7 @@ import requests from time import sleep from mgrctl.settings.api import ( + API_INPUT_PORT, API_URL, API_HEADERS, API_EMAIL, @@ -14,6 +15,7 @@ from mgrctl.settings.api import ( API_VERIFY_SSL, API_COUNT_TRY_CONNECTIONS ) +from mgrctl.settings.platform import PLATFORM_TYPE class BaseAPI(object): @@ -33,6 +35,7 @@ class BaseAPI(object): def call_api(self, url, method='GET', headers={}, data={}): attempt = API_COUNT_TRY_CONNECTIONS while attempt: + attempt -= 1 try: uri = self._gen_request_url(url) headers = self.API_HEADERS if not headers else headers @@ -52,16 +55,25 @@ class BaseAPI(object): verify=self.API_VERIFY_SSL ) except Exception as error: - click.echo(f'Error: {type(error).__name__}') - sys.exit() + ConnectionError = requests.exceptions.ConnectionError + if type(error) is ConnectionError and PLATFORM_TYPE == 'dci': + # ? workaround if new docker version use dashes + # TODO: ISPsystem developers must set container_name !!! + self.API_URL = f'http://dci-input-1:{API_INPUT_PORT}' + if attempt == 0: + click.echo(f'Error: {type(error).__name__}') + sys.exit() + else: + continue + else: + click.echo(f'Error: {type(error).__name__}') + sys.exit() # Get response: response = self._parse_response(api_request) # Validate response: if self._error_handler(response): - attempt -= 1 - sleep(2) # wait 2 second timeout continue # new attempt connection return response @@ -80,6 +92,7 @@ class BaseAPI(object): def _is_error_3004(self, error): if error.get('code') == 3004: + sleep(2) # wait 2 second timeout return True def _error_handler(self, response):