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:
parent
e87d6d8a70
commit
c1f5432cc0
1 changed files with 21 additions and 15 deletions
|
@ -136,6 +136,21 @@ lease:
|
||||||
sample: 'mydesktop'
|
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:
|
class OmapiHostManager:
|
||||||
def __init__(self, module):
|
def __init__(self, module):
|
||||||
|
@ -147,6 +162,12 @@ class OmapiHostManager:
|
||||||
try:
|
try:
|
||||||
self.omapi = Omapi(self.module.params['host'], self.module.params['port'], self.module.params['key_name'],
|
self.omapi = Omapi(self.module.params['host'], self.module.params['port'], self.module.params['key_name'],
|
||||||
self.module.params['key'])
|
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:
|
except socket.error:
|
||||||
e = get_exception()
|
e = get_exception()
|
||||||
self.module.fail_json(msg="Unable to connect to OMAPI server: %s" % e)
|
self.module.fail_json(msg="Unable to connect to OMAPI server: %s" % e)
|
||||||
|
@ -301,20 +322,5 @@ def main():
|
||||||
e = get_exception()
|
e = get_exception()
|
||||||
module.fail_json(msg="OMAPI input value error: %s" % e)
|
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__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in a new issue