summaryrefslogtreecommitdiffstats
path: root/ipapython
diff options
context:
space:
mode:
authorMartin Kosek <mkosek@redhat.com>2011-06-16 10:47:11 +0200
committerRob Crittenden <rcritten@redhat.com>2011-06-19 20:06:21 -0400
commitd9808498a82fa8662e5bc1bc1fca4d175fe9447c (patch)
treeaf0a953504c741482ea7901985bb87c65dc0023b /ipapython
parent79ce958a3c9e182a4b4ee0850d7315fdd51982d7 (diff)
downloadfreeipa-d9808498a82fa8662e5bc1bc1fca4d175fe9447c.tar.gz
freeipa-d9808498a82fa8662e5bc1bc1fca4d175fe9447c.tar.xz
freeipa-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.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/ipapython/config.py b/ipapython/config.py
index c78508541..051e39f92 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):
"""