diff options
author | Martin Kosek <mkosek@redhat.com> | 2011-06-16 10:47:11 +0200 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2011-06-19 20:06:21 -0400 |
commit | d9808498a82fa8662e5bc1bc1fca4d175fe9447c (patch) | |
tree | af0a953504c741482ea7901985bb87c65dc0023b /ipapython | |
parent | 79ce958a3c9e182a4b4ee0850d7315fdd51982d7 (diff) | |
download | freeipa.git-d9808498a82fa8662e5bc1bc1fca4d175fe9447c.tar.gz freeipa.git-d9808498a82fa8662e5bc1bc1fca4d175fe9447c.tar.xz freeipa.git-d9808498a82fa8662e5bc1bc1fca4d175fe9447c.zip |
Improve IP address handling in IPA option parser
Implements a way to pass match_local and parse_netmask parameters
to IP option checker.
Now, there is just one common option type "ip" with new optional
attributes "ip_local" and "ip_netmask" which can be used to
pass IP address validation parameters.
https://fedorahosted.org/freeipa/ticket/1333
Diffstat (limited to 'ipapython')
-rw-r--r-- | ipapython/config.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/ipapython/config.py b/ipapython/config.py index c7850854..051e39f9 100644 --- a/ipapython/config.py +++ b/ipapython/config.py @@ -49,8 +49,11 @@ class IPAFormatter(IndentedHelpFormatter): def check_ip_option(option, opt, value): from ipapython.ipautil import CheckedIPAddress + + ip_local = option.ip_local is True + ip_netmask = option.ip_netmask is True try: - return CheckedIPAddress(value, parse_netmask=(option.type == "ipnet")) + return CheckedIPAddress(value, parse_netmask=ip_netmask, match_local=ip_local) except Exception as e: raise OptionValueError("option %s: invalid IP address %s: %s" % (opt, value, e)) @@ -59,10 +62,10 @@ class IPAOption(Option): optparse.Option subclass with support of options labeled as security-sensitive such as passwords. """ - ATTRS = Option.ATTRS + ["sensitive"] - TYPES = Option.TYPES + ("ipaddr", "ipnet") + ATTRS = Option.ATTRS + ["sensitive", "ip_local", "ip_netmask"] + TYPES = Option.TYPES + ("ip",) TYPE_CHECKER = copy(Option.TYPE_CHECKER) - TYPE_CHECKER["ipaddr"] = TYPE_CHECKER["ipnet"] = check_ip_option + TYPE_CHECKER["ip"] = check_ip_option class IPAOptionParser(OptionParser): """ |