Hotfixes API and gogo.sh #14

Merged
MOIS3Y merged 2 commits from MOIS3Y/isp-maintenance:gogo into main 2024-06-09 15:59:05 +08:00
Showing only changes of commit da3e61eccb - Show all commits

View File

@ -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,6 +55,17 @@ class BaseAPI(object):
verify=self.API_VERIFY_SSL
)
except Exception as error:
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()
@ -60,8 +74,6 @@ class BaseAPI(object):
# 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):