Parse domain name correctly in fuelmenu

Change-Id: I5fdbbb58dace2049265d7b59f3e2f8ebcefa92b7
Closes-Bug: #1351293
This commit is contained in:
Matthew Mosesohn 2014-08-01 16:18:38 +04:00
parent bd0127be00
commit b1dc7ecf07
2 changed files with 17 additions and 5 deletions

View File

@ -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",

View File

@ -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