def _do_request(self, payload): payload = payload.build() LOG.debug('Sending request to %(endpoint)s: %(payload)s', { 'endpoint': self.endpoint, 'payload': payload }) try: resp = requests.post( self.endpoint, auth=requests.auth.HTTPBasicAuth(self.username, self.password), data=payload, # TODO(ifarkas): enable cert verification verify=False) except requests.exceptions.RequestException: LOG.exception('Request failed') raise exceptions.WSManRequestFailure() LOG.debug('Received response from %(endpoint)s: %(payload)s', { 'endpoint': self.endpoint, 'payload': resp.content }) if not resp.ok: raise exceptions.WSManInvalidResponse(status_code=resp.status_code, reason=resp.reason) else: return resp
def _do_request(self, payload): payload = payload.build() # LOG.debug('Sending request to %(endpoint)s: %(payload)s', # {'endpoint': self.endpoint, 'payload': payload}) num_tries = 1 while num_tries <= self.ssl_retries: try: resp = requests.post( self.endpoint, auth=requests.auth.HTTPBasicAuth(self.username, self.password), data=payload, # TODO(ifarkas): enable cert verification verify=False) break except (requests.exceptions.ConnectionError, requests.exceptions.SSLError) as ex: error_msg = "A {error_type} error occurred while " \ " communicating with {host}, attempt {num_tries} of " \ "{retries}".format( error_type=type(ex).__name__, host=self.host, num_tries=num_tries, retries=self.ssl_retries) if num_tries == self.ssl_retries: # LOG.error(error_msg) raise exceptions.WSManRequestFailure( "A {error_type} error occurred while communicating " "with {host}: {error}".format( error_type=type(ex).__name__, host=self.host, error=ex)) else: print(error_msg) # LOG.warning(error_msg) num_tries += 1 if self.ssl_retry_delay > 0 and num_tries <= self.ssl_retries: time.sleep(self.ssl_retry_delay) except requests.exceptions.RequestException as ex: error_msg = "A {error_type} error occurred while " \ "communicating with {host}: {error}".format( error_type=type(ex).__name__, host=self.host, error=ex) # LOG.error(error_msg) raise exceptions.WSManRequestFailure(error_msg) # LOG.debug('Received response from %(endpoint)s: %(payload)s', # {'endpoint': self.endpoint, 'payload': resp.content}) if not resp.ok: raise exceptions.WSManInvalidResponse(status_code=resp.status_code, reason=resp.reason) else: return resp