From b1dc7ecf073975c5ba03163829dde74652299225 Mon Sep 17 00:00:00 2001 From: Matthew Mosesohn Date: Fri, 1 Aug 2014 16:18:38 +0400 Subject: [PATCH] Parse domain name correctly in fuelmenu Change-Id: I5fdbbb58dace2049265d7b59f3e2f8ebcefa92b7 Closes-Bug: #1351293 --- fuelmenu/fuelmenu/fuelmenu.py | 8 ++++++++ fuelmenu/fuelmenu/modules/dnsandhostname.py | 14 +++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/fuelmenu/fuelmenu/fuelmenu.py b/fuelmenu/fuelmenu/fuelmenu.py index 1cf4cc512d..1c91b2ef3d 100755 --- a/fuelmenu/fuelmenu/fuelmenu.py +++ b/fuelmenu/fuelmenu/fuelmenu.py @@ -340,6 +340,11 @@ def save_only(iface): except Exception: print("Unable to define DHCP pools") sys.exit(1) + try: + hostname, sep, domain = os.uname()[1].partition('.') + except Exception: + print("Unable to calculate hostname and domain") + sys.exit(1) settings = \ { "ADMIN_NETWORK/interface": iface, @@ -350,6 +355,9 @@ def save_only(iface): "ADMIN_NETWORK/dhcp_pool_end": dynamic_end, "ADMIN_NETWORK/static_pool_start": static_start, "ADMIN_NETWORK/static_pool_end": static_end, + "HOSTNAME": hostname, + "DNS_DOMAIN": domain, + "DNS_SEARCH": domain, "astute/user": "naily", "astute/password": pwgen.password(), "cobbler/user": "cobbler", diff --git a/fuelmenu/fuelmenu/modules/dnsandhostname.py b/fuelmenu/fuelmenu/modules/dnsandhostname.py index 13ded6d63e..2b6f33155e 100644 --- a/fuelmenu/fuelmenu/modules/dnsandhostname.py +++ b/fuelmenu/fuelmenu/modules/dnsandhostname.py @@ -20,6 +20,7 @@ import fuelmenu.common.urwidwrapper as widget from fuelmenu.settings import Settings import logging import netaddr +import os import re import socket import subprocess @@ -48,11 +49,12 @@ class dnsandhostname(urwid.WidgetWrap): "Internet access."] self.fields = ["HOSTNAME", "DNS_DOMAIN", "DNS_SEARCH", "DNS_UPSTREAM", "blank", "TEST_DNS"] + hostname, sep, domain = os.uname()[1].partition('.') self.defaults = \ { "HOSTNAME": {"label": "Hostname", "tooltip": "Hostname to use for Fuel master node", - "value": socket.gethostname().split('.')[0]}, + "value": hostname}, "DNS_UPSTREAM": {"label": "External DNS", "tooltip": "DNS server(s) (comma separated) \ to handle DNS requests (example 8.8.8.8)", @@ -60,11 +62,11 @@ to handle DNS requests (example 8.8.8.8)", "DNS_DOMAIN": {"label": "Domain", "tooltip": "Domain suffix to user for all \ nodes in your cluster", - "value": "domain.tld"}, + "value": domain}, "DNS_SEARCH": {"label": "Search Domain", "tooltip": "Domains to search when looking up \ DNS (space separated)", - "value": "domain.tld"}, + "value": domain}, "TEST_DNS": {"label": "Hostname to test DNS:", "value": "www.google.com", "tooltip": "DNS record to resolve to see if DNS \ @@ -300,8 +302,10 @@ is accessible"} continue #Read hostname if it's already set try: - import os - oldsettings["HOSTNAME"] = os.uname()[1] + hostname, sep, domain = os.uname()[1].partition('.') + oldsettings["HOSTNAME"] = hostname + oldsettings["DNS_DOMAIN"] = domain + oldsettings["DNS_SEARCH"] = domain except Exception: log.warning("Unable to look up system hostname") return oldsettings