1
0
mirror of https://github.com/rancher/os.git synced 2025-08-15 21:43:42 +00:00

Merge pull request #633 from ibuildthecloud/hostname-dhcp

Set hostname prior to running DHCP
This commit is contained in:
Ivan Mikushin 2015-11-06 09:34:53 +05:00
commit c11a0739dd
2 changed files with 17 additions and 5 deletions

View File

@ -168,17 +168,26 @@ func fetchUserData() ([]byte, datasource.Metadata, error) {
return userDataBytes, metadata, nil
}
func SetHostname(cc *rancherConfig.CloudConfig) error {
if cc.Hostname != "" {
//set hostname
if err := hostname.SetHostname(cc.Hostname); err != nil {
log.WithFields(log.Fields{"err": err, "hostname": cc.Hostname}).Error("Error setting hostname")
return err
}
}
return nil
}
func executeCloudConfig() error {
cc, err := rancherConfig.LoadConfig()
if err != nil {
return err
}
if cc.Hostname != "" {
//set hostname
if err := hostname.SetHostname(cc.Hostname); err != nil {
log.WithFields(log.Fields{"err": err, "hostname": cc.Hostname}).Error("Error setting hostname")
}
if err := SetHostname(cc); err != nil {
return err
}
if len(cc.SSHAuthorizedKeys) > 0 {

View File

@ -7,6 +7,7 @@ import (
log "github.com/Sirupsen/logrus"
"github.com/rancher/netconf"
"github.com/rancher/os/cmd/cloudinit"
"github.com/rancher/os/config"
)
@ -20,6 +21,8 @@ func Main() {
if err != nil {
log.Fatal(err)
}
// Purposely ignore error
cloudinit.SetHostname(cfg)
if err := netconf.ApplyNetworkConfigs(&cfg.Rancher.Network); err != nil {
log.Fatal(err)
}