Add call of API /cloudapi/rg/getResourceConsumption to DecortController._rg_get_by_id and update its logic and code style

rc-5.3.0^2
Dmitriy Smirnov 11 months ago
parent a5f03389f2
commit 1304a0fcbf

@ -1561,9 +1561,10 @@ class DecortController(object):
@param (int) )rg_id: ID of the RG to find and return facts for. @param (int) )rg_id: ID of the RG to find and return facts for.
@return: RG ID and a dictionary of RG facts as provided by rg/get API call. Note that if it fails @return: RG ID and a dictionary of RG facts as provided by rg/get
to find the RG with the specified ID, it may return 0 for ID and empty dictionary for the facts. So API call. Note that if it fails to find the RG with the specified ID,
it is suggested to check the return values accordingly. it may return 0 for ID and empty dictionary for the facts. So it is
suggested to check the return values accordingly.
""" """
ret_rg_id = 0 ret_rg_id = 0
ret_rg_dict = dict() ret_rg_dict = dict()
@ -1573,14 +1574,38 @@ class DecortController(object):
self.result['msg'] = "rg_get_by_id(): zero RG ID specified." self.result['msg'] = "rg_get_by_id(): zero RG ID specified."
self.amodule.fail_json(**self.result) self.amodule.fail_json(**self.result)
api_params = dict(rgId=rg_id, ) api_params = {'rgId': rg_id}
api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/rg/get", api_params)
if api_resp.status_code == 200: # Get RG base info
api_rg_resp = self.decort_api_call(
arg_req_function=requests.post,
arg_api_name='/restmachine/cloudapi/rg/get',
arg_params=api_params
)
if api_rg_resp.status_code != 200:
self.result['warning'] = (
f'rg_get_by_id(): failed to get RG by ID {rg_id}.'
f' HTTP code {api_rg_resp.status_code}'
f', response {api_rg_resp.reason}.'
)
return ret_rg_id, ret_rg_dict
ret_rg_id = rg_id ret_rg_id = rg_id
ret_rg_dict = json.loads(api_resp.content.decode('utf8')) ret_rg_dict = api_rg_resp.json()
# Get RG resources info
api_rg_res_resp = self.decort_api_call(
arg_req_function=requests.post,
arg_api_name='/restmachine/cloudapi/rg/getResourceConsumption',
arg_params=api_params
)
if api_rg_res_resp.status_code != 200:
self.result['warning'] = (
f'rg_get_by_id(): failed to get RG Resources by ID {rg_id}.'
f' HTTP code {api_rg_res_resp.status_code}'
f', response {api_rg_res_resp.reason}.'
)
else: else:
self.result['warning'] = ("rg_get_by_id(): failed to get RG by ID {}. HTTP code {}, " ret_rg_dict['Resources'] = api_rg_res_resp.json()
"response {}.").format(rg_id, api_resp.status_code, api_resp.reason)
return ret_rg_id, ret_rg_dict return ret_rg_id, ret_rg_dict

Loading…
Cancel
Save