Workaround for KVM VM created without vNICs, more errir info for API connection failures

master
Sergey Shubin svs1370 5 years ago
parent 22f54c1191
commit fdbcdbe208

@ -132,13 +132,13 @@ def main():
# catch requests.exceptions.ConnectionError to handle incorrect oauth2_url case # catch requests.exceptions.ConnectionError to handle incorrect oauth2_url case
try: try:
token_get_resp = requests.post(token_get_url, data=req_data, verify=amodule.params['verify_ssl']) token_get_resp = requests.post(token_get_url, data=req_data, verify=amodule.params['verify_ssl'])
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError as errco:
result.update(failed=True) result.update(failed=True)
result['msg'] = "Failed to connect to {}".format(token_get_url) result['msg'] = "Failed to connect to {}: {}".format(token_get_url, errco)
amodule.fail_json(**result) amodule.fail_json(**result)
except requests.exceptions.Timeout: except requests.exceptions.Timeout as errti:
result.update(failed=True) result.update(failed=True)
result['msg'] = "Timeout when trying to connect to {}".format(token_get_url) result['msg'] = "Timeout when trying to connect to {}: {}".format(token_get_url, errti)
amodule.fail_json(**result) amodule.fail_json(**result)
# alternative -- if resp == requests.codes.ok # alternative -- if resp == requests.codes.ok

@ -533,7 +533,15 @@ class decort_kvmvm(DecortController):
else: else:
validated_bdisk_size =self.amodule.params['boot_disk'] validated_bdisk_size =self.amodule.params['boot_disk']
start_compute = True # NOTE: due to a libvirt "feature", that impacts management of a VM created without any network interfaces,
# we create KVM VM in HALTED state.
# Consequently, if desired state is different from 'halted' or 'porewedoff", we should explicitly start it
# in the upstream code.
# See corresponding NOTE below for another place where this "feature" is redressed for.
#
# Once this "feature" is fixed, make sure VM is created according to the actual desired state
#
start_compute = False # change this once a workaround for the aforementioned libvirt "feature" is implemented
if self.amodule.params['state'] in ('halted', 'poweredoff'): if self.amodule.params['state'] in ('halted', 'poweredoff'):
start_compute = False start_compute = False
@ -548,6 +556,7 @@ class decort_kvmvm(DecortController):
# if we get through here, all parameters required to create new Compute instance should be at hand # if we get through here, all parameters required to create new Compute instance should be at hand
# NOTE: KVM VM is created in HALTED state and must be explicitly started
self.comp_id = self.kvmvm_provision(rg_id=self.rg_id, self.comp_id = self.kvmvm_provision(rg_id=self.rg_id,
comp_name=self.amodule.params['name'], arch=self.amodule.params['arch'], comp_name=self.amodule.params['name'], arch=self.amodule.params['arch'],
cpu=self.amodule.params['cpu'], ram=self.amodule.params['ram'], cpu=self.amodule.params['cpu'], ram=self.amodule.params['ram'],
@ -568,7 +577,12 @@ class decort_kvmvm(DecortController):
self.compute_networks(self.comp_info, self.amodule.params['networks']) self.compute_networks(self.comp_info, self.amodule.params['networks'])
# Next manage data disks # Next manage data disks
self.compute_data_disks(self.comp_info, self.amodule.params['data_disks']) self.compute_data_disks(self.comp_info, self.amodule.params['data_disks'])
# read in Compute facts after all initial setup is complete
# NOTE: see NOTE above regarding libvirt "feature" and new VMs created in HALTED state
if self.amodule.params['state'] not in ('halted', 'poweredoff'):
self.compute_powerstate(self.comp_info, 'started')
# read in Compute facts once more after all initial setup is complete
_, self.comp_info, _ = self.compute_find(comp_id=self.comp_id) _, self.comp_info, _ = self.compute_find(comp_id=self.comp_id)
return return

@ -213,14 +213,14 @@ class DecortController(object):
# catch requests.exceptions.ConnectionError to handle incorrect oauth2_url case # catch requests.exceptions.ConnectionError to handle incorrect oauth2_url case
try: try:
token_get_resp = requests.post(token_get_url, data=req_data, verify=self.verify_ssl) token_get_resp = requests.post(token_get_url, data=req_data, verify=self.verify_ssl)
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError as errco:
self.result['failed'] = True self.result['failed'] = True
self.result['msg'] = "Failed to connect to '{}' to obtain JWT access token".format(token_get_url) self.result['msg'] = "Failed to connect to '{}' to obtain JWT access token: {}".format(token_get_url, errco)
self.amodule.fail_json(**self.result) self.amodule.fail_json(**self.result)
except requests.exceptions.Timeout: except requests.exceptions.Timeout as errti:
self.result['failed'] = True self.result['failed'] = True
self.result['msg'] = "Timeout when trying to connect to '{}' to obtain JWT access token".format( self.result['msg'] = "Timeout when trying to connect to '{}' to obtain JWT access token: {}".format(
token_get_url) token_get_url, errti)
self.amodule.fail_json(**self.result) self.amodule.fail_json(**self.result)
# alternative -- if resp == requests.codes.ok # alternative -- if resp == requests.codes.ok

Loading…
Cancel
Save