Merge branch 'fix/decort_utils.py/_rg_get_by_id/1' into 'rc-5.2.6'

Add call of API /cloudapi/rg/getResourceConsumption to...

See merge request rudecs/dev/decort-ansible!14
rc-5.3.0^2
Алексей Даньков 10 months ago
commit 9bf50c958f

@ -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,41 @@ 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
rg_status = ret_rg_dict.get('status')
if not rg_status or rg_status == 'DELETED':
return ret_rg_id, ret_rg_dict
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