From 02cce4d56770d6901702532b4fd972e2527a337c Mon Sep 17 00:00:00 2001 From: Xabi Ezpeleta Date: Mon, 3 Feb 2020 12:08:50 +0100 Subject: [PATCH] Add error handling Check network is a valid object --- proxmox.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/proxmox.py b/proxmox.py index 8079b9e..d22e281 100755 --- a/proxmox.py +++ b/proxmox.py @@ -205,17 +205,18 @@ 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: - 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 + if type(network) 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 return None def openvz_ip_address(self, node, vm):