mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
9f3d1ce3ff
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>
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"time"
|
|
|
|
log "github.com/Sirupsen/logrus"
|
|
|
|
"github.com/docker/libnetwork"
|
|
"github.com/docker/libnetwork/options"
|
|
)
|
|
|
|
func main() {
|
|
log.SetLevel(log.DebugLevel)
|
|
controller, err := libnetwork.New()
|
|
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}
|
|
|
|
err = controller.ConfigureNetworkDriver(netType, options)
|
|
for i := 0; i < 10; i++ {
|
|
netw, err := controller.NewNetwork(netType, fmt.Sprintf("Gordon-%d", i))
|
|
if err != nil {
|
|
if _, ok := err.(libnetwork.NetworkNameError); !ok {
|
|
log.Fatal(err)
|
|
}
|
|
} else {
|
|
fmt.Println("Network Created Successfully :", netw)
|
|
}
|
|
netw, _ = controller.NetworkByName(fmt.Sprintf("Gordon-%d", i))
|
|
_, err = netw.CreateEndpoint(fmt.Sprintf("Gordon-Ep-%d", i), nil)
|
|
if err != nil {
|
|
log.Fatalf("Error creating endpoint 1 %v", err)
|
|
}
|
|
|
|
_, err = netw.CreateEndpoint(fmt.Sprintf("Gordon-Ep2-%d", i), nil)
|
|
if err != nil {
|
|
log.Fatalf("Error creating endpoint 2 %v", err)
|
|
}
|
|
|
|
time.Sleep(2 * time.Second)
|
|
}
|
|
}
|