1
0
mirror of https://github.com/rancher/os.git synced 2025-09-16 23:21:19 +00:00

Fix DHCP hostname being overwritten

This commit is contained in:
Josh Curl
2016-04-14 21:58:07 -07:00
parent 447a96a5f8
commit a0ae6222c9
11 changed files with 152 additions and 62 deletions

View File

@@ -22,7 +22,6 @@ import (
"os"
"strings"
"sync"
"syscall"
"time"
yaml "github.com/cloudfoundry-incubator/candiedyaml"
@@ -169,32 +168,12 @@ func fetchUserData() ([]byte, datasource.Metadata, error) {
return userDataBytes, metadata, nil
}
func SetHostname(cc *rancherConfig.CloudConfig) (string, error) {
name, _ := os.Hostname()
if cc.Hostname != "" {
name = cc.Hostname
}
if name != "" {
//set hostname
if err := syscall.Sethostname([]byte(name)); err != nil {
log.WithFields(log.Fields{"err": err, "hostname": name}).Error("Error setting hostname")
return "", err
}
}
return name, nil
}
func executeCloudConfig() error {
cc, err := rancherConfig.LoadConfig()
if err != nil {
return err
}
if _, err := SetHostname(cc); err != nil {
return err
}
if len(cc.SSHAuthorizedKeys) > 0 {
authorizeSSHKeys("rancher", cc.SSHAuthorizedKeys, sshKeyName)
authorizeSSHKeys("docker", cc.SSHAuthorizedKeys, sshKeyName)