network

package
v0.0.0-...-504d40a Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(networkName string, cInfo *container.Info) error

连楼容2带到之前创建的网络 ydocker 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.Info) 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

删除网络对应的 Linux Bridge

func (*BridgeNetworkDriver) Disconnect

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

func (*BridgeNetworkDriver) Name

func (d *BridgeNetworkDriver) Name() string

type Driver

type Driver 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
}

网络驱动

type Endpoint

type Endpoint struct {
	ID          string           `json:"id"`  // 网络ID
	Device      netlink.Veth     `json:"dev"` // Veth 设备
	IPAddress   net.IP           `json:"ip"`  // IP 地址
	MacAddress  net.HardwareAddr `json:"mac"` // MAC 地址
	Network     *Network         // 连接的容器和网络
	PortMapping []string         // 端口映射
}

网络端点

type IPAM

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

地址分配

func (*IPAM) Allocate

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

从指定的 subnet 网段中分配 IP 地址

func (*IPAM) Release

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

从指定的 subnet 网段中释放掉指定的 IP 地址

type Network

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

网络

Jump to

Keyboard shortcuts

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