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

Better user report when OMAPI error occurs or key is invalid (#20035)

* Move imports after header
This commit is contained in:
Ner'zhul 2017-01-09 13:40:53 +01:00 committed by John R Barker
parent e87d6d8a70
commit c1f5432cc0

View file

@ -136,6 +136,21 @@ lease:
sample: 'mydesktop'
'''
# import module snippets
from ansible.module_utils.basic import AnsibleModule, get_exception, to_bytes
from ansible.module_utils.six import iteritems
import socket
import struct
import binascii
try:
from pypureomapi import Omapi, OmapiMessage, OmapiError, OmapiErrorNotFound
from pypureomapi import pack_ip, unpack_ip, pack_mac, unpack_mac
from pypureomapi import OMAPI_OP_STATUS, OMAPI_OP_UPDATE
pureomapi_found = True
except ImportError:
pureomapi_found = False
class OmapiHostManager:
def __init__(self, module):
@ -147,6 +162,12 @@ class OmapiHostManager:
try:
self.omapi = Omapi(self.module.params['host'], self.module.params['port'], self.module.params['key_name'],
self.module.params['key'])
except binascii.Error:
self.module.fail_json(msg="Unable to open OMAPI connection. 'key' is not a valid base64 key.")
except OmapiError:
e = get_exception()
self.module.fail_json(msg="Unable to open OMAPI connection. Ensure 'host', 'port', 'key' and 'key_name' "
"are valid. Exception was: %s" % e)
except socket.error:
e = get_exception()
self.module.fail_json(msg="Unable to connect to OMAPI server: %s" % e)
@ -301,20 +322,5 @@ def main():
e = get_exception()
module.fail_json(msg="OMAPI input value error: %s" % e)
# import module snippets
from ansible.module_utils.basic import AnsibleModule, get_exception, to_bytes
from ansible.module_utils.six import iteritems
import socket
import struct
try:
from pypureomapi import Omapi, OmapiMessage, OmapiError, OmapiErrorNotFound
from pypureomapi import pack_ip, unpack_ip, pack_mac, unpack_mac
from pypureomapi import OMAPI_OP_STATUS, OMAPI_OP_UPDATE
pureomapi_found = True
except ImportError:
pureomapi_found = False
if __name__ == '__main__':
main()