in Solutions/Infoblox/Data Connectors/InfobloxCloudDataConnector/SharedCode/utils.py [0:0]
def make_dossier_call(self, url, method, headers, params=None, body=None):
"""Make a dossier call.
Args:
url (str): The URL to make the call to.
method (str): The HTTP method to use for the call.
headers (dict): The headers to include in the request.
params (dict, optional): The parameters to pass in the call (default is None).
body (dict, optional): The body of the request (default is None).
Returns:
dict: The JSON response if the call is successful.
"""
__method_name = inspect.currentframe().f_code.co_name
try:
for i in range(consts.MAX_RETRIES):
applogger.debug(
self.log_format.format(
consts.LOGS_STARTS_WITH,
__method_name,
self.azure_function_name,
"Calling url: {}".format(url),
)
)
response = requests.request(
method,
url,
headers=headers,
params=params,
json=body,
)
if response.status_code >= 200 and response.status_code <= 299:
applogger.info(
self.log_format.format(
consts.LOGS_STARTS_WITH,
__method_name,
self.azure_function_name,
"Rest Call Completed, Status code : {}".format(response.status_code),
)
)
response_json = response.json()
return response_json
elif response.status_code == 500:
applogger.error(
self.log_format.format(
consts.LOGS_STARTS_WITH,
__method_name,
self.azure_function_name,
"Internal Server Error, Status code : {}".format(response.status_code),
)
)
raise InfobloxException()
elif response.status_code == 429:
applogger.error(
self.log_format.format(
consts.LOGS_STARTS_WITH,
__method_name,
self.azure_function_name,
"Too many requests, Status code : {}, Retrying... {}".format(response.status_code, i),
)
)
time.sleep(randrange(1, 10))
continue
elif response.status_code == 404:
applogger.error(
self.log_format.format(
consts.LOGS_STARTS_WITH,
__method_name,
self.azure_function_name,
"Not found, Status code : {}".format(response.status_code),
)
)
raise InfobloxException()
else:
applogger.error(
self.log_format.format(
consts.LOGS_STARTS_WITH,
__method_name,
self.azure_function_name,
"Error while creating job, Status code: {}, Error-{}".format(
response.status_code, response.content
),
)
)
raise InfobloxException()
applogger.error(
self.log_format.format(
consts.LOGS_STARTS_WITH,
__method_name,
self.azure_function_name,
"Max retries exceeded.",
)
)
raise InfobloxException()
except requests.ConnectionError as error:
applogger.error(
self.log_format.format(
consts.LOGS_STARTS_WITH,
__method_name,
self.azure_function_name,
"Connection error : Error-{}".format(error),
)
)
raise InfobloxException()
except requests.HTTPError as error:
applogger.error(
self.log_format.format(
consts.LOGS_STARTS_WITH,
__method_name,
self.azure_function_name,
consts.HTTP_ERROR_MSG.format(error),
)
)
raise InfobloxException()
except requests.RequestException as error:
applogger.error(
self.log_format.format(
consts.LOGS_STARTS_WITH,
__method_name,
self.azure_function_name,
"Request error : Error-{}".format(error),
)
)
raise InfobloxException()
except Exception as error:
applogger.error(
self.log_format.format(
consts.LOGS_STARTS_WITH,
__method_name,
self.azure_function_name,
consts.UNEXPECTED_ERROR_MSG.format(error),
)
)
raise InfobloxException()