Clean up of IP address checks in install scripts.

Fixes ipa-dns-install incorrect warning.

ticket 1486
This commit is contained in:
Jan Cholasta 2011-07-18 13:36:47 +02:00 committed by Martin Kosek
parent 9869b0971d
commit c09f116f43
4 changed files with 13 additions and 38 deletions

View File

@ -112,13 +112,11 @@ def main():
ip = options.ip_address ip = options.ip_address
else: else:
hostaddr = resolve_host(api.env.host) hostaddr = resolve_host(api.env.host)
ip = hostaddr and ipautil.CheckedIPAddress(hostaddr) try:
ip = hostaddr and ipautil.CheckedIPAddress(hostaddr, match_local=True)
try: except Exception, e:
verify_ip_address(ip) print "Error: Invalid IP Address %s: %s" % (ip, e)
except Exception, e: ip = None
print "Error: Invalid IP Address %s: %s" % (ip, e)
ip = None
if not ip: if not ip:
if options.unattended: if options.unattended:

View File

@ -186,7 +186,7 @@ def install_bind(config, options):
ip_address = resolve_host(config.host_name) ip_address = resolve_host(config.host_name)
if not ip_address: if not ip_address:
sys.exit("Unable to resolve IP address for host name") sys.exit("Unable to resolve IP address for host name")
ip = installutils.parse_ip_address(ip_address) ip = ipautil.CheckedIPAddress(ip_address, match_local=True)
ip_address = str(ip) ip_address = str(ip)
if options.reverse_zone: if options.reverse_zone:
@ -225,7 +225,7 @@ def install_dns_records(config, options):
ip_address = resolve_host(config.host_name) ip_address = resolve_host(config.host_name)
if not ip_address: if not ip_address:
sys.exit("Unable to resolve IP address for host name") sys.exit("Unable to resolve IP address for host name")
ip = installutils.parse_ip_address(ip_address) ip = ipautil.CheckedIPAddress(ip_address, match_local=True)
ip_address = str(ip) ip_address = str(ip)
reverse_zone = bindinstance.find_reverse_zone(ip) reverse_zone = bindinstance.find_reverse_zone(ip)

View File

@ -628,20 +628,11 @@ def main():
if hostaddr is not None: if hostaddr is not None:
ip = CheckedIPAddress(hostaddr, match_local=True) ip = CheckedIPAddress(hostaddr, match_local=True)
else: else:
if not options.ip_address:
print "Unable to resolve IP address for host name"
ip = options.ip_address ip = options.ip_address
if ip is None and options.unattended: if ip is None:
sys.exit("Unable to resolve IP address for host name") print "Unable to resolve IP address for host name"
if options.unattended:
if ip: sys.exit(1)
try:
verify_ip_address(ip)
except Exception, e:
print "Error: Invalid IP Address %s: %s" % (ip, e)
if options.unattended:
sys.exit(1)
ip = None
if options.ip_address: if options.ip_address:
if options.ip_address != ip and not options.setup_dns: if options.ip_address != ip and not options.setup_dns:
@ -651,11 +642,6 @@ def main():
return 1 return 1
ip = options.ip_address ip = options.ip_address
try:
verify_ip_address(ip)
except Exception, e:
print "Error: Invalid IP Address %s: %s" % (ip, e)
sys.exit(1)
if ip is None: if ip is None:
ip = read_ip_address(host_name, fstore) ip = read_ip_address(host_name, fstore)

View File

@ -163,15 +163,6 @@ def verify_fqdn(host_name,no_host_dns=False):
else: else:
print "Warning: Hostname (%s) not found in DNS" % host_name print "Warning: Hostname (%s) not found in DNS" % host_name
def parse_ip_address(addr, match_local=True, parse_netmask=True):
ip = ipautil.CheckedIPAddress(addr, match_local=match_local, parse_netmask=parse_netmask)
if match_local and not ip.is_local():
print "Warning: No network interface matches IP address %s" % addr
return ip
def verify_ip_address(addr, match_local=True, parse_netmask=True):
ip = parse_ip_address(addr, match_local, parse_netmask)
def record_in_hosts(ip, host_name, file="/etc/hosts"): def record_in_hosts(ip, host_name, file="/etc/hosts"):
hosts = open(file, 'r').readlines() hosts = open(file, 'r').readlines()
for line in hosts: for line in hosts:
@ -204,7 +195,7 @@ def read_ip_address(host_name, fstore):
while True: while True:
ip = ipautil.user_input("Please provide the IP address to be used for this host name", allow_empty = False) ip = ipautil.user_input("Please provide the IP address to be used for this host name", allow_empty = False)
try: try:
ip_parsed = parse_ip_address(ip) ip_parsed = ipautil.CheckedIPAddress(ip, match_local=True)
except Exception, e: except Exception, e:
print "Error: Invalid IP Address %s: %s" % (ip, e) print "Error: Invalid IP Address %s: %s" % (ip, e)
continue continue
@ -229,7 +220,7 @@ def read_dns_forwarders():
if not ip: if not ip:
break break
try: try:
ip_parsed = parse_ip_address(ip, match_local=False, parse_netmask=False) ip_parsed = ipautil.CheckedIPAddress(ip, parse_netmask=False)
except Exception, e: except Exception, e:
print "Error: Invalid IP Address %s: %s" % (ip, e) print "Error: Invalid IP Address %s: %s" % (ip, e)
print "DNS forwarder %s not added" % ip print "DNS forwarder %s not added" % ip