From 7a06dee16fe3e794fba24b89dbd4dc6adf9aa72d Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Mon, 21 Jul 2014 11:24:42 -0700 Subject: [PATCH 1/2] system: Cleanup redundant code --- system/networkd.go | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/system/networkd.go b/system/networkd.go index 4dc5f0a..a79e9de 100644 --- a/system/networkd.go +++ b/system/networkd.go @@ -2,11 +2,8 @@ package system import ( "fmt" - "io/ioutil" "net" - "os" "os/exec" - "path" "strings" "time" @@ -46,9 +43,8 @@ func downNetworkInterfaces(interfaces []network.InterfaceGenerator) error { sysInterfaceMap := make(map[string]*net.Interface) if systemInterfaces, err := net.Interfaces(); err == nil { for _, iface := range systemInterfaces { - // Need a copy of the interface so we can take the address - temp := iface - sysInterfaceMap[temp.Name] = &temp + iface := iface + sysInterfaceMap[iface.Name] = &iface } } else { return err @@ -92,15 +88,15 @@ func restartNetworkd() error { func WriteNetworkdConfigs(interfaces []network.InterfaceGenerator) error { for _, iface := range interfaces { - filename := path.Join(runtimeNetworkPath, fmt.Sprintf("%s.netdev", iface.Filename())) + filename := fmt.Sprintf("%s.netdev", iface.Filename()) if err := writeConfig(filename, iface.Netdev()); err != nil { return err } - filename = path.Join(runtimeNetworkPath, fmt.Sprintf("%s.link", iface.Filename())) + filename = fmt.Sprintf("%s.link", iface.Filename()) if err := writeConfig(filename, iface.Link()); err != nil { return err } - filename = path.Join(runtimeNetworkPath, fmt.Sprintf("%s.network", iface.Filename())) + filename = fmt.Sprintf("%s.network", iface.Filename()) if err := writeConfig(filename, iface.Network()); err != nil { return err } @@ -112,8 +108,6 @@ func writeConfig(filename string, config string) error { if config == "" { return nil } - if err := os.MkdirAll(path.Dir(filename), 0755); err != nil { - return err - } - return ioutil.WriteFile(filename, []byte(config), 0444) + _, err := WriteFile(&File{Content: config, Path: filename}, runtimeNetworkPath) + return err } From 21e32e44f86b1cc33e61d745a3e944dfdc2bf3e7 Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Mon, 21 Jul 2014 11:25:22 -0700 Subject: [PATCH 2/2] system: Add more logging for networkd --- system/networkd.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/system/networkd.go b/system/networkd.go index a79e9de..0b0ffa7 100644 --- a/system/networkd.go +++ b/system/networkd.go @@ -2,6 +2,7 @@ package system import ( "fmt" + "log" "net" "os/exec" "strings" @@ -52,6 +53,7 @@ func downNetworkInterfaces(interfaces []network.InterfaceGenerator) error { for _, iface := range interfaces { if systemInterface, ok := sysInterfaceMap[iface.Name()]; ok { + log.Printf("Taking down interface %q\n", systemInterface.Name) if err := netlink.NetworkLinkDown(systemInterface); err != nil { fmt.Printf("Error while downing interface %q (%s). Continuing...\n", systemInterface.Name, err) } @@ -64,6 +66,7 @@ func downNetworkInterfaces(interfaces []network.InterfaceGenerator) error { func maybeProbe8012q(interfaces []network.InterfaceGenerator) error { for _, iface := range interfaces { if iface.Type() == "vlan" { + log.Printf("Probing LKM %q (%q)\n", "8021q", "8021q") return exec.Command("modprobe", "8021q").Run() } } @@ -78,10 +81,12 @@ func maybeProbeBonding(interfaces []network.InterfaceGenerator) error { break } } + log.Printf("Probing LKM %q (%q)\n", "bonding", args) return exec.Command("modprobe", args...).Run() } func restartNetworkd() error { + log.Printf("Restarting networkd.service\n") _, err := NewUnitManager("").RunUnitCommand("restart", "systemd-networkd.service") return err } @@ -108,6 +113,7 @@ func writeConfig(filename string, config string) error { if config == "" { return nil } + log.Printf("Writing networkd unit %q\n", filename) _, err := WriteFile(&File{Content: config, Path: filename}, runtimeNetworkPath) return err }