mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
Handle virtual machine config element gracefully (#32924)
This fix uses '_get_vm_prop' API to handle virtual machine related properties rather than failing with AttributeError. Handled invalid request type while connecting to ESXi server, which is caused by malformed request. Fixes: #32477 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
@@ -26,7 +26,7 @@ try:
|
||||
# requests is required for exception handling of the ConnectionError
|
||||
import requests
|
||||
from pyVim import connect
|
||||
from pyVmomi import vim
|
||||
from pyVmomi import vim, vmodl
|
||||
HAS_PYVMOMI = True
|
||||
except ImportError:
|
||||
HAS_PYVMOMI = False
|
||||
@@ -420,11 +420,15 @@ def connect_to_api(module, disconnect_atexit=True):
|
||||
" to log on to vCenter or ESXi API at %s: %s" % (username, hostname, e.msg))
|
||||
except (requests.ConnectionError, ssl.SSLError) as e:
|
||||
module.fail_json(msg="Unable to connect to vCenter or ESXi API at %s on TCP/443: %s" % (hostname, e))
|
||||
except vmodl.fault.InvalidRequest as e:
|
||||
# Request is malformed
|
||||
module.fail_json(msg="Failed to get a response from server %s as "
|
||||
"request is malformed: %s" % (hostname, e.msg))
|
||||
except Exception as e:
|
||||
module.fail_json(msg="Unknown error connecting to vCenter or ESXi API at %s: %s" % (hostname, e))
|
||||
module.fail_json(msg="Unknown error while connecting to vCenter or ESXi API at %s: %s" % (hostname, e))
|
||||
|
||||
if service_instance is None:
|
||||
module.fail_json(msg="Unknown error connecting to vCenter or ESXi API at %s" % hostname)
|
||||
module.fail_json(msg="Unknown error while connecting to vCenter or ESXi API at %s" % hostname)
|
||||
|
||||
# Disabling atexit should be used in special cases only.
|
||||
# Such as IP change of the ESXi host which removes the connection anyway.
|
||||
|
||||
Reference in New Issue
Block a user