install: use standard Python classes to declare knob types

Use type(None) rather than bool to define knobs which are represented as
command line flags. This allows declaring both "--option" and
"--option={0,1}"-style command line options.

Use enum.Enum subclasses instead of set literals to declare enumerations.

Use typing.List[T] instead of (list, T) to declare lists. (Note that a
minimal reimplementation of typing.List is used instead of the Python 2
backport of the typing module due to non-technical reasons.)

Use CheckedIPAddress instead of 'ip' and 'ip-local' to declare IP
addresses.

https://fedorahosted.org/freeipa/ticket/6392

Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
Jan Cholasta
2016-11-07 14:01:10 +01:00
parent 9fd1981ae8
commit a929ac3338
5 changed files with 96 additions and 13 deletions

View File

@@ -10,6 +10,7 @@ import sys
import six
from ipapython.dn import DN
from ipapython.ipautil import CheckedIPAddress
from ipapython.install import common, core
from ipapython.install.core import Knob
from ipalib.util import validate_domain_name
@@ -308,13 +309,22 @@ class BaseServer(common.Installable, common.Interactive, core.Composite):
)
ip_addresses = Knob(
(list, 'ip-local'), None,
(list, 'ip'), None,
description=("Master Server IP Address. This option can be used "
"multiple times"),
cli_name='ip-address',
cli_metavar='IP_ADDRESS',
)
@ip_addresses.validator
def ip_addresses(self, values):
for value in values:
try:
CheckedIPAddress(value, match_local=True)
except Exception as e:
raise ValueError("invalid IP address {0}: {1}".format(
value, e))
no_host_dns = Knob(
bool, False,
description="Do not use DNS for hostname lookup during installation",