diff options
author | Jan Cholasta <jcholast@redhat.com> | 2011-05-27 20:17:22 +0200 |
---|---|---|
committer | Martin Kosek <mkosek@redhat.com> | 2011-05-30 13:36:26 +0200 |
commit | 80b4b3d44bbbe745e644b56c5371ef5f4cda6600 (patch) | |
tree | 970dd0df7105626fa997330afe0b30026dfcc5bf /ipapython/config.py | |
parent | 868d4e734ed0f22221f25a1067fbf57141b64c21 (diff) | |
download | freeipa.git-80b4b3d44bbbe745e644b56c5371ef5f4cda6600.tar.gz freeipa.git-80b4b3d44bbbe745e644b56c5371ef5f4cda6600.tar.xz freeipa.git-80b4b3d44bbbe745e644b56c5371ef5f4cda6600.zip |
Parse netmasks in IP addresses passed to server install.
ticket 1212
Diffstat (limited to 'ipapython/config.py')
-rw-r--r-- | ipapython/config.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/ipapython/config.py b/ipapython/config.py index 7e5b1951..c7850854 100644 --- a/ipapython/config.py +++ b/ipapython/config.py @@ -18,7 +18,8 @@ # import ConfigParser -from optparse import Option, Values, OptionParser, IndentedHelpFormatter +from optparse import Option, Values, OptionParser, IndentedHelpFormatter, OptionValueError +from copy import copy import socket import ipapython.dnsclient @@ -46,12 +47,22 @@ class IPAFormatter(IndentedHelpFormatter): ret += "%s %s\n" % (spacing, line) return ret +def check_ip_option(option, opt, value): + from ipapython.ipautil import CheckedIPAddress + try: + return CheckedIPAddress(value, parse_netmask=(option.type == "ipnet")) + except Exception as e: + raise OptionValueError("option %s: invalid IP address %s: %s" % (opt, value, e)) + 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") + TYPE_CHECKER = copy(Option.TYPE_CHECKER) + TYPE_CHECKER["ipaddr"] = TYPE_CHECKER["ipnet"] = check_ip_option class IPAOptionParser(OptionParser): """ |