1
0
mirror of https://github.com/rancher/os.git synced 2025-09-06 09:14:31 +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

@@ -23,7 +23,7 @@ const (
)
var (
defaultDhcpArgs = []string{"dhcpcd", "-MA4", "-e", "force_hostname=true"}
defaultDhcpArgs = []string{"dhcpcd", "-MA4"}
)
func createInterfaces(netCfg *NetworkConfig) {
@@ -168,36 +168,48 @@ func ApplyNetworkConfigs(netCfg *NetworkConfig) error {
return err
}
dhcpLinks := map[string]string{}
//apply network config
for _, link := range links {
linkName := link.Attrs().Name
if match, ok := findMatch(link, netCfg); ok {
if match.DHCP {
dhcpLinks[link.Attrs().Name] = match.DHCPArgs
} else if err = applyInterfaceConfig(link, match); err != nil {
if match, ok := findMatch(link, netCfg); ok && !match.DHCP {
if err := applyInterfaceConfig(link, match); err != nil {
log.Errorf("Failed to apply settings to %s : %v", linkName, err)
}
}
}
runCmds(netCfg.PostCmds, "")
return err
}
func RunDhcp(netCfg *NetworkConfig, dhcpHostname bool) error {
links, err := netlink.LinkList()
if err != nil {
return err
}
dhcpLinks := map[string]string{}
for _, link := range links {
if match, ok := findMatch(link, netCfg); ok && match.DHCP {
dhcpLinks[link.Attrs().Name] = match.DHCPArgs
}
}
//run dhcp
wg := sync.WaitGroup{}
for iface, args := range dhcpLinks {
wg.Add(1)
go func(iface, args string) {
runDhcp(netCfg, iface, args)
runDhcp(netCfg, iface, args, dhcpHostname)
wg.Done()
}(iface, args)
}
wg.Wait()
runCmds(netCfg.PostCmds, "")
return err
}
func runDhcp(netCfg *NetworkConfig, iface string, argstr string) {
func runDhcp(netCfg *NetworkConfig, iface string, argstr string, dhcpHostname bool) {
log.Infof("Running DHCP on %s", iface)
args := []string{}
if argstr != "" {
@@ -215,6 +227,10 @@ func runDhcp(netCfg *NetworkConfig, iface string, argstr string) {
args = append(args, "--nohook", "resolv.conf")
}
if dhcpHostname {
args = append(args, "-e", "force_hostname=true")
}
args = append(args, iface)
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdout = os.Stdout