def verifyStatus(self, url, timeout=120): counter = 0 while True: response = self.get(url) if 'status' in response.json(): currentStatus = response.json()['status'] elif 'state' in response.json(): currentStatus = response.json()['state'] if currentStatus == 'Error': errorMessage = 'Operation failed' if 'message' in response.json(): errorMessage = response.json()['message'] raise IxLoadRestApiException('verifyStatus failed: {}'.format(errorMessage)) else: raise IxLoadRestApiException('verifyStatus failed: No status and no state in json response') self.logInfo(f'verifyStatus: {response.json()}') if currentStatus == 'Error' and 'error' in response.json(): errorMessage = response.json()['error'] raise IxLoadRestApiException('Operation failed: {0}'.format(errorMessage)) if currentStatus == 'EXCEPTION': if 'error' in response.json(): errorMessage = response.json()['error'] raise IxLoadRestApiException(f'Operation failed: {errorMessage}') else: raise IxLoadRestApiException(f'Operation failed') if counter <= timeout and currentStatus not in ['Successful', 'SUCCESS']: self.logInfo(f'\tCurrent status: {currentStatus}. Wait {counter}/{timeout} seconds...', timestamp=False) time.sleep(self.pollStatusInterval) counter += self.pollStatusInterval continue self.logInfo(f'\n\tverifyStatus: Current Status: {currentStatus}') if counter <= timeout and currentStatus in ['Successful', 'SUCCESS']: return if counter >= timeout and currentStatus not in ['Successful', 'SUCCESS']: raise IxLoadRestApiException('Operation failed: {0}'.format(url))