mirror of
https://github.com/clearlinux/libnetwork.git
synced 2026-08-19 04:17:48 +00:00
Moved the TOML based Configuration to dnet
The configuration format for docker runtime is based on daemon flags and hence adjusting the libnetwork configuration to accomodate it by moving the TOML based configuration to the dnet tool. Also changed the controller configuration via options Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
+40
-2
@@ -19,16 +19,19 @@ import (
|
||||
"github.com/docker/libnetwork"
|
||||
"github.com/docker/libnetwork/api"
|
||||
"github.com/docker/libnetwork/client"
|
||||
"github.com/docker/libnetwork/config"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
var (
|
||||
const (
|
||||
// DefaultHTTPHost is used if only port is provided to -H flag e.g. docker -d -H tcp://:8080
|
||||
DefaultHTTPHost = "127.0.0.1"
|
||||
// DefaultHTTPPort is the default http port used by dnet
|
||||
DefaultHTTPPort = 2385
|
||||
// DefaultUnixSocket exported
|
||||
DefaultUnixSocket = "/var/run/dnet.sock"
|
||||
cfgFileEnv = "LIBNETWORK_CFG"
|
||||
defaultCfgFile = "/etc/default/libnetwork.toml"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -45,6 +48,36 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func parseConfig(cfgFile string) (*config.Config, error) {
|
||||
if strings.Trim(cfgFile, " ") == "" {
|
||||
cfgFile = os.Getenv(cfgFileEnv)
|
||||
if strings.Trim(cfgFile, " ") == "" {
|
||||
cfgFile = defaultCfgFile
|
||||
}
|
||||
}
|
||||
return config.ParseConfig(cfgFile)
|
||||
}
|
||||
|
||||
func processConfig(cfg *config.Config) []config.Option {
|
||||
options := []config.Option{}
|
||||
if cfg == nil {
|
||||
return options
|
||||
}
|
||||
if strings.TrimSpace(cfg.Daemon.DefaultNetwork) != "" {
|
||||
options = append(options, config.OptionDefaultNetwork(cfg.Daemon.DefaultNetwork))
|
||||
}
|
||||
if strings.TrimSpace(cfg.Daemon.DefaultDriver) != "" {
|
||||
options = append(options, config.OptionDefaultDriver(cfg.Daemon.DefaultDriver))
|
||||
}
|
||||
if strings.TrimSpace(cfg.Datastore.Client.Provider) != "" {
|
||||
options = append(options, config.OptionKVProvider(cfg.Datastore.Client.Provider))
|
||||
}
|
||||
if strings.TrimSpace(cfg.Datastore.Client.Address) != "" {
|
||||
options = append(options, config.OptionKVProviderURL(cfg.Datastore.Client.Address))
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
func dnetCommand(stdout, stderr io.Writer) error {
|
||||
flag.Parse()
|
||||
|
||||
@@ -111,7 +144,12 @@ type dnetConnection struct {
|
||||
}
|
||||
|
||||
func (d *dnetConnection) dnetDaemon() error {
|
||||
controller, err := libnetwork.New("")
|
||||
cfg, err := parseConfig(*flCfgFile)
|
||||
var cOptions []config.Option
|
||||
if err == nil {
|
||||
cOptions = processConfig(cfg)
|
||||
}
|
||||
controller, err := libnetwork.New(cOptions...)
|
||||
if err != nil {
|
||||
fmt.Println("Error starting dnetDaemon :", err)
|
||||
return err
|
||||
|
||||
@@ -19,6 +19,7 @@ var (
|
||||
flHost = flag.String([]string{"H", "-host"}, "", "Daemon socket to connect to")
|
||||
flLogLevel = flag.String([]string{"l", "-log-level"}, "info", "Set the logging level")
|
||||
flDebug = flag.Bool([]string{"D", "-debug"}, false, "Enable debug mode")
|
||||
flCfgFile = flag.String([]string{"c", "-cfg-file"}, "/etc/default/libnetwork.toml", "Configuration file")
|
||||
flHelp = flag.Bool([]string{"h", "-help"}, false, "Print usage")
|
||||
|
||||
dnetCommands = []command{
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
func main() {
|
||||
// Create a new controller instance
|
||||
controller, err := libnetwork.New("/etc/default/libnetwork.toml")
|
||||
controller, err := libnetwork.New()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
+1
-3
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
@@ -14,8 +13,7 @@ import (
|
||||
|
||||
func main() {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
os.Setenv("LIBNETWORK_CFG", "libnetwork.toml")
|
||||
controller, err := libnetwork.New("libnetwork.toml")
|
||||
controller, err := libnetwork.New()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user