machine

package
v0.0.0-...-250839a Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReadPermission  uint8 = 1
	WritePermission uint8 = 2
)

volume permission

View Source
const (
	StatusRunning    = "running"
	StatusCreated    = "created"
	StatusExited     = "exited"
	StatusRemoving   = "removing"
	StatusDead       = "dead"
	StatusRestarting = "restarting"
	StatusPaused     = "paused"
)
View Source
const TIME_LAYOUT = "2006-01-02 15:04:05.999999999 -0700 MST"

Variables

This section is empty.

Functions

func AddMachine

func AddMachine(f Factory) (string, error)

func CheckExist

func CheckExist(id string) bool

func ContainerConnectNetwork

func ContainerConnectNetwork(id string, network *Network) error

func DeleteContainer

func DeleteContainer(containerID string) error

func DeleteVM

func DeleteVM(UUID string) error

func KillContainer

func KillContainer(containerID string, signal string) error

func KillVM

func KillVM(UUID string, signal string) error

func PauseContainer

func PauseContainer(containerID string) error

func PauseVM

func PauseVM(UUID string) error

func RestartContainer

func RestartContainer(timeout int32, containerID string) error

func RestartVM

func RestartVM(timeout int32, UUID string) error

func StartContainer

func StartContainer(containerID string) error

func StartVM

func StartVM(UUID string) error

func StopContainer

func StopContainer(timeout int32, containerID string) error

func StopVM

func StopVM(timeout int32, UUID string) error

func UnpauseContainer

func UnpauseContainer(containerID string) error

func UnpauseVM

func UnpauseVM(UUID string) error

func VMConnectNetwork

func VMConnectNetwork(id string, nw *Network) error

Types

type Base

type Base struct {
	IsDocker      bool           `json:"is_docker"`
	ImageID       string         `json:"image_id"`
	ID            string         `json:"id"`
	ImageName     string         `json:"imageName"`
	ImagePath     string         `json:"image_path"`
	ImageType     string         `json:"image_type"`
	Name          string         `json:"name"` // 名字
	CreateTime    time.Time      `json:"create_time"`
	RuntimeConfig *RuntimeConfig `json:"runtime_config"` // 运行配置
}

func (*Base) Commit

func (m *Base) Commit(name string) (string, error)

func (*Base) ConnectNetWork

func (m *Base) ConnectNetWork(nw *Network) error

func (*Base) Delete

func (m *Base) Delete() error

func (*Base) GetImageID

func (m *Base) GetImageID() string

func (*Base) GetName

func (m *Base) GetName() string

func (*Base) GetState

func (m *Base) GetState() string

func (*Base) GetStdio

func (m *Base) GetStdio(detachKey string) (chan []byte, chan []byte, chan []byte, error)

func (*Base) Inspect

func (m *Base) Inspect() (name string, runtimeSetting string, spec string, machineType string, err error)

func (*Base) Kill

func (m *Base) Kill(signal string) error

func (*Base) Pause

func (m *Base) Pause() error

func (*Base) Rename

func (m *Base) Rename(newName string) error

func (*Base) ResizeTTY

func (m *Base) ResizeTTY(h uint32, w uint32) error

func (*Base) Restart

func (m *Base) Restart(timeout int32) error

func (*Base) Start

func (m *Base) Start() error

func (*Base) Stop

func (m *Base) Stop(timeout int32) error

func (*Base) Unpause

func (m *Base) Unpause() error

type BaseContainer

type BaseContainer struct {
	Base            *Base
	ContainerConfig *container.Config     `json:"container_config"`
	HostConfig      *container.HostConfig `json:"host_config"`
}

func (*BaseContainer) Create

func (container *BaseContainer) Create() error

Factory interface

func (*BaseContainer) GetBase

func (container *BaseContainer) GetBase() (*Base, error)

func (*BaseContainer) SetCgroups

func (container *BaseContainer) SetCgroups(res docker.Resources)

func (*BaseContainer) SetCmd

func (container *BaseContainer) SetCmd(cmd []string)

func (*BaseContainer) SetEntrypoint

func (container *BaseContainer) SetEntrypoint(entrypoint []string)

func (*BaseContainer) SetEnv

func (container *BaseContainer) SetEnv(env []string)

func (*BaseContainer) SetExposedPorts

func (container *BaseContainer) SetExposedPorts(info []proxy.ProxyInfo)

func (*BaseContainer) SetHostname

func (container *BaseContainer) SetHostname(name string)

func (*BaseContainer) SetHosts

func (container *BaseContainer) SetHosts(hosts []string)

func (*BaseContainer) SetImage

func (container *BaseContainer) SetImage(imageID string, path string, name string)

func (*BaseContainer) SetName

func (container *BaseContainer) SetName(name string) error

func (*BaseContainer) SetNetworks

func (container *BaseContainer) SetNetworks(networks []*Network)

func (*BaseContainer) SetRoutes

func (container *BaseContainer) SetRoutes(routes []*Route)

func (*BaseContainer) SetTTY

func (container *BaseContainer) SetTTY(tty bool)

func (*BaseContainer) SetTTYSize

func (container *BaseContainer) SetTTYSize(width, height uint16)

func (*BaseContainer) SetUser

func (container *BaseContainer) SetUser(user string)

func (*BaseContainer) SetVolumes

func (container *BaseContainer) SetVolumes(volumes []*Volume)

func (*BaseContainer) SetWorkingDir

func (container *BaseContainer) SetWorkingDir(dir string)

type BaseVM

type BaseVM struct {
	BaseInfo *Base
	VMConfig *libvirtxml.Domain
}

func (*BaseVM) Create

func (VM *BaseVM) Create() error

Factory interface

func (*BaseVM) GetBase

func (VM *BaseVM) GetBase() (*Base, error)

func (*BaseVM) SetCgroups

func (VM *BaseVM) SetCgroups(res container.Resources)

func (*BaseVM) SetCmd

func (VM *BaseVM) SetCmd(cmd []string)

func (*BaseVM) SetEntrypoint

func (VM *BaseVM) SetEntrypoint(entrypoint []string)

func (*BaseVM) SetEnv

func (VM *BaseVM) SetEnv(env []string)

func (*BaseVM) SetExposedPorts

func (VM *BaseVM) SetExposedPorts(info []proxy.ProxyInfo)

func (*BaseVM) SetHostname

func (VM *BaseVM) SetHostname(name string)

func (*BaseVM) SetHosts

func (VM *BaseVM) SetHosts(hosts []string)

func (*BaseVM) SetImage

func (VM *BaseVM) SetImage(imageID string, path string, name string)

func (*BaseVM) SetName

func (VM *BaseVM) SetName(name string) error

func (*BaseVM) SetNetworks

func (VM *BaseVM) SetNetworks(networks []*Network)

func (*BaseVM) SetRoutes

func (VM *BaseVM) SetRoutes([]*Route)

func (*BaseVM) SetTTY

func (VM *BaseVM) SetTTY(tty bool)

func (*BaseVM) SetTTYSize

func (VM *BaseVM) SetTTYSize(width, height uint16)

func (*BaseVM) SetUser

func (VM *BaseVM) SetUser(user string)

func (*BaseVM) SetVolumes

func (VM *BaseVM) SetVolumes(volumes []*Volume)

func (*BaseVM) SetWorkingDir

func (VM *BaseVM) SetWorkingDir(dir string)

type CgroupsConfig

type CgroupsConfig struct {
	//CgroupsPath    string                `json:"cgroupsPath,omitempty"` // cgroup path 必须是绝对路径
	//LinuxResources *specs.LinuxResources `json:"resources,omitempty"`
	container.Resources
}

type Factory

type Factory interface {
	SetName(string) error            // 容器的名字
	SetHostname(string)              // 设置主机名
	SetTTY(bool)                     // 设置是否使用终端
	SetNetworks([]*Network)          // 添加网络
	SetRoutes([]*Route)              // 添加路由
	SetImage(string, string, string) // 添加镜像地址
	SetVolumes([]*Volume)            // 添加卷
	SetEntrypoint([]string)          // EntryPoint (entrypoint, cmd)
	SetCmd([]string)                 // Cmd
	SetWorkingDir(string)            // WorkingDir 默认 "/"
	SetUser(string)                  // User
	SetEnv([]string)                 // Env
	SetTTYSize(width, height uint16)
	GetBase() (*Base, error) // get machine entry
	SetHosts([]string)       // 格式:{"hostname:192.168.0.2"}
	SetExposedPorts(info []proxy.ProxyInfo)
	Create() error
	SetCgroups(container.Resources)
}

func CreateContainer

func CreateContainer(imageID string) Factory

func CreateVM

func CreateVM(imageID string) Factory

type HostEntry

type HostEntry struct {
	Host    string
	Address string
}

type Machine

type Machine interface {
	Start() error        // 运行machine
	Kill(string) error   // 使用指定的信号来停止一个容器
	Pause() error        // 暂停
	Unpause() error      // 恢复
	Delete() error       // 删除这个machine所占用的资源
	Stop(int32) error    // 停止
	Restart(int32) error // 重启
	GetImageID() string  //
	Rename(string) error // rename
	ResizeTTY(h uint32, w uint32) error
	GetStdio(string) (chan []byte, chan []byte, chan []byte, error) // stdin, stdout, stderr
	GetState() string                                               // get machine state
	Inspect() (name string, runtimeSetting string, spec string, machineType string, err error)
	Commit(name string) (string, error)
	ConnectNetWork(*Network) error

	GetName() string
}

func GetMachine

func GetMachine(id string) (Machine, error)

type MachineInfo

type MachineInfo struct {
	ImageName  string
	ID         string
	Name       string
	CreateTime string
	ImageType  string
	Status     string
	ImageId    string
}

func ListMachine

func ListMachine() []MachineInfo

type Network

type Network struct {
	// Type 设置 networks type, 通常设置为 veth 或者 loopback
	Type string `json:"type"`

	// Name 设置网络接口名字比如 eth0
	Name string `json:"name"`

	// Bridge 设置要使用的网桥
	Bridge string `json:"bridge"`

	// MacAddress 设置接口的 mac 地址
	MacAddress string `json:"mac_address"`

	// Address 设置包含 mask 的 IPV4 地址 比如 192.169.10.2/24
	Address []string `json:"address"`

	// Gateway 设置接口的默认 ipv4 网关地址
	Gateway string `json:"gateway"`

	// IPv6Address 设置包含 mask 的 IPV6 地址
	IPv6Address []string `json:"ipv6_address"`

	// IPv6Gateway 设置接口的默认 ipv6 网关地址
	IPv6Gateway string `json:"ipv6_gateway"`

	// 设置一対 veth 之间的 mtu
	// 注意:不会作用于:loopback
	Mtu int `json:"mtu"`

	// 设置一対 veth 之间的 tx_queuelen
	// 注意:不会作用于:loopback
	TxQueueLen int `json:"txqueuelen"`

	// 一対 veth 中在宿主机上的 veth 的名字
	HostInterfaceName string `json:"host_interface_name"`
}

type Route

type Route struct {
	// 设置 destination 和 mask 必须是 CIDR 格式
	// 支持 IPV4 和 IPV6 比如:192.168.1.2/24
	Destination string `json:"destination"`

	// 设置 source 和 mask 必须是 CIDR 格式
	// 支持 IPV4 和 IPV6 比如:192.168.1.3/24
	Source string `json:"source"`

	// 设置网关
	// 支持 IPV4 和 IPV6 比如:192.168.1.1
	Gateway string `json:"gateway"`

	// 设备名 比如 eth0
	InterfaceName string `json:"interface_name"`
}

type RuntimeConfig

type RuntimeConfig struct {
	Tty          bool               `json:"tty"`
	Networks     []*Network         `json:"networks"` // 网络设备配置
	Routes       []*Route           `json:"routes"`   // 路由配置
	Volumes      map[string]*Volume `json:"volumes"`
	ExposedPorts []proxy.ProxyInfo  `json:"exposed_ports"`
	ProxyManager proxy.ProxyManager
}

type Volume

type Volume struct {
	Destination string `json:"destination"`
	RW          uint8  `json:"rw"`
	Source      string `json:"source"`
	Name        string `json:"name"`
	Type        string `json:"type"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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