Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 37 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,43 @@ Please refer to the [roadmap](ROADMAP.md) for more information.
There are many networking solutions available to suit a broad range of use-cases. libnetwork uses a driver / plugin model to support all of these solutions while abstracting the complexity of the driver implementations by exposing a simple and consistent Network Model to users.

```go
//Create a network for containers to join.
network, err := libnetwork.NewNetwork("simplebridge", &Options{})
if err != nil {
return err
}
//
// For a new container: create network namespace (providing the path).
networkPath := "/var/lib/docker/.../4d23e"
networkNamespace, err := libnetwork.NewNetworkNamespace(networkPath)
if err != nil {
return err
}
//
// For each new container: allocate IP and interfaces. The returned network
// settings will be used for container infos (inspect and such), as well as
// iptables rules for port publishing.
interfaces, err := network.Link(containerID)
if err != nil {
return err
}
//
// Add interfaces to the namespace.
for _, interface := range interfaces {
if err := networkNamespace.AddInterface(interface); err != nil {
return err
}
}
//
// Create a new controller instance
controller := libnetwork.New()

options := options.Generic{}
// Create a network for containers to join.
network, err := controller.NewNetwork("simplebridge", "network1", options)
if err != nil {
return
}

// For a new container: create a sandbox instance (providing a unique key).
// For linux it is a filesystem path
networkPath := "/var/lib/docker/.../4d23e"
networkNamespace, err := sandbox.NewSandbox(networkPath)
if err != nil {
return
}

// For each new container: allocate IP and interfaces. The returned network
// settings will be used for container infos (inspect and such), as well as
// iptables rules for port publishing.
_, sinfo, err := network.CreateEndpoint("Endpoint1", networkNamespace.Key(), "")
if err != nil {
return
}

// Add interfaces to the namespace.
for _, iface := range sinfo.Interfaces {
if err := networkNamespace.AddInterface(iface); err != nil {
return
}
}

// Set the gateway IP
if err := networkNamespace.SetGateway(sinfo.Gateway); err != nil {
return
}
```

## Future
Expand Down
7 changes: 4 additions & 3 deletions cmd/test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import (
"net"

"github.com/docker/libnetwork"
_ "github.com/docker/libnetwork/drivers/bridge"
"github.com/docker/libnetwork/pkg/options"
)

func main() {
ip, net, _ := net.ParseCIDR("192.168.100.1/24")
net.IP = ip

options := libnetwork.DriverParams{"AddressIPv4": net}
netw, err := libnetwork.NewNetwork("simplebridge", "dummy", options)
options := options.Generic{"AddressIPv4": net}
controller := libnetwork.New()
netw, err := controller.NewNetwork("simplebridge", "dummy", options)
if err != nil {
log.Fatal(err)
}
Expand Down
Loading