add consistency in_network for IPOption
This new consistency can validate that an IPv4 is a specified (network/netmask) network
This commit is contained in:
@@ -784,6 +784,18 @@ class IPOption(Option):
|
||||
if self._private_only and not ip.iptype() == 'PRIVATE':
|
||||
raise ValueError(_("invalid IP, must be in private class"))
|
||||
|
||||
def _cons_in_network(self, opts, vals):
|
||||
if len(vals) != 3:
|
||||
raise ConfigError(_('invalid len for vals'))
|
||||
if None in vals:
|
||||
return
|
||||
ip, network, netmask = vals
|
||||
if IP(ip) not in IP('{0}/{1}'.format(network, netmask)):
|
||||
raise ValueError(_('invalid IP {0} ({1}) with network {2} '
|
||||
'({3}) and netmask {4} ({5})').format(
|
||||
ip, opts[0]._name, network,
|
||||
opts[1]._name, netmask, opts[2]._name))
|
||||
|
||||
|
||||
class PortOption(Option):
|
||||
"""represents the choice of a port
|
||||
|
Reference in New Issue
Block a user