network

package
v0.0.0-...-ae7814b Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(networkName string, cinfo *container.ContainerInfo) error

连接容器到之前创建的网络 mydocker run net testnet -p 8080:80 xxxx

func CreateNetwork

func CreateNetwork(driver, subnet, name string) error

创建网络

func DeleteNetwork

func DeleteNetwork(networkName string) error

删除网络信息

func Disconnect

func Disconnect(networkName string, cinfo *container.ContainerInfo) error

func Init

func Init() error

网络初始化

func ListNetwork

func ListNetwork()

列出网络信息

Types

type BridgeNetworkDriver

type BridgeNetworkDriver struct {
}

func (*BridgeNetworkDriver) Connect

func (d *BridgeNetworkDriver) Connect(network *Network, endpoint *Endpoint) error

连接一个网络和网络端点

func (*BridgeNetworkDriver) Create

func (d *BridgeNetworkDriver) Create(subnet string, name string) (*Network, error)

func (*BridgeNetworkDriver) Delete

func (d *BridgeNetworkDriver) Delete(network Network) error

func (*BridgeNetworkDriver) Disconnect

func (d *BridgeNetworkDriver) Disconnect(network Network, endpoint *Endpoint) error

func (*BridgeNetworkDriver) Name

func (d *BridgeNetworkDriver) Name() string

type Endpoint

type Endpoint struct {
	ID          string           `json:"id"`
	Device      netlink.Veth     `json:"dev"`
	IPAddress   net.IP           `json:"ip"`
	MacAddress  net.HardwareAddr `json:"mac"`
	Network     *Network
	PortMapping []string
}

网络端点 包括连接到网络的一些信息, 比如地址Veth设备,端口映射,连接的容器和网络等信息 网络端点信息传输需要靠网络功能的两个组件配合完成,这两个组件分别为网络驱动(NetworkDriver)和IPAM

type IPAM

type IPAM struct {
	// 分配文件存放位置
	SubnetAllocatorPath string
	// 网段的位图算法的数组map, key是网段,value是分配的位图数组(记录的是分配的ip信息
	Subnets *map[string]string
}

func (*IPAM) Allocate

func (ipam *IPAM) Allocate(subnet *net.IPNet) (ip net.IP, err error)

在网段中分配一个可用的 IP 地址

func (*IPAM) Release

func (ipam *IPAM) Release(subnet *net.IPNet, ipaddr *net.IP) error

地址释放

type Network

type Network struct {
	Name    string     // 网络名
	IpRange *net.IPNet // 地址段
	Driver  string     // 网络驱动名
}

网络信息

type NetworkDriver

type NetworkDriver interface {
	// 驱动名
	Name() string
	// 创建网络
	Create(subnet string, name string) (*Network, error)
	// 删除网络
	Delete(network Network) error
	// 连接容器网络端点到网络
	Connect(network *Network, endpoint *Endpoint) error
	// 从网络上一处容器网络端点
	Disconnect(network Network, endpoint *Endpoint) error
}

网络驱动

Jump to

Keyboard shortcuts

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