Add error handling

Check network is a valid object
This commit is contained in:
Xabi Ezpeleta 2020-02-03 12:08:50 +01:00
parent e05f224c8c
commit 02cce4d567
1 changed files with 12 additions and 11 deletions

View File

@ -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):