mirror of
https://github.com/clearlinux/libnetwork.git
synced 2026-09-01 02:44:45 +00:00
TOML based Configuration support for libnetwork
Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
+1
-1
@@ -106,7 +106,7 @@ type dnetConnection struct {
|
||||
}
|
||||
|
||||
func (d *dnetConnection) dnetDaemon() error {
|
||||
controller, err := libnetwork.New()
|
||||
controller, err := libnetwork.New("")
|
||||
if err != nil {
|
||||
fmt.Println("Error starting dnetDaemon :", err)
|
||||
return err
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
func main() {
|
||||
// Create a new controller instance
|
||||
controller, err := libnetwork.New()
|
||||
controller, err := libnetwork.New("/etc/default/libnetwork.toml")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
title = "LibNetwork Configuration file"
|
||||
|
||||
[daemon]
|
||||
debug = false
|
||||
[cluster]
|
||||
discovery = "token://swarm-discovery-token"
|
||||
Address = "Cluster-wide reachable Host IP"
|
||||
[datastore]
|
||||
embedded = false
|
||||
[datastore.client]
|
||||
provider = "consul"
|
||||
Address = "localhost:8500"
|
||||
+17
-10
@@ -4,25 +4,32 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/docker/libnetwork"
|
||||
"github.com/docker/libnetwork/options"
|
||||
)
|
||||
|
||||
func main() {
|
||||
os.Setenv("LIBNETWORK_CFG", "libnetwork.toml")
|
||||
controller, err := libnetwork.New("libnetwork.toml")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
netType := "null"
|
||||
ip, net, _ := net.ParseCIDR("192.168.100.1/24")
|
||||
net.IP = ip
|
||||
|
||||
options := options.Generic{"AddressIPv4": net}
|
||||
controller, err := libnetwork.New()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
netType := "bridge"
|
||||
|
||||
err = controller.ConfigureNetworkDriver(netType, options)
|
||||
netw, err := controller.NewNetwork(netType, "dummy")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
for i := 0; i < 100; i++ {
|
||||
netw, err := controller.NewNetwork(netType, fmt.Sprintf("Gordon-%d", i))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println("Network Created Successfully :", netw)
|
||||
time.Sleep(10 * time.Second)
|
||||
}
|
||||
fmt.Printf("Network=%#v\n", netw)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user