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

[2.10] Fix omapi_host on python3 (#788) (#1353)

(cherry picked from commit 5c768dc6f1)

Co-authored-by: Alexey Masolov <amasolov@redhat.com>
This commit is contained in:
patchback[bot] 2020-11-22 12:43:09 +01:00 committed by GitHub
parent bcf0060f10
commit 7ace59f505
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 10 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- omapi_host - fix compatibility with Python 3 (https://github.com/ansible-collections/community.general/issues/787).

View file

@ -150,7 +150,7 @@ class OmapiHostManager:
def connect(self):
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'])
except binascii.Error:
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):
result = dict(obj)
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:
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:
result['hardware-type'] = struct.unpack("!I", result['hardware-type'])
result['hardware-type'] = struct.unpack("!I", result[to_bytes('hardware-type')])
return result
@ -192,11 +192,11 @@ class OmapiHostManager:
# If host was not found using macaddr, add create message
if host_response is None:
msg = OmapiMessage.open(to_bytes('host', errors='surrogate_or_strict'))
msg.message.append(('create', struct.pack('!I', 1)))
msg.message.append(('exclusive', struct.pack('!I', 1)))
msg.obj.append(('hardware-address', pack_mac(self.module.params['macaddr'])))
msg.obj.append(('hardware-type', struct.pack('!I', 1)))
msg.obj.append(('name', self.module.params['hostname']))
msg.message.append((to_bytes('create'), struct.pack('!I', 1)))
msg.message.append((to_bytes('exclusive'), struct.pack('!I', 1)))
msg.obj.append((to_bytes('hardware-address'), pack_mac(self.module.params['macaddr'])))
msg.obj.append((to_bytes('hardware-type'), struct.pack('!I', 1)))
msg.obj.append((to_bytes('name'), to_bytes(self.module.params['hostname'])))
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'])))
@ -212,7 +212,7 @@ class OmapiHostManager:
self.module.fail_json(msg="Invalid statements found: %s" % to_native(e))
if len(stmt_join) > 0:
msg.obj.append(('statements', stmt_join))
msg.obj.append((to_bytes('statements'), to_bytes(stmt_join)))
try:
response = self.omapi.query_server(msg)