From 3650024b1d9290089273851c6a88185a69112eb0 Mon Sep 17 00:00:00 2001 From: Abid Khan Date: Fri, 21 Feb 2020 03:32:18 -0700 Subject: [PATCH] Fixed python3 errors Modified `network` > `networks`. Also fixed Python3 `TypeError: string indices must be integers` dict error. --- proxmox.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/proxmox.py b/proxmox.py index d22e281..f5d29ca 100755 --- a/proxmox.py +++ b/proxmox.py @@ -205,18 +205,17 @@ class ProxmoxAPI(object): ip_address = None networks = self.get('api2/json/nodes/{0}/qemu/{1}/agent/network-get-interfaces'.format(node, vm))['result'] if networks: - if type(network) is dict: + if type(networks) is dict: for network in networks: - for address in network['ip-addresses']: - ip_address = address['ip-address'] - try: - # IP address validation - if socket.inet_aton(ip_address): - # Ignore localhost - if ip_address != '127.0.0.1': - return ip_address - except socket.error: - pass + for ip_address in ['ip-address']: + try: + # IP address validation + if socket.inet_aton(ip_address): + # Ignore localhost + if ip_address != '127.0.0.1': + return ip_address + except socket.error: + pass return None def openvz_ip_address(self, node, vm):