forked from ISPsystem/isp-maintenance
		
	Hotfix: some instances use dashes rather than underscores in container names
This commit is contained in:
		
							parent
							
								
									e0de805af7
								
							
						
					
					
						commit
						da3e61eccb
					
				| @ -7,6 +7,7 @@ import requests | |||||||
| from time import sleep | from time import sleep | ||||||
| 
 | 
 | ||||||
| from mgrctl.settings.api import ( | from mgrctl.settings.api import ( | ||||||
|  |     API_INPUT_PORT, | ||||||
|     API_URL, |     API_URL, | ||||||
|     API_HEADERS, |     API_HEADERS, | ||||||
|     API_EMAIL, |     API_EMAIL, | ||||||
| @ -14,6 +15,7 @@ from mgrctl.settings.api import ( | |||||||
|     API_VERIFY_SSL, |     API_VERIFY_SSL, | ||||||
|     API_COUNT_TRY_CONNECTIONS |     API_COUNT_TRY_CONNECTIONS | ||||||
| ) | ) | ||||||
|  | from mgrctl.settings.platform import PLATFORM_TYPE | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class BaseAPI(object): | class BaseAPI(object): | ||||||
| @ -33,6 +35,7 @@ class BaseAPI(object): | |||||||
|     def call_api(self, url, method='GET', headers={}, data={}): |     def call_api(self, url, method='GET', headers={}, data={}): | ||||||
|         attempt = API_COUNT_TRY_CONNECTIONS |         attempt = API_COUNT_TRY_CONNECTIONS | ||||||
|         while attempt: |         while attempt: | ||||||
|  |             attempt -= 1 | ||||||
|             try: |             try: | ||||||
|                 uri = self._gen_request_url(url) |                 uri = self._gen_request_url(url) | ||||||
|                 headers = self.API_HEADERS if not headers else headers |                 headers = self.API_HEADERS if not headers else headers | ||||||
| @ -52,16 +55,25 @@ class BaseAPI(object): | |||||||
|                         verify=self.API_VERIFY_SSL |                         verify=self.API_VERIFY_SSL | ||||||
|                     ) |                     ) | ||||||
|             except Exception as error: |             except Exception as error: | ||||||
|                 click.echo(f'Error: {type(error).__name__}') |                 ConnectionError = requests.exceptions.ConnectionError | ||||||
|                 sys.exit() |                 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: |             # Get response: | ||||||
|             response = self._parse_response(api_request) |             response = self._parse_response(api_request) | ||||||
| 
 | 
 | ||||||
|             # Validate response: |             # Validate response: | ||||||
|             if self._error_handler(response): |             if self._error_handler(response): | ||||||
|                 attempt -= 1 |  | ||||||
|                 sleep(2)  # wait 2 second timeout |  | ||||||
|                 continue  # new attempt connection |                 continue  # new attempt connection | ||||||
| 
 | 
 | ||||||
|             return response |             return response | ||||||
| @ -80,6 +92,7 @@ class BaseAPI(object): | |||||||
| 
 | 
 | ||||||
|     def _is_error_3004(self, error): |     def _is_error_3004(self, error): | ||||||
|         if error.get('code') == 3004: |         if error.get('code') == 3004: | ||||||
|  |             sleep(2)  # wait 2 second timeout | ||||||
|             return True |             return True | ||||||
| 
 | 
 | ||||||
|     def _error_handler(self, response): |     def _error_handler(self, response): | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user