mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-28 10:44:25 +01:00
Add vm factory support per design in the VM Factory plugin section. The vm factory controls how a new vm is created: 1. direct: vm is created directly 2. template: vm is created via vm template. A template vm is pre-created and saved. Later vm is just a clone of the template vm so that they readonly share a portion of initial memory (including kernel, initramfs and the kata agent). CPU and memory are hot plugged when necessary. 3. cache: vm is created via vm caches. A set of cached vm are pre-created and maintained alive. New vms are created by just picking a cached vm. CPU and memory are hot plugged when necessary. Fixes: #303 Signed-off-by: Peng Tao <bergwolf@gmail.com>
47 lines
890 B
Go
47 lines
890 B
Go
// Copyright (c) 2018 HyperHQ Inc.
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
// direct implements base vm factory without vm templating.
|
|
|
|
package direct
|
|
|
|
import (
|
|
vc "github.com/kata-containers/runtime/virtcontainers"
|
|
"github.com/kata-containers/runtime/virtcontainers/factory/base"
|
|
)
|
|
|
|
type direct struct {
|
|
config vc.VMConfig
|
|
}
|
|
|
|
// New returns a new direct vm factory.
|
|
func New(config vc.VMConfig) base.FactoryBase {
|
|
return &direct{config}
|
|
}
|
|
|
|
// Config returns the direct factory's configuration.
|
|
func (d *direct) Config() vc.VMConfig {
|
|
return d.config
|
|
}
|
|
|
|
// GetBaseVM create a new VM directly.
|
|
func (d *direct) GetBaseVM() (*vc.VM, error) {
|
|
vm, err := vc.NewVM(d.config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = vm.Pause()
|
|
if err != nil {
|
|
vm.Stop()
|
|
return nil, err
|
|
}
|
|
|
|
return vm, nil
|
|
}
|
|
|
|
// CloseFactory closes the direct vm factory.
|
|
func (d *direct) CloseFactory() {
|
|
}
|