Avoid excessive compute/get calls in compute_find
This commit is contained in:
@@ -655,15 +655,24 @@ class DecortController(object):
|
|||||||
|
|
||||||
validated_rg_id, validated_rg_facts = self._rg_get_by_id(rg_id)
|
validated_rg_id, validated_rg_facts = self._rg_get_by_id(rg_id)
|
||||||
if validated_rg_id:
|
if validated_rg_id:
|
||||||
|
api_params = {
|
||||||
|
'includedeleted': True,
|
||||||
|
}
|
||||||
|
api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/compute/list", api_params)
|
||||||
|
if api_resp.status_code == 200:
|
||||||
|
comp_list = json.loads(api_resp.content.decode('utf8'))
|
||||||
|
else:
|
||||||
|
self.result['warning'] = ("compute_find(): failed to get list Computes. HTTP code {}, "
|
||||||
|
"response {}.").format(api_resp.status_code, api_resp.reason)
|
||||||
|
|
||||||
# if we have validated RG ID at this point, look up Compute by name in this RG
|
# if we have validated RG ID at this point, look up Compute by name in this RG
|
||||||
# rg.vms list contains IDs of compute instances registered with this RG until compute is
|
# rg.vms list contains IDs of compute instances registered with this RG until compute is
|
||||||
# destroyed. So we may see here computes in "active" and DELETED states.
|
# destroyed. So we may see here computes in "active" and DELETED states.
|
||||||
for runner in validated_rg_facts['vms']:
|
for runner in comp_list:
|
||||||
_, runner_dict, _ = self._compute_get_by_id(runner)
|
if runner['name'] == comp_name and runner['rgId'] == validated_rg_id:
|
||||||
if runner_dict['name'] == comp_name:
|
if not check_state or runner['status'] not in COMP_INVALID_STATES:
|
||||||
if not check_state or runner_dict['status'] not in COMP_INVALID_STATES:
|
ret_comp_id = runner['id']
|
||||||
ret_comp_id = runner
|
ret_comp_dict = runner
|
||||||
ret_comp_dict = runner_dict
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
# validated_rg_id is zero - seems that we've been given RG ID for non-existent resource group.
|
# validated_rg_id is zero - seems that we've been given RG ID for non-existent resource group.
|
||||||
|
|||||||
Reference in New Issue
Block a user