hypervisor

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2015 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BaseDir         = "/var/run/hyper"
	HyperSockName   = "hyper.sock"
	TtySockName     = "tty.sock"
	ConsoleSockName = "console.sock"
	ShareDirTag     = "share_dir"
	DefaultKernel   = "/var/lib/hyper/kernel"
	DefaultInitrd   = "/var/lib/hyper/hyper-initrd.img"
	PciAddrFrom     = 0x05
	ExitChar        = 4
	InterfaceCount  = 1
)
View Source
const (
	EVENT_VM_START_FAILED = iota
	EVENT_VM_EXIT
	EVENT_VM_KILL
	EVENT_VM_TIMEOUT
	EVENT_POD_FINISH
	EVENT_INIT_CONNECTED
	EVENT_CONTAINER_ADD
	EVENT_CONTAINER_DELETE
	EVENT_VOLUME_ADD
	EVENT_VOLUME_DELETE
	EVENT_BLOCK_INSERTED
	EVENT_BLOCK_EJECTED
	EVENT_INTERFACE_ADD
	EVENT_INTERFACE_DELETE
	EVENT_INTERFACE_INSERTED
	EVENT_INTERFACE_EJECTED
	EVENT_SERIAL_ADD
	EVENT_SERIAL_DELETE
	EVENT_TTY_OPEN
	EVENT_TTY_CLOSE
	COMMAND_RUN_POD
	COMMAND_REPLACE_POD
	COMMAND_STOP_POD
	COMMAND_SHUTDOWN
	COMMAND_RELEASE
	COMMAND_EXEC
	COMMAND_ATTACH
	COMMAND_DETACH
	COMMAND_WINDOWSIZE
	COMMAND_ACK
	ERROR_INIT_FAIL
	ERROR_QMP_FAIL
	ERROR_INTERRUPTED
	ERROR_CMD_FAIL
)
View Source
const (
	INIT_RESERVED = iota
	INIT_STARTPOD
	INIT_GETPOD
	INIT_STOPPOD
	INIT_DESTROYPOD
	INIT_NEWCONTAINER
	INIT_EXECCMD
	INIT_FINISHCMD
	INIT_READY
	INIT_ACK
	INIT_ERROR
	INIT_WINSIZE
	INIT_PING
	INIT_FINISHPOD
)
View Source
const (
	PREPARING_CONTAINER = iota
	PREPARING_VOLUME
	PREPARING_BLOCK
	PREPARING_BIND_DIR
)

Variables

This section is empty.

Functions

func CreateContainer

func CreateContainer(userPod *pod.UserPod, sharedDir string, hub chan VmEvent) (string, error)

func CreateInterface

func CreateInterface(index int, pciAddr int, name string, isDefault bool, addrOnly bool,
	maps []pod.UserContainerPort, callback chan VmEvent)

func DiskId2Name

func DiskId2Name(id int) string

func EventString

func EventString(ev int) string

func ReleaseInterface

func ReleaseInterface(index int, ipAddr string, file *os.File,
	maps []pod.UserContainerPort, callback chan VmEvent)

func TtyLiner

func TtyLiner(conn io.Reader, output chan string)

func UmountAufsContainer

func UmountAufsContainer(shareDir, image string, index int, hub chan VmEvent)

func UmountDMDevice

func UmountDMDevice(deviceFullPath, name string, hub chan VmEvent)

func UmountOverlayContainer

func UmountOverlayContainer(shareDir, image string, index int, hub chan VmEvent)

func UmountVolume

func UmountVolume(shareDir, volPath string, name string, hub chan VmEvent)

func UnixSocketConnect

func UnixSocketConnect(name string) (conn net.Conn, err error)

func VmAssociate

func VmAssociate(driver HypervisorDriver, vmId string,
	hub chan VmEvent, client chan *types.QemuResponse,
	wg *sync.WaitGroup, pack []byte)

func VmLoop

func VmLoop(driver HypervisorDriver, vmId string, hub chan VmEvent, client chan *types.QemuResponse, boot *BootConfig)

Types

type AttachCommand

type AttachCommand struct {
	Container string
	Streams   *TtyIO
	Size      *WindowSize
}

func (*AttachCommand) Event

func (qe *AttachCommand) Event() int

type BlockdevInsertedEvent

type BlockdevInsertedEvent struct {
	Name       string
	SourceType string //image or volume
	DeviceName string
	ScsiId     int
}

func (*BlockdevInsertedEvent) Event

func (qe *BlockdevInsertedEvent) Event() int

type BlockdevRemovedEvent

type BlockdevRemovedEvent struct {
	Name    string
	Success bool
}

func (*BlockdevRemovedEvent) Event

func (qe *BlockdevRemovedEvent) Event() int

type BootConfig

type BootConfig struct {
	CPU    int
	Memory int
	Kernel string
	Initrd string
	Bios   string
	Cbfs   string
}

type CommandAck

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

func (*CommandAck) Event

func (qe *CommandAck) Event() int

type CommandError

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

func (*CommandError) Event

func (qe *CommandError) Event() int

type ContainerCreatedEvent

type ContainerCreatedEvent struct {
	Index  int
	Id     string
	Rootfs string
	Image  string // if fstype is `dir`, this should be a path relative to share_dir
	// which described the mounted aufs or overlayfs dir.
	Fstype     string
	Workdir    string
	Entrypoint []string
	Cmd        []string
	Envs       map[string]string
}

func (*ContainerCreatedEvent) Event

func (qe *ContainerCreatedEvent) Event() int

type ContainerInfo

type ContainerInfo struct {
	Id     string
	Rootfs string
	Image  string // if fstype is `dir`, this should be a path relative to share_dir
	// which described the mounted aufs or overlayfs dir.
	Fstype     string
	Workdir    string
	Entrypoint []string
	Cmd        []string
	Envs       map[string]string
}

type ContainerUnmounted

type ContainerUnmounted struct {
	Index   int
	Success bool
}

func (*ContainerUnmounted) Event

func (qe *ContainerUnmounted) Event() int

type DecodedMessage

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

Message

type DeviceFailed

type DeviceFailed struct {
	Session VmEvent
}

func (*DeviceFailed) Event

func (qe *DeviceFailed) Event() int

type DriverContext

type DriverContext interface {
	Launch(ctx *VmContext)
	Associate(ctx *VmContext)
	Dump() (map[string]interface{}, error)

	AddDisk(ctx *VmContext, name, sourceType, filename, format string, id int)
	RemoveDisk(ctx *VmContext, filename, format string, id int, callback VmEvent)

	AddNic(ctx *VmContext, host *HostNicInfo, guest *GuestNicInfo)
	RemoveNic(ctx *VmContext, device, mac string, callback VmEvent)

	Shutdown(ctx *VmContext)
	Kill(ctx *VmContext)

	BuildinNetwork() bool
	Close()
}

type EmptyContext

type EmptyContext struct{}

func (*EmptyContext) AddDisk

func (ec *EmptyContext) AddDisk(ctx *VmContext, name, sourceType, filename, format string, id int)

func (*EmptyContext) AddNic

func (ec *EmptyContext) AddNic(ctx *VmContext, host *HostNicInfo, guest *GuestNicInfo)

func (*EmptyContext) Associate

func (ec *EmptyContext) Associate(ctx *VmContext)

func (*EmptyContext) BuildinNetwork

func (ec *EmptyContext) BuildinNetwork() bool

func (*EmptyContext) Close

func (ec *EmptyContext) Close()

func (*EmptyContext) Dump

func (ec *EmptyContext) Dump() (map[string]interface{}, error)

func (*EmptyContext) Kill

func (ec *EmptyContext) Kill(ctx *VmContext)

func (*EmptyContext) Launch

func (ec *EmptyContext) Launch(ctx *VmContext)

func (*EmptyContext) RemoveDisk

func (ec *EmptyContext) RemoveDisk(ctx *VmContext, filename, format string, id int, callback VmEvent)

func (*EmptyContext) RemoveNic

func (ec *EmptyContext) RemoveNic(ctx *VmContext, device, mac string, callback VmEvent)

func (*EmptyContext) Shutdown

func (ec *EmptyContext) Shutdown(ctx *VmContext)

type EmptyDriver

type EmptyDriver struct{}

func (*EmptyDriver) InitContext

func (ed *EmptyDriver) InitContext(homeDir string) DriverContext

func (*EmptyDriver) Initialize

func (ed *EmptyDriver) Initialize() error

func (*EmptyDriver) LoadContext

func (ed *EmptyDriver) LoadContext(persisted map[string]interface{}) (DriverContext, error)

type ExecCommand

type ExecCommand struct {
	Container string   `json:"container,omitempty"`
	Sequence  uint64   `json:"seq"`
	Command   []string `json:"cmd"`
	Streams   *TtyIO   `json:"-"`
}

func (*ExecCommand) Event

func (qe *ExecCommand) Event() int

type FinishCmd

type FinishCmd struct {
	Seq uint64 `json:"seq"`
}

type GuestNicInfo

type GuestNicInfo struct {
	Device  string
	Ipaddr  string
	Index   int
	Busaddr int
}

type HostNicInfo

type HostNicInfo struct {
	Fd      uint64
	Device  string
	Mac     string
	Bridge  string
	Gateway string
}

type HypervisorDriver

type HypervisorDriver interface {
	Initialize() error

	InitContext(homeDir string) DriverContext

	LoadContext(persisted map[string]interface{}) (DriverContext, error)
}

type InitConnectedEvent

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

func (*InitConnectedEvent) Event

func (qe *InitConnectedEvent) Event() int

type InitFailedEvent

type InitFailedEvent struct {
	Reason string
}

func (*InitFailedEvent) Event

func (qe *InitFailedEvent) Event() int

type InterfaceCreated

type InterfaceCreated struct {
	Index      int
	PCIAddr    int
	Fd         *os.File
	Bridge     string
	HostDevice string
	DeviceName string
	MacAddr    string
	IpAddr     string
	NetMask    string
	RouteTable []*RouteRule
}

func (*InterfaceCreated) Event

func (qe *InterfaceCreated) Event() int

type InterfaceReleased

type InterfaceReleased struct {
	Index   int
	Success bool
}

func (*InterfaceReleased) Event

func (qe *InterfaceReleased) Event() int

type Interrupted

type Interrupted struct {
	Reason string
}

func (*Interrupted) Event

func (qe *Interrupted) Event() int

type NetDevInsertedEvent

type NetDevInsertedEvent struct {
	Index      int
	DeviceName string
	Address    int
}

func (*NetDevInsertedEvent) Event

func (qe *NetDevInsertedEvent) Event() int

type NetDevRemovedEvent

type NetDevRemovedEvent struct {
	Index int
}

func (*NetDevRemovedEvent) Event

func (qe *NetDevRemovedEvent) Event() int

type PersistInfo

type PersistInfo struct {
	Id          string
	DriverInfo  map[string]interface{}
	UserSpec    *pod.UserPod
	VmSpec      *VmPod
	HwStat      *VmHwStatus
	VolumeList  []*PersistVolumeInfo
	NetworkList []*PersistNetworkInfo
}

type PersistNetworkInfo

type PersistNetworkInfo struct {
	Index      int
	PciAddr    int
	DeviceName string
	IpAddr     string
}

type PersistVolumeInfo

type PersistVolumeInfo struct {
	Name       string
	Filename   string
	Format     string
	Fstype     string
	DeviceName string
	ScsiId     int
	Containers []int
	MontPoints []string
}

type PodFinished

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

func (*PodFinished) Event

func (qe *PodFinished) Event() int

type PreparingItem

type PreparingItem interface {
	ItemType() string
}

type ReleaseVMCommand

type ReleaseVMCommand struct{}

func (*ReleaseVMCommand) Event

func (qe *ReleaseVMCommand) Event() int

type ReplacePodCommand

type ReplacePodCommand RunPodCommand

func (*ReplacePodCommand) Event

func (qe *ReplacePodCommand) Event() int

type RouteRule

type RouteRule struct {
	Destination string
	Gateway     string
	ViaThis     bool
}

type RunPodCommand

type RunPodCommand struct {
	Spec       *pod.UserPod
	Containers []*ContainerInfo
	Volumes    []*VolumeInfo
	Wg         *sync.WaitGroup
}

func (*RunPodCommand) Event

func (qe *RunPodCommand) Event() int

type RunningContainer

type RunningContainer struct {
	Id string `json:"id"`
}

type ShutdownCommand

type ShutdownCommand struct {
	Wait bool
}

func (*ShutdownCommand) Event

func (qe *ShutdownCommand) Event() int

type StopPodCommand

type StopPodCommand struct{}

func (*StopPodCommand) Event

func (qe *StopPodCommand) Event() int

type TtyIO

type TtyIO struct {
	Stdin     io.ReadCloser
	Stdout    io.WriteCloser
	ClientTag string
	Callback  chan *types.QemuResponse
}

func LinerTty

func LinerTty(output chan string) *TtyIO

func (*TtyIO) Close

func (tty *TtyIO) Close() string

type VmContainer

type VmContainer struct {
	Id            string               `json:"id"`
	Rootfs        string               `json:"rootfs"`
	Fstype        string               `json:"fstype,omitempty"`
	Image         string               `json:"image"`
	Volumes       []VmVolumeDescriptor `json:"volumes,omitempty"`
	Fsmap         []VmFsmapDescriptor  `json:"fsmap,omitempty"`
	Tty           uint64               `json:"tty,omitempty"`
	Workdir       string               `json:"workdir"`
	Entrypoint    []string             `json:"-"`
	Cmd           []string             `json:"cmd"`
	Envs          []VmEnvironmentVar   `json:"envs,omitempty"`
	RestartPolicy string               `json:"restartPolicy"`
}

type VmContext

type VmContext struct {
	Id string

	Boot *BootConfig

	// Communication Context
	Hub chan VmEvent

	DCtx DriverContext

	HomeDir         string
	HyperSockName   string
	TtySockName     string
	ConsoleSockName string
	ShareDir        string
	// contains filtered or unexported fields
}

func InitContext

func InitContext(dr HypervisorDriver, id string, hub chan VmEvent, client chan *types.QemuResponse, dc DriverContext, boot *BootConfig) (*VmContext, error)

func (*VmContext) Become

func (ctx *VmContext) Become(handler stateHandler, desc string)

func (*VmContext) Close

func (ctx *VmContext) Close()

func (*VmContext) InitDeviceContext

func (ctx *VmContext) InitDeviceContext(spec *pod.UserPod, wg *sync.WaitGroup,
	cInfo []*ContainerInfo, vInfo []*VolumeInfo)

InitDeviceContext will init device info in context

func (*VmContext) Lookup

func (ctx *VmContext) Lookup(container string) int

type VmEnvironmentVar

type VmEnvironmentVar struct {
	Env   string `json:"env"`
	Value string `json:"value"`
}

type VmEvent

type VmEvent interface {
	Event() int
}

type VmExit

type VmExit struct{}

func (*VmExit) Event

func (qe *VmExit) Event() int

type VmFsmapDescriptor

type VmFsmapDescriptor struct {
	Source   string `json:"source"`
	Path     string `json:"path"`
	ReadOnly bool   `json:"readOnly"`
}

type VmHwStatus

type VmHwStatus struct {
	PciAddr  int    //next available pci addr for pci hotplug
	ScsiId   int    //next available scsi id for scsi hotplug
	AttachId uint64 //next available attachId for attached tty
}

type VmKilledEvent

type VmKilledEvent struct {
	Success bool
}

func (*VmKilledEvent) Event

func (qe *VmKilledEvent) Event() int

type VmNetworkInf

type VmNetworkInf struct {
	Device    string `json:"device"`
	IpAddress string `json:"ipAddress"`
	NetMask   string `json:"netMask"`
}

type VmOnDiskInfo

type VmOnDiskInfo struct {
	QmpSockName     string
	HyperSockName   string
	TtySockName     string
	ConsoleSockName string
	ShareDir        string
}

type VmPod

type VmPod struct {
	Hostname   string         `json:"hostname"`
	Containers []VmContainer  `json:"containers"`
	Interfaces []VmNetworkInf `json:"interfaces"`
	Routes     []VmRoute      `json:"routes"`
	ShareDir   string         `json:"shareDir"`
}

type VmRoute

type VmRoute struct {
	Dest    string `json:"dest"`
	Gateway string `json:"gateway,omitempty"`
	Device  string `json:"device,omitempty"`
}

type VmStartFailEvent

type VmStartFailEvent struct {
	Message string
}

func (*VmStartFailEvent) Event

func (qe *VmStartFailEvent) Event() int

type VmTimeout

type VmTimeout struct{}

func (*VmTimeout) Event

func (qe *VmTimeout) Event() int

type VmVolumeDescriptor

type VmVolumeDescriptor struct {
	Device   string `json:"device"`
	Mount    string `json:"mount"`
	Fstype   string `json:"fstype,omitempty"`
	ReadOnly bool   `json:"readOnly"`
}

Vm DataStructure

type VolumeInfo

type VolumeInfo struct {
	Name     string //volumen name in spec
	Filepath string //block dev absolute path, or dir path relative to share dir
	Fstype   string //"xfs", "ext4" etc. for block dev, or "dir" for dir path
	Format   string //"raw" (or "qcow2") for volume, no meaning for dir path
}

type VolumeReadyEvent

type VolumeReadyEvent struct {
	Name     string //volumen name in spec
	Filepath string //block dev absolute path, or dir path relative to share dir
	Fstype   string //"xfs", "ext4" etc. for block dev, or "dir" for dir path
	Format   string //"raw" (or "qcow2") for volume, no meaning for dir path
}

func (*VolumeReadyEvent) Event

func (qe *VolumeReadyEvent) Event() int

type VolumeUnmounted

type VolumeUnmounted struct {
	Name    string
	Success bool
}

func (*VolumeUnmounted) Event

func (qe *VolumeUnmounted) Event() int

type WindowSize

type WindowSize struct {
	Row    uint16 `json:"row"`
	Column uint16 `json:"column"`
}

type WindowSizeCommand

type WindowSizeCommand struct {
	ClientTag string
	Size      *WindowSize
}

func (*WindowSizeCommand) Event

func (qe *WindowSizeCommand) Event() int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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