1
0
mirror of https://github.com/rancher/os.git synced 2025-08-02 07:24:28 +00:00

Call dhcp release on interfaces that are dhcp:false

and then remove any non-specified IP addresses from them too

Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
Sven Dowideit 2017-03-30 12:29:32 +00:00
parent d35e0e05d8
commit ac5cb304d6
3 changed files with 28 additions and 13 deletions

View File

@ -395,7 +395,7 @@ func layDownOS(image, installType, cloudConfig, device, partition, kappend strin
CONSOLE := "tty0"
baseName := "/mnt/new_img"
bootDir := "boot/"
kernelArgs := "rancher.state.dev=LABEL=RANCHER_STATE rancher.state.wait printk.devkmsg=on" // console="+CONSOLE
kernelArgs := "printk.devkmsg=on rancher.state.dev=LABEL=RANCHER_STATE rancher.state.wait" // console="+CONSOLE
// unmount on trap
defer util.Unmount(baseName)
@ -1027,6 +1027,7 @@ func installRancher(baseName, bootDir, VERSION, DIST, kappend string) (string, e
}
}
os.Rename(currentCfg, previousCfg)
// TODO: now that we're parsing syslinux.cfg files, maybe we can delete old kernels and initrds
}
// The image/ISO have all the files in it - the syslinux cfg's and the kernel&initrd, so we can copy them all from there
@ -1039,7 +1040,6 @@ func installRancher(baseName, bootDir, VERSION, DIST, kappend string) (string, e
log.Errorf("copy %s: %s", file.Name(), err)
//return err
}
log.Debugf("copied %s to %s as %s", filepath.Join(DIST, file.Name()), filepath.Join(baseName, bootDir), file.Name())
}
// the general INCLUDE syslinuxcfg
if err := dfs.CopyFile(filepath.Join(DIST, "isolinux", "isolinux.cfg"), filepath.Join(baseName, bootDir, "syslinux"), "syslinux.cfg"); err != nil {

View File

@ -43,10 +43,12 @@ func ApplyNetworkConfig(cfg *config.CloudConfig) {
// TODO: seems wrong to do this outside netconf
userSetHostname := cfg.Hostname != ""
log.Infof("Apply Network Config RunDhcp")
if err := netconf.RunDhcp(&cfg.Rancher.Network, !userSetHostname, !userSetDNS); err != nil {
log.Error(err)
}
log.Infof("Apply Network Config SyncHostname")
if err := hostname.SyncHostname(); err != nil {
log.Error(err)
}

View File

@ -24,6 +24,7 @@ const (
var (
defaultDhcpArgs = []string{"dhcpcd", "-MA4"}
dhcpReleaseCmd = "dhcpcd --release"
)
func createInterfaces(netCfg *NetworkConfig) {
@ -186,10 +187,12 @@ func ApplyNetworkConfigs(netCfg *NetworkConfig) error {
}
func RunDhcp(netCfg *NetworkConfig, setHostname, setDNS bool) error {
log.Debugf("RunDhcp")
populateDefault(netCfg)
links, err := netlink.LinkList()
if err != nil {
log.Errorf("RunDhcp failed to get LinkList, %s", err)
return err
}
@ -197,21 +200,26 @@ func RunDhcp(netCfg *NetworkConfig, setHostname, setDNS bool) error {
for _, link := range links {
name := link.Attrs().Name
args := ""
if match, ok := findMatch(link, netCfg); ok && match.DHCP {
args = match.DHCPArgs
} else {
args = "dhcpd --release"
if name == "lo" {
continue
}
match, ok := findMatch(link, netCfg)
if !ok {
continue
}
wg.Add(1)
go func(iface, args string) {
runDhcp(netCfg, iface, args, setHostname, setDNS)
go func(iface string, match InterfaceConfig) {
if match.DHCP {
runDhcp(netCfg, iface, match.DHCPArgs, setHostname, setDNS)
} else {
runDhcp(netCfg, iface, dhcpReleaseCmd, false, true)
}
wg.Done()
}(name, args)
}(name, match)
}
wg.Wait()
return err
return nil
}
func runDhcp(netCfg *NetworkConfig, iface string, argstr string, setHostname, setDNS bool) {
@ -387,8 +395,13 @@ func applyInterfaceConfig(link netlink.Link, netConf InterfaceConfig) error {
}
for _, addr := range existingAddrs {
if _, ok := addrMap[addr.IPNet.String()]; !ok {
log.Infof("leaving %s from %s", addr.String(), link.Attrs().Name)
//removeAddress(addr, link)
if netConf.DHCP {
// let the dhcpcd take care of it
log.Infof("leaving %s from %s", addr.String(), link.Attrs().Name)
} else {
log.Infof("removing %s from %s", addr.String(), link.Attrs().Name)
removeAddress(addr, link)
}
}
}