diff --git a/client/ipa-client-install b/client/ipa-client-install index 6330f1d28..535fe65da 100755 --- a/client/ipa-client-install +++ b/client/ipa-client-install @@ -55,7 +55,9 @@ try: from ipalib import api, errors from ipalib import x509, certstore from ipalib.util import ( - normalize_hostname, validate_domain_name, verify_host_resolvable) + normalize_hostname, validate_domain_name, verify_host_resolvable, + network_ip_address_warning, broadcast_ip_address_warning + ) from ipalib.constants import CACERT from ipapython.dn import DN from ipapython.ssh import SSHPublicKey @@ -1651,19 +1653,8 @@ def update_dns(server, hostname, options): root_logger.info("Failed to determine this machine's ip address(es).") return - for ip in update_ips: - if ip.is_network_addr(): - root_logger.warning("IP address %s might be network address", ip) - # fixme: once when loggers will be fixed, we can remove this print - print( - "WARNING: IP address {} might be network address".format(ip), - file=sys.stderr) - if ip.is_broadcast_addr(): - root_logger.warning("IP address %s might be broadcast address", ip) - # fixme: once when loggers will be fixed, we can remove this print - print( - "WARNING: IP address {} might be broadcast address".format(ip), - file=sys.stderr) + network_ip_address_warning(update_ips) + broadcast_ip_address_warning(update_ips) update_txt = "debug\n" update_txt += ipautil.template_str(DELETE_TEMPLATE_A, diff --git a/ipalib/util.py b/ipalib/util.py index 805774006..785dd5fd4 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -21,7 +21,10 @@ Various utility functions. """ -from __future__ import absolute_import +from __future__ import ( + absolute_import, + print_function, +) import os import socket @@ -29,6 +32,7 @@ import re import decimal import dns import encodings +import sys from weakref import WeakKeyDictionary import netaddr @@ -45,6 +49,7 @@ from ipapython.ssh import SSHPublicKey from ipapython.dn import DN, RDN from ipapython.dnsutil import DNSName from ipapython.dnsutil import resolve_ip_addresses +from ipapython.ipa_log_manager import root_logger if six.PY3: unicode = str @@ -994,3 +999,23 @@ def check_principal_realm_in_trust_namespace(api_instance, *keys): name='krbprincipalname', error=_('realm or UPN suffix overlaps with trusted domain ' 'namespace')) + + +def network_ip_address_warning(addr_list): + for ip in addr_list: + if ip.is_network_addr(): + root_logger.warning("IP address %s might be network address", ip) + # fixme: once when loggers will be fixed, we can remove this + # print + print("WARNING: IP address {} might be network address".format(ip), + file=sys.stderr) + + +def broadcast_ip_address_warning(addr_list): + for ip in addr_list: + if ip.is_broadcast_addr(): + root_logger.warning("IP address %s might be broadcast address", ip) + # fixme: once when loggers will be fixed, we can remove this + # print + print("WARNING: IP address {} might be broadcast address".format( + ip), file=sys.stderr) diff --git a/ipaserver/install/server/install.py b/ipaserver/install/server/install.py index 2ef9bdb76..7733106d0 100644 --- a/ipaserver/install/server/install.py +++ b/ipaserver/install/server/install.py @@ -31,7 +31,11 @@ from ipaplatform.paths import paths from ipaplatform.tasks import tasks from ipalib import api, constants, errors, x509 from ipalib.constants import CACERT -from ipalib.util import validate_domain_name +from ipalib.util import ( + validate_domain_name, + network_ip_address_warning, + broadcast_ip_address_warning, +) import ipaclient.ntpconf from ipaserver.install import ( bindinstance, ca, cainstance, certs, dns, dsinstance, @@ -609,19 +613,8 @@ def install_check(installer): not installer.interactive, False, options.ip_addresses) - for ip in ip_addresses: - if ip.is_network_addr(): - root_logger.warning("IP address %s might be network address", ip) - # fixme: once when loggers will be fixed, we can remove this print - print( - "WARNING: IP address {} might be network address".format(ip), - file=sys.stderr) - if ip.is_broadcast_addr(): - root_logger.warning("IP address %s might be broadcast address", ip) - # fixme: once when loggers will be fixed, we can remove this print - print( - "WARNING: IP address {} might be broadcast address".format(ip), - file=sys.stderr) + network_ip_address_warning(ip_addresses) + broadcast_ip_address_warning(ip_addresses) # installer needs to update hosts file when DNS subsystem will be # installed or custom addresses are used diff --git a/ipaserver/install/server/replicainstall.py b/ipaserver/install/server/replicainstall.py index 5edc0021b..d835052e1 100644 --- a/ipaserver/install/server/replicainstall.py +++ b/ipaserver/install/server/replicainstall.py @@ -13,7 +13,6 @@ import dns.reversename as dnsreversename import os import shutil import socket -import sys import tempfile import six @@ -28,6 +27,10 @@ from ipaplatform import services from ipaplatform.tasks import tasks from ipaplatform.paths import paths from ipalib import api, certstore, constants, create_api, errors, rpc, x509 +from ipalib.util import ( + network_ip_address_warning, + broadcast_ip_address_warning, +) import ipaclient.ipachangeconf import ipaclient.ntpconf from ipaserver.install import ( @@ -736,27 +739,8 @@ def install_check(installer): config.host_name, not installer.interactive, False, options.ip_addresses) - for ip in config.ips: - if ip.is_network_addr(): - root_logger.warning( - "IP address %s might be network address", ip) - # fixme: once when loggers will be fixed, we can remove this - # print - print( - "WARNING: IP address {} might be network address".format( - ip), - file=sys.stderr - ) - if ip.is_broadcast_addr(): - root_logger.warning( - "IP address %s might be broadcast address", ip) - # fixme: once when loggers will be fixed, we can remove this - # print - print( - "WARNING: IP address {} might be broadcast address".format( - ip), - file=sys.stderr - ) + network_ip_address_warning(config.ips) + broadcast_ip_address_warning(config.ips) except errors.ACIError: raise ScriptError("\nThe password provided is incorrect for LDAP server " @@ -1329,25 +1313,8 @@ def promote_check(installer): config.host_name, not installer.interactive, False, options.ip_addresses) - for ip in config.ips: - if ip.is_network_addr(): - root_logger.warning( - "IP address %s might be network address", ip) - # fixme: once when loggers will be fixed, we can remove this - # print - print( - "WARNING: IP address {} might be network address".format( - ip), file=sys.stderr - ) - if ip.is_broadcast_addr(): - root_logger.warning( - "IP address %s might be broadcast address", ip) - # fixme: once when loggers will be fixed, we can remove this - # print - print( - "WARNING: IP address {} might be broadcast address".format( - ip), file=sys.stderr - ) + network_ip_address_warning(config.ips) + broadcast_ip_address_warning(config.ips) except errors.ACIError: raise ScriptError("\nInsufficient privileges to promote the server.")