Fix fqdn hostnames not added to /etc/hosts

This fixes an issue where using a fqdn as hostname
not being added to /etc/hosts.

The etchosts.Build() function was never called
with an IP-address, therefore the fqdn was not
added.

The subsequent updateHostsFile() was not updated
to support fqdn's as hostname, and not adding
the record correctly to /etc/hosts.

This patch implements the functionality in
updateHostsFile()

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2016-12-09 14:25:46 +01:00
parent 16b9fc994e
commit 6c3fc691e7
1 changed files with 10 additions and 6 deletions

View File

@ -100,8 +100,6 @@ func (sb *sandbox) buildHostsFile() error {
}
func (sb *sandbox) updateHostsFile(ifaceIP string) error {
var mhost string
if ifaceIP == "" {
return nil
}
@ -110,11 +108,17 @@ func (sb *sandbox) updateHostsFile(ifaceIP string) error {
return nil
}
// User might have provided a FQDN in hostname or split it across hostname
// and domainname. We want the FQDN and the bare hostname.
fqdn := sb.config.hostName
mhost := sb.config.hostName
if sb.config.domainName != "" {
mhost = fmt.Sprintf("%s.%s %s", sb.config.hostName, sb.config.domainName,
sb.config.hostName)
} else {
mhost = sb.config.hostName
fqdn = fmt.Sprintf("%s.%s", fqdn, sb.config.domainName)
}
parts := strings.SplitN(fqdn, ".", 2)
if len(parts) == 2 {
mhost = fmt.Sprintf("%s %s", fqdn, parts[0])
}
extraContent := []etchosts.Record{{Hosts: mhost, IP: ifaceIP}}