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:
2014-03-11 18:57:19 +01:00
parent f2154e2322
commit d7b04ebed0
4 changed files with 203 additions and 160 deletions

View File

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