simplify netmaskoption

This commit is contained in:
Emmanuel Garette 2019-02-25 19:10:20 +01:00
parent 9c459e21b1
commit 0e20318a9b
1 changed files with 19 additions and 20 deletions

View File

@ -77,29 +77,28 @@ class NetmaskOption(StrOption):
warnings_only,
context,
_cidr=False):
# opts must be (netmask, ip) options
if context is undefined and len(vals) != 2:
raise ConfigError(_('ip_netmask needs an IP and a netmask'))
if None in vals or len(vals) != 2:
return
msg = None
val_netmask, val_ip = vals
opt_netmask, opt_ip = opts
ip = ip_interface('{0}/{1}'.format(val_ip, val_netmask))
network = ip.network
if ip.ip == network.network_address:
if not _cidr and current_opt == opts[1]:
msg = _('this is a network with netmask "{0}" ("{1}")')
if not _cidr and current_opt == opt_ip
if ip.ip == ip.network.network_address:
raise ValueError( _('this is a network with netmask "{0}" ("{1}")'
'').format(val_netmask,
opt_netmask.impl_get_display_name()))
elif ip.ip == ip.network.broadcast_address:
raise ValueError(_('this is a broadcast with netmask "{0}" ("{1}")'
'').format(val_netmask,
opt_netmask.impl_get_display_name()))
else:
msg = _('IP "{0}" ("{1}") is the network')
elif ip.ip == network.broadcast_address:
if not _cidr and current_opt == opts[1]:
msg = _('this is a broadcast with netmask "{0}" ("{1}")')
else:
msg = _('IP "{0}" ("{1}") is the broadcast')
if msg is not None:
if not _cidr and current_opt == opts[1]:
raise ValueError(msg.format(val_netmask,
opts[0].impl_get_display_name()))
else:
raise ValueError(msg.format(val_ip,
opts[1].impl_get_display_name()))
if ip.ip == ip.network.network_address:
raise ValueError(_('IP "{0}" ("{1}") is the network'
'').format(val_ip,
opt_ip.impl_get_display_name()))
elif ip.ip == ip.network.broadcast_address:
raise ValueError(_('IP "{0}" ("{1}") is the broadcast'
'')format(val_ip,
opt_ip.impl_get_display_name()))