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:
@@ -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)
|
||||
|
Reference in New Issue
Block a user