Filter out empty ip addresses

When resetting default gateways filter out interfaces with empty
ip addresses and netmasks
Also log invalid addresses and netmasks

Change-Id: I5ad4865fff7294e837d6786da759547179dbbe65
Closes-Bug: #1543767
(cherry picked from commit 610f127425)
This commit is contained in:
Georgy Kibardin 2016-04-06 13:40:18 +03:00 committed by Fedor Zhadaev
parent acb168f2df
commit 5b9987cfc8
2 changed files with 12 additions and 2 deletions

View File

@ -134,7 +134,11 @@ def netmaskToCidr(netmask):
def addr_in_cidr_notation(ip, netmask):
return str(netaddr.IPNetwork("{0}/{1}".format(ip, netmask)))
try:
return str(netaddr.IPNetwork("{0}/{1}".format(ip, netmask)))
except Exception:
log.exception('Invalid IP address or netmask, '
'ip: "%s", netmask: "%s"', ip, netmask)
def duplicateIPExists(ip, iface, arping_bind=False):

View File

@ -231,13 +231,19 @@ class interfaces(urwid.WidgetWrap):
return responses
def clear_gateways_except(self, iface):
def include_interface(name):
return name != iface and \
self.netsettings[name].get('addr') and \
self.netsettings[name].get('netmask')
return [{'type': "resource",
'class': "l23network::l3::ifconfig",
'name': name,
'params': {'ipaddr': network.addr_in_cidr_notation(
self.netsettings[name]['addr'],
self.netsettings[name]['netmask'])}}
for name in self.netsettings if name != iface]
for name in self.netsettings if include_interface(name)]
def apply(self, args):
responses = self.check(args)