feat(convertNetconf): Add support for network config conversion

Adding the flag -convertNetconf which is used to specify the config
format to convert from (right now, only 'debian' is supported).
Once the network configs are generated, they are written to
systemd's runtime network directory and the network is restarted.
This commit is contained in:
Alex Crawford
2014-05-22 15:00:41 -07:00
parent 79a40a38d8
commit 48df1be793
3 changed files with 170 additions and 53 deletions

View File

@@ -1,10 +1,6 @@
package network
import (
"fmt"
"io"
"os"
"path"
"strings"
)
@@ -26,43 +22,6 @@ func ProcessDebianNetconf(config string) ([]InterfaceGenerator, error) {
return buildInterfaces(interfaces), nil
}
func WriteConfigs(configPath string, interfaces []InterfaceGenerator) error {
if err := os.MkdirAll(configPath, os.ModePerm+os.ModeDir); err != nil {
fmt.Println(err)
os.Exit(1)
}
for _, iface := range interfaces {
filename := path.Join(configPath, fmt.Sprintf("%s.netdev", iface.Name()))
if err := writeConfig(filename, iface.GenerateNetdevConfig()); err != nil {
return err
}
filename = path.Join(configPath, fmt.Sprintf("%s.link", iface.Name()))
if err := writeConfig(filename, iface.GenerateLinkConfig()); err != nil {
return err
}
filename = path.Join(configPath, fmt.Sprintf("%s.network", iface.Name()))
if err := writeConfig(filename, iface.GenerateNetworkConfig()); err != nil {
return err
}
}
return nil
}
func writeConfig(filename string, config string) error {
if config == "" {
return nil
}
if file, err := os.Create(filename); err == nil {
io.WriteString(file, config)
file.Close()
return nil
} else {
return err
}
}
func formatConfig(config string) []string {
lines := []string{}
config = strings.Replace(config, "\\\n", "", -1)