From 17ecb2d824242ab1a1fb3885b21c961fe76d625d Mon Sep 17 00:00:00 2001 From: Andrey Limachko Date: Fri, 25 Feb 2022 17:40:55 +0400 Subject: [PATCH] Python3 support fixes --- library/proxmox_kvm.py | 8 ++++---- plugins/filters.py | 4 ++-- roles/inventory/templates/ssh_config | 2 +- roles/inventory/templates/ssh_config-bootstrap | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/library/proxmox_kvm.py b/library/proxmox_kvm.py index 52b5b57..78dc25a 100644 --- a/library/proxmox_kvm.py +++ b/library/proxmox_kvm.py @@ -644,7 +644,7 @@ def get_vminfo(module, proxmox, node, vmid, **kwargs): kwargs = dict((k, v) for k, v in kwargs.items() if v is not None) # Convert all dict in kwargs to elements. For hostpci[n], ide[n], net[n], numa[n], parallel[n], sata[n], scsi[n], serial[n], virtio[n] - for k in kwargs.keys(): + for k in list(kwargs.keys()): if isinstance(kwargs[k], dict): kwargs.update(kwargs[k]) del kwargs[k] @@ -730,7 +730,7 @@ def create_vm(module, proxmox, vmid, newid, node, name, memory, cpu, cores, sock #kwargs['net'][n]['virtio'] = results['mac'][n] # Convert all dict in kwargs to elements. For hostpci[n], ide[n], net[n], numa[n], parallel[n], sata[n], scsi[n], serial[n], virtio[n] - for k in kwargs.keys(): + for k in list(kwargs.keys()): if isinstance(kwargs[k], dict): kwargs.update(kwargs[k]) del kwargs[k] @@ -1067,9 +1067,9 @@ def main(): module.exit_json(changed=True, msg="VM %s with vmid %s deployed" % (name, vmid), **results) except Exception as e: if update: - module.fail_json(msg="Unable to update vm {} with vimd {}=".format(name, vmid) + str(e)) + module.fail_json(msg="Unable to update vm {} with vimd {} = {}".format(name, vmid, str(e))) elif clone is not None: - module.fail_json(msg="Unable to clone vm {} from vimd {}=".format(name, vmid) + str(e)) + module.fail_json(msg="Unable to clone vm {} from vimd {} = {}".format(name, vmid, str(e))) else: module.fail_json(msg="creation of %s VM %s with vmid %s failed with exception=%s" % (VZ_TYPE, name, vmid, e)) diff --git a/plugins/filters.py b/plugins/filters.py index 5298cfb..4a093d7 100644 --- a/plugins/filters.py +++ b/plugins/filters.py @@ -36,7 +36,7 @@ def dict_merge(dct, merge_dct): :param merge_dct: dct merged into dct :return: None """ - for k, v in merge_dct.iteritems(): + for k, v in merge_dct.items(): if (k in dct and isinstance(dct[k], dict) and isinstance(merge_dct[k], collections.Mapping)): dict_merge(dct[k], merge_dct[k]) @@ -115,7 +115,7 @@ def get_steps(node, steps_list): def filter_dict(src, pred): p = eval(pred) - return { k: v for k, v in src.iteritems() if p(v)} + return { k: v for k, v in src.items() if p(v)} def format2(what, fmt): return fmt % what diff --git a/roles/inventory/templates/ssh_config b/roles/inventory/templates/ssh_config index bea1f15..45d81a3 100644 --- a/roles/inventory/templates/ssh_config +++ b/roles/inventory/templates/ssh_config @@ -1,4 +1,4 @@ -{% for node_name, node in stack.nodes.iteritems() %} +{% for node_name, node in stack.nodes.items() %} Host {{node_name}}.{{stack.domain}} {{node_name}} HostName {{node.net.eth0.ipv4[0]|ipaddr('address')}} User root diff --git a/roles/inventory/templates/ssh_config-bootstrap b/roles/inventory/templates/ssh_config-bootstrap index ff3ff52..cf65e2a 100644 --- a/roles/inventory/templates/ssh_config-bootstrap +++ b/roles/inventory/templates/ssh_config-bootstrap @@ -1,4 +1,4 @@ -{% for node_name, node in stack.nodes.iteritems() %} +{% for node_name, node in stack.nodes.items() %} Host {{node_name}}.{{stack.domain}} {{node_name}} {% if node.nics is defined %} HostName {{node.nics.eth0.addrs[0]|ipaddr('address')}}