docker

package
v0.0.0-...-52087c1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BYTES  = 1
	KBYTES = BYTES * 1024
	MBYTES = KBYTES * 1024
	GBYTES = MBYTES * 1024
)
View Source
const (
	IMAGE_EXPIRE_DURATION = time.Hour * 24 * 30
)

Variables

View Source
var (
	ErrVmNotFound         = errors.New("VM not found")
	ErrVmNotSupportedArch = errors.New("VM arch not supported")
)

Functions

func AddBeforeNetworkRemoveHook

func AddBeforeNetworkRemoveHook(hook BeforeNetworkRemove)

AddBeforeNetworkRemoveHook adds a hook to the BeforeNetworkRemoveHook list

func AddOnContainerLaunchHook

func AddOnContainerLaunchHook(hook OnContainerLaunch)

AddOnContainerLaunchHook adds a hook to the OnContainerLaunchHook list

func AddOnContainerStopHook

func AddOnContainerStopHook(hook OnContainerStop)

AddOnContainerStopHook adds a hook to the OnContainerStopHook list

func AddOnDockerDaemonStartHook

func AddOnDockerDaemonStartHook(hook OnDockerDaemonStart)

AddOnDockerDaemonStartHook adds a hook to the OnDockerDaemonStartHook list

func AddOnNetworkCreateHook

func AddOnNetworkCreateHook(hook OnNetworkCreate)

AddOnNetworkCreateHook adds a hook to the OnNetworkCreateHook list

func AddOnNetworkRemoveHook

func AddOnNetworkRemoveHook(hook OnNetworkRemove)

AddOnNetworkRemoveHook adds a hook to the OnNetworkRemoveHook list

func InitCIDRPool

func InitCIDRPool(cidr_expression string) (int, error)

func InitDocker

func InitDocker()

func ParseCIDRRange

func ParseCIDRRange(cidr string) ([]string, error)

Parse a CIDR expression into a list of CIDR CIDR expression like: 172.[128-255].[0-255].0/24 every number in the expression can be a range or a single number

Types

type BeforeNetworkRemove

type BeforeNetworkRemove func(*Docker, types.Network) error

type ContainerNetworkInfo

type ContainerNetworkInfo struct {
	ContainerId string
	Networks    []struct {
		Network kisara_types.Network
		Ip      string
	}
}

type Docker

type Docker struct {
	KisaraNetworkMonitor
	Client *client.Client
	Ctx    *context.Context
	Vm     VirtualMachineInf
}

func NewDocker

func NewDocker() *Docker

func (*Docker) BuildImage

func (c *Docker) BuildImage(tar_file io.Reader, image_name string, message_callback func(string), fault_callback func(string), finish ...chan struct{}) error

BuildImage will build a docker image from a tar file

func (*Docker) CheckImageExist

func (c *Docker) CheckImageExist(image_name string) bool

func (*Docker) ConnectContainerToNetwork

func (c *Docker) ConnectContainerToNetwork(container_id string, network_id string) error

Connect a container to a network

func (*Docker) CreateContainer

func (c *Docker) CreateContainer(
	image string, uid int, port_protocol string,
	subnet_names []string, module string,
	env map[string]string, vol map[string]string,
	cpu_usage float64, mem_usage int64, disk_usage int64,
) (*kisara_types.Container, error)

func (*Docker) CreateNetwork

func (c *Docker) CreateNetwork(subnet string, name string, internal bool, driver string) (*kisara_types.Network, error)

Create a new docker virtual network

func (*Docker) CreateRandomCIDRNetwork

func (c *Docker) CreateRandomCIDRNetwork(internal bool, driver string) (*kisara_types.Network, error)

Create a Random CIDR network

func (*Docker) CreateService

func (c *Docker) CreateService(service_config types.KisaraService, message_callback ...func(string)) (*types.Service, error)

create a service from a service config

func (*Docker) DeleteImage

func (c *Docker) DeleteImage(uuid string) error

func (*Docker) DeleteNetwork

func (c *Docker) DeleteNetwork(network_id string) error

Delete a docker virtual network

func (*Docker) DeleteService

func (c *Docker) DeleteService(service_id string) error

delete a service

func (*Docker) DisconnectContainerFromNetwork

func (c *Docker) DisconnectContainerFromNetwork(container_id string, network_id string) error

Disconnect a container from a network

func (*Docker) Exec

func (c *Docker) Exec(container_id string, cmd string) error

func (*Docker) ExecWarp

func (c *Docker) ExecWarp(container_id string, cmd string, timeout time.Duration) ([]byte, error)

func (*Docker) GetContainerNetwork

func (c *Docker) GetContainerNetwork(container_id string) (ContainerNetworkInfo, error)

Get a container's network info

func (*Docker) GetContainerNumber

func (c *Docker) GetContainerNumber() (int, error)

Get container Number

func (*Docker) GetImage

func (c *Docker) GetImage(image_name string) (*kisara_types.Image, error)

func (*Docker) GetNetworkByName

func (c *Docker) GetNetworkByName(name string) (*kisara_types.Network, error)

Get a docker virtual network by name

func (*Docker) GetService

func (c *Docker) GetService(service_id string) (*types.Service, error)

func (*Docker) InitImage

func (c *Docker) InitImage() error

init current image db records, create record if not exists

func (*Docker) InspectContainer

func (c *Docker) InspectContainer(container_id string, has_state ...bool) (*kisara_types.Container, error)

InspectContainer will insepct to docker container and return some information about the container like host_port, container status, etc.

func (*Docker) LaunchAWD

func (c *Docker) LaunchAWD(image_name string, port_protocols string, uid int, subnet_name string, env map[string]string) (*kisara_types.Container, error)

func (*Docker) LaunchContainer

func (c *Docker) LaunchContainer(image_name string, uid int, port_protocol string, subnet_name string, module string, env_mount ...map[string]string) (*kisara_types.Container, error)

func (*Docker) LaunchServiceContainer

func (c *Docker) LaunchServiceContainer(image_name string, port_protocols string, uid int, subnet_names []string, env map[string]string) (*kisara_types.Container, error)

func (*Docker) LaunchTargetMachine

func (c *Docker) LaunchTargetMachine(image_name string, port_protocol string, subnet_name string, uid int, module string) (*kisara_types.Container, error)

func (*Docker) ListContainer

func (c *Docker) ListContainer() (*[]*kisara_types.Container, error)

func (*Docker) ListImage

func (c *Docker) ListImage() (*[]*kisara_types.Image, error)

func (*Docker) ListNetwork

func (c *Docker) ListNetwork() ([]kisara_types.Network, error)

List all docker virtual network

func (*Docker) ListServices

func (c *Docker) ListServices() ([]*types.Service, error)

func (*Docker) PullImage

func (c *Docker) PullImage(image_name string, event_callback func(message string)) (*kisara_types.Image, error)

func (*Docker) ReleaseCIDRNetwork

func (c *Docker) ReleaseCIDRNetwork(cidr string) error

Release a CIDR network

func (*Docker) RemoveContainer

func (c *Docker) RemoveContainer(id string) error

func (*Docker) RequireImage

func (c *Docker) RequireImage(image_name string, message_callback func(string)) (*kisara_types.Image, error)

when launch container, it's nessesscry to require image first it will lock the image to avoid image deletion before launch container it will also automatically pull image if not exists

func (*Docker) RunNetworkMonitor

func (c *Docker) RunNetworkMonitor(network_name string, context io.Reader, message_callback func(string)) (*types.KisaraNetworkMonitorContainer, error)

func (*Docker) RunNetworkMonitorScript

func (c *Docker) RunNetworkMonitorScript(containers *types.KisaraNetworkTestSet) (*types.KisaraNetworkTestResultSet, error)

Run the test script, support multiple containers result and error should be all considered beacuse of multiple tests

func (*Docker) Stop

func (c *Docker) Stop()

func (*Docker) StopContainer

func (c *Docker) StopContainer(id string) error

func (*Docker) StopNetworkMonitor

func (c *Docker) StopNetworkMonitor(container *types.KisaraNetworkMonitorContainer) error

type KisaraNetworkMonitor

type KisaraNetworkMonitor interface {
	// Run the test container
	//@param network_name: the network name to run the test container
	//@param context: the context to build the test container, should be a tar file and contains dockerfile etc.
	RunNetworkMonitor(network_name string, context io.Reader, message_callback func(string)) (*types.KisaraNetworkMonitorContainer, error)
	// Stop the test container, and automatically remove it
	StopNetworkMonitor(container *types.KisaraNetworkMonitorContainer) error
	// Run the test script, support multiple containers
	RunNetworkMonitorScript(containers *types.KisaraNetworkTestSet) (*types.KisaraNetworkTestResultSet, error)
	// contains filtered or unexported methods
}

type OnContainerLaunch

type OnContainerLaunch func(*Docker, types.Container)

type OnContainerStop

type OnContainerStop func(*Docker, types.Container)

type OnDockerDaemonStart

type OnDockerDaemonStart func(*Docker, []types.Network)

type OnNetworkCreate

type OnNetworkCreate func(*Docker, types.Network)

type OnNetworkRemove

type OnNetworkRemove func(*Docker, types.Network)

type VirtualMachine

type VirtualMachine struct {
	VirtualMachineInf
	// contains filtered or unexported fields
}

func GetVirtualMachine

func GetVirtualMachine() *VirtualMachine

func (*VirtualMachine) Init

func (vm *VirtualMachine) Init(docker *Docker) error

func (*VirtualMachine) LaunchVm

func (vm *VirtualMachine) LaunchVm(
	docker *Docker, image_id string, port_protocols string,
	networks []string,
	limit types.KisaraVmLimit,
) (*types.VM, error)

func (*VirtualMachine) ListVm

func (vm *VirtualMachine) ListVm(docker *Docker) ([]*types.VM, error)

func (*VirtualMachine) StopVm

func (vm *VirtualMachine) StopVm(docker *Docker, vm_id string) error

type VirtualMachineInf

type VirtualMachineInf interface {
	// init vm
	Init(docker *Docker) error
	// launch vm
	LaunchVm(docker *Docker, image_id string, port_protocols string,
		networks []string,
		limit types.KisaraVmLimit) (*types.VM, error)
	// stop vm
	StopVm(docker *Docker, vm_id string) error
	// list vm
	ListVm(docker *Docker) ([]*types.VM, error)
	// get vm
	GetVm(docker *Docker, vm_id string) (*types.VM, error)
}

Jump to

Keyboard shortcuts

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