libnetwork

package module
v0.0.0-...-ddd11cc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2015 License: Apache-2.0 Imports: 8 Imported by: 0

README

libnetwork - networking for containers

Circle CI Coverage Status GoDoc

Libnetwork provides a native Go implementation for connecting containers

The goal of libnetwork is to deliver a robust Container Network Model that provides a consistent programming interface and the required network abstractions for applications.

NOTE: libnetwork project is under heavy development and is not ready for general use.

Current Status

Please watch this space for updates on the progress.

Currently libnetwork is nothing more than an attempt to modularize the Docker platform's networking subsystem by moving it into libnetwork as a library.

Please refer to the roadmap for more information.

Using libnetwork

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.

 // Create a new controller instance
 controller := libnetwork.New()

 // This option is only needed for in-tree drivers. Plugins(in future) will get 
 // their options through plugin infrastructure.
 option := options.Generic{}
 driver, err := controller.NewNetworkDriver("simplebridge", option)
 if err != nil {
    return
 }

 netOptions := options.Generic{}
 // Create a network for containers to join.
 network, err := controller.NewNetwork(driver, "network1", netOptions)
 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. This info is contained or accessible
 // from the returned endpoint.
 ep, err := network.CreateEndpoint("Endpoint1", networkNamespace.Key(), "")
 if err != nil {
    return
 }

 // Add interfaces to the namespace.
 sinfo := ep.SandboxInfo()
 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

See the roadmap.

Contributing

Want to hack on libnetwork? Docker's contributions guidelines apply.

Code and documentation copyright 2015 Docker, inc. Code released under the Apache 2.0 license. Docs released under Creative commons.

Documentation

Overview

Package libnetwork provides the basic functionality and extension points to create network namespaces and allocate interfaces for containers to use.

    // Create a new controller instance
    controller := libnetwork.New()

    // This option is only needed for in-tree drivers. Plugins(in future) will get
    // their options through plugin infrastructure.
    option := options.Generic{}
    driver, err := controller.NewNetworkDriver("simplebridge", option)
    if err != nil {
        return
    }

    netOptions := options.Generic{}
    // Create a network for containers to join.
    network, err := controller.NewNetwork(driver, "network1", netOptions)
    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.
    ep, err := network.CreateEndpoint("Endpoint1", networkNamespace.Key(), "")
    if err != nil {
	    return
    }

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNilNetworkDriver is returned if a nil network driver
	// is passed to NewNetwork api.
	ErrNilNetworkDriver = errors.New("nil NetworkDriver instance")
	// ErrInvalidNetworkDriver is returned if an invalid driver
	// instance is passed.
	ErrInvalidNetworkDriver = errors.New("invalid driver bound to network")
)

Functions

This section is empty.

Types

type ActiveEndpointsError

type ActiveEndpointsError struct {
	// contains filtered or unexported fields
}

ActiveEndpointsError is returned when a network is deleted which has active endpoints in it.

func (*ActiveEndpointsError) Error

func (aee *ActiveEndpointsError) Error() string

type Endpoint

type Endpoint interface {
	// A system generated id for this endpoint.
	ID() string

	// Name returns the name of this endpoint.
	Name() string

	// Network returns the name of the network to which this endpoint is attached.
	Network() string

	// SandboxInfo returns the sandbox information for this endpoint.
	SandboxInfo() *driverapi.SandboxInfo

	// Delete and detaches this endpoint from the network.
	Delete() error
}

Endpoint represents a logical connection between a network and a sandbox.

type Network

type Network interface {
	// A user chosen name for this network.
	Name() string

	// A system generated id for this network.
	ID() string

	// The type of network, which corresponds to its managing driver.
	Type() string

	// Create a new endpoint to this network symbolically identified by the
	// specified unique name. The options parameter carry driver specific options.
	// Labels support will be added in the near future.
	CreateEndpoint(name string, sboxKey string, options interface{}) (Endpoint, error)

	// Endpoints returns the list of Endpoint in this network.
	Endpoints() []Endpoint

	// Delete the network.
	Delete() error
}

A Network represents a logical connectivity zone that containers may join using the Link method. A Network is managed by a specific driver.

type NetworkController

type NetworkController interface {
	// NOTE: This method will go away when moving to plugin infrastructure
	NewNetworkDriver(networkType string, options interface{}) (*NetworkDriver, error)
	// Create a new network. The options parameter carries network specific options.
	// Labels support will be added in the near future.
	NewNetwork(d *NetworkDriver, name string, options interface{}) (Network, error)
}

NetworkController provides the interface for controller instance which manages networks.

func New

func New() NetworkController

New creates a new instance of network controller.

type NetworkDriver

type NetworkDriver struct {
	// contains filtered or unexported fields
}

NetworkDriver provides a reference to driver and way to push driver specific config

type NetworkNameError

type NetworkNameError string

NetworkNameError is returned when a network with the same name already exists.

func (NetworkNameError) Error

func (name NetworkNameError) Error() string

type NetworkTypeError

type NetworkTypeError string

NetworkTypeError type is returned when the network type string is not known to libnetwork.

func (NetworkTypeError) Error

func (nt NetworkTypeError) Error() string

type UnknownEndpointError

type UnknownEndpointError struct {
	// contains filtered or unexported fields
}

UnknownEndpointError is returned when libnetwork could not find in it's database an endpoint with the same name and id.

func (*UnknownEndpointError) Error

func (uee *UnknownEndpointError) Error() string

type UnknownNetworkError

type UnknownNetworkError struct {
	// contains filtered or unexported fields
}

UnknownNetworkError is returned when libnetwork could not find in it's database a network with the same name and id.

func (*UnknownNetworkError) Error

func (une *UnknownNetworkError) Error() string

Directories

Path Synopsis
Godeps
_workspace/src/github.com/vishvananda/netlink
Package netlink provides a simple library for netlink.
Package netlink provides a simple library for netlink.
_workspace/src/github.com/vishvananda/netlink/nl
Package nl has low level primitives for making Netlink calls.
Package nl has low level primitives for making Netlink calls.
_workspace/src/github.com/vishvananda/netns
Package netns allows ultra-simple network namespace handling.
Package netns allows ultra-simple network namespace handling.
cmd
readme_test command
test command
drivers
Package ipallocator defines the default IP allocator.
Package ipallocator defines the default IP allocator.
pkg
options
Package options provides a way to pass unstructured sets of options to a component expecting a strongly-typed configuration structure.
Package options provides a way to pass unstructured sets of options to a component expecting a strongly-typed configuration structure.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL