mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
(cherry picked from commit 5c768dc6f1
)
Co-authored-by: Alexey Masolov <amasolov@redhat.com>
This commit is contained in:
parent
bcf0060f10
commit
7ace59f505
2 changed files with 12 additions and 10 deletions
2
changelogs/fragments/788-fix_omapi_host_on_python3.yaml
Normal file
2
changelogs/fragments/788-fix_omapi_host_on_python3.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- omapi_host - fix compatibility with Python 3 (https://github.com/ansible-collections/community.general/issues/787).
|
|
@ -150,7 +150,7 @@ class OmapiHostManager:
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
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'], to_bytes(self.module.params['key_name']),
|
||||||
self.module.params['key'])
|
self.module.params['key'])
|
||||||
except binascii.Error:
|
except binascii.Error:
|
||||||
self.module.fail_json(msg="Unable to open OMAPI connection. 'key' is not a valid base64 key.")
|
self.module.fail_json(msg="Unable to open OMAPI connection. 'key' is not a valid base64 key.")
|
||||||
|
@ -173,13 +173,13 @@ class OmapiHostManager:
|
||||||
def unpack_facts(obj):
|
def unpack_facts(obj):
|
||||||
result = dict(obj)
|
result = dict(obj)
|
||||||
if 'hardware-address' in result:
|
if 'hardware-address' in result:
|
||||||
result['hardware-address'] = unpack_mac(result['hardware-address'])
|
result['hardware-address'] = to_native(unpack_mac(result[to_bytes('hardware-address')]))
|
||||||
|
|
||||||
if 'ip-address' in result:
|
if 'ip-address' in result:
|
||||||
result['ip-address'] = unpack_ip(result['ip-address'])
|
result['ip-address'] = to_native(unpack_ip(result[to_bytes('ip-address')]))
|
||||||
|
|
||||||
if 'hardware-type' in result:
|
if 'hardware-type' in result:
|
||||||
result['hardware-type'] = struct.unpack("!I", result['hardware-type'])
|
result['hardware-type'] = struct.unpack("!I", result[to_bytes('hardware-type')])
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -192,11 +192,11 @@ class OmapiHostManager:
|
||||||
# If host was not found using macaddr, add create message
|
# If host was not found using macaddr, add create message
|
||||||
if host_response is None:
|
if host_response is None:
|
||||||
msg = OmapiMessage.open(to_bytes('host', errors='surrogate_or_strict'))
|
msg = OmapiMessage.open(to_bytes('host', errors='surrogate_or_strict'))
|
||||||
msg.message.append(('create', struct.pack('!I', 1)))
|
msg.message.append((to_bytes('create'), struct.pack('!I', 1)))
|
||||||
msg.message.append(('exclusive', struct.pack('!I', 1)))
|
msg.message.append((to_bytes('exclusive'), struct.pack('!I', 1)))
|
||||||
msg.obj.append(('hardware-address', pack_mac(self.module.params['macaddr'])))
|
msg.obj.append((to_bytes('hardware-address'), pack_mac(self.module.params['macaddr'])))
|
||||||
msg.obj.append(('hardware-type', struct.pack('!I', 1)))
|
msg.obj.append((to_bytes('hardware-type'), struct.pack('!I', 1)))
|
||||||
msg.obj.append(('name', self.module.params['hostname']))
|
msg.obj.append((to_bytes('name'), to_bytes(self.module.params['hostname'])))
|
||||||
if self.module.params['ip'] is not None:
|
if self.module.params['ip'] is not None:
|
||||||
msg.obj.append((to_bytes("ip-address", errors='surrogate_or_strict'), pack_ip(self.module.params['ip'])))
|
msg.obj.append((to_bytes("ip-address", errors='surrogate_or_strict'), pack_ip(self.module.params['ip'])))
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ class OmapiHostManager:
|
||||||
self.module.fail_json(msg="Invalid statements found: %s" % to_native(e))
|
self.module.fail_json(msg="Invalid statements found: %s" % to_native(e))
|
||||||
|
|
||||||
if len(stmt_join) > 0:
|
if len(stmt_join) > 0:
|
||||||
msg.obj.append(('statements', stmt_join))
|
msg.obj.append((to_bytes('statements'), to_bytes(stmt_join)))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = self.omapi.query_server(msg)
|
response = self.omapi.query_server(msg)
|
||||||
|
|
Loading…
Reference in a new issue