1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add error handling for user login (#32613)

This fix adds additional error handling for vmware connect
method, where username provided user does not have required
permissions to use/login ESXi.

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2017-11-08 20:48:22 +00:00 committed by Jordan Borean
parent 8e081b7e30
commit 80967380d3

View file

@ -414,6 +414,9 @@ def connect_to_api(module, disconnect_atexit=True):
service_instance = connect.SmartConnect(host=hostname, user=username, pwd=password, sslContext=ssl_context) service_instance = connect.SmartConnect(host=hostname, user=username, pwd=password, sslContext=ssl_context)
except vim.fault.InvalidLogin as e: except vim.fault.InvalidLogin as e:
module.fail_json(msg="Unable to log on to vCenter or ESXi API at %s as %s: %s" % (hostname, username, e.msg)) module.fail_json(msg="Unable to log on to vCenter or ESXi API at %s as %s: %s" % (hostname, username, e.msg))
except vim.fault.NoPermission as e:
module.fail_json(msg="User %s does not have required permission"
" to log on to vCenter or ESXi API at %s: %s" % (username, hostname, e.msg))
except (requests.ConnectionError, ssl.SSLError) as e: 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)) module.fail_json(msg="Unable to connect to vCenter or ESXi API at %s on TCP/443: %s" % (hostname, e))
except Exception as e: except Exception as e: