Optimize number of compute/get calls when creating new kvmvm, step 2
This commit is contained in:
@@ -570,8 +570,22 @@ class decort_kvmvm(DecortController):
|
|||||||
start_on_create=start_compute)
|
start_on_create=start_compute)
|
||||||
self.comp_should_exist = True
|
self.comp_should_exist = True
|
||||||
|
|
||||||
# Need to re-read comp_info after VM was provisioned
|
# Originally we would have had to re-read comp_info after VM was provisioned
|
||||||
_, self.comp_info, _ = self.compute_find(self.comp_id)
|
# _, self.comp_info, _ = self.compute_find(self.comp_id)
|
||||||
|
|
||||||
|
# However, to avoid extra call to compute/get API we need to construct comp_info so that
|
||||||
|
# the below calls to compute_networks and compute_data_disks work properly.
|
||||||
|
#
|
||||||
|
# Here we are imitating comp_info structure as if it has been returned by a real call
|
||||||
|
# to API compute/get
|
||||||
|
self.comp_info = {
|
||||||
|
'id': self.comp_id,
|
||||||
|
'accountId': self.acc_id,
|
||||||
|
'status': "ENABLED",
|
||||||
|
'techStatus': "STOPPED",
|
||||||
|
'interfaces': [], # new compute instance is created network-less
|
||||||
|
'disks': [], # new compute instance is created without any data disks attached
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Compute was created
|
# Compute was created
|
||||||
|
|||||||
@@ -2273,16 +2273,15 @@ class DecortController(object):
|
|||||||
return 0, None
|
return 0, None
|
||||||
elif disk_name != "":
|
elif disk_name != "":
|
||||||
if account_id > 0:
|
if account_id > 0:
|
||||||
api_params = dict(accountId=account_id,
|
api_params = dict(accountId=account_id)
|
||||||
name=disk_name,
|
api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/disks/list", api_params)
|
||||||
showAll=False) # we do not want to see disks in DESTROYED, PURGED or invalid states
|
|
||||||
api_resp = self.decort_api_call(requests.post, "/restmachine/cloudapi/disks/search", api_params)
|
|
||||||
# the above call may return more than one matching disk
|
# the above call may return more than one matching disk
|
||||||
disks_list = json.loads(api_resp.content.decode('utf8'))
|
disks_list = json.loads(api_resp.content.decode('utf8'))
|
||||||
for runner in disks_list:
|
for runner in disks_list:
|
||||||
# return first disk on this list that fulfills status matching rule
|
# return the first disk of the specified name that fulfills status matching rule
|
||||||
if not check_state or ret_disk_facts['status'] not in DISK_INVALID_STATES:
|
if runner['name'] == disk_name:
|
||||||
return runner['id'], runner
|
if not check_state or runner['status'] not in DISK_INVALID_STATES:
|
||||||
|
return runner['id'], runner
|
||||||
else:
|
else:
|
||||||
return 0, None
|
return 0, None
|
||||||
else: # we are missing meaningful account_id - fail the module
|
else: # we are missing meaningful account_id - fail the module
|
||||||
|
|||||||
Reference in New Issue
Block a user