add allow_reserved in IPOption
This commit is contained in:
parent
30c376e3ea
commit
28c416dd84
|
@ -29,6 +29,15 @@ def test_ip_default():
|
||||||
c.a == '88.88.88.88'
|
c.a == '88.88.88.88'
|
||||||
|
|
||||||
|
|
||||||
|
def test_ip_reserved():
|
||||||
|
a = IPOption('a', '')
|
||||||
|
b = IPOption('b', '', allow_reserved=True)
|
||||||
|
od = OptionDescription('od', '', [a, b])
|
||||||
|
c = Config(od)
|
||||||
|
raises(ValueError, "c.a = '226.94.1.1'")
|
||||||
|
c.b = '226.94.1.1'
|
||||||
|
|
||||||
|
|
||||||
def test_network():
|
def test_network():
|
||||||
a = NetworkOption('a', '')
|
a = NetworkOption('a', '')
|
||||||
od = OptionDescription('od', '', [a])
|
od = OptionDescription('od', '', [a])
|
||||||
|
|
|
@ -702,14 +702,15 @@ class SymLinkOption(BaseOption):
|
||||||
|
|
||||||
class IPOption(Option):
|
class IPOption(Option):
|
||||||
"represents the choice of an ip"
|
"represents the choice of an ip"
|
||||||
__slots__ = ('_only_private',)
|
__slots__ = ('_only_private', '_allow_reserved')
|
||||||
_opt_type = 'ip'
|
_opt_type = 'ip'
|
||||||
|
|
||||||
def __init__(self, name, doc, default=None, default_multi=None,
|
def __init__(self, name, doc, default=None, default_multi=None,
|
||||||
requires=None, multi=False, callback=None,
|
requires=None, multi=False, callback=None,
|
||||||
callback_params=None, validator=None, validator_params=None,
|
callback_params=None, validator=None, validator_params=None,
|
||||||
properties=None, only_private=False):
|
properties=None, only_private=False, allow_reserved=False):
|
||||||
self._only_private = only_private
|
self._only_private = only_private
|
||||||
|
self._allow_reserved = allow_reserved
|
||||||
super(IPOption, self).__init__(name, doc, default=default,
|
super(IPOption, self).__init__(name, doc, default=default,
|
||||||
default_multi=default_multi,
|
default_multi=default_multi,
|
||||||
callback=callback,
|
callback=callback,
|
||||||
|
@ -722,8 +723,8 @@ class IPOption(Option):
|
||||||
|
|
||||||
def _validate(self, value):
|
def _validate(self, value):
|
||||||
ip = IP('{0}/32'.format(value))
|
ip = IP('{0}/32'.format(value))
|
||||||
if ip.iptype() == 'RESERVED':
|
if not self._allow_reserved and ip.iptype() == 'RESERVED':
|
||||||
raise ValueError(_("IP shall not be in reserved class"))
|
raise ValueError(_("IP mustn't not be in reserved class"))
|
||||||
if self._only_private and not ip.iptype() == 'PRIVATE':
|
if self._only_private and not ip.iptype() == 'PRIVATE':
|
||||||
raise ValueError(_("IP must be in private class"))
|
raise ValueError(_("IP must be in private class"))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue