cli: add vm factory management subcommand

Add enable_template option to the config file.
When it is set, enable the vm template factory.

cache factory cannot be used by kata cli directly because
it requires a running daemon to maintain the cache VMs.

`kata-runtime factory init` would initialize the vm factory and
`kata-runtime factory destroy` would destroy the vm factory.

When configured, a vm factory is loaded before creating new sandboxes.

Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
Peng Tao
2018-07-13 17:58:10 +08:00
parent a7d888febc
commit 0309e59cf8
8 changed files with 287 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ import (
"strings"
vc "github.com/kata-containers/runtime/virtcontainers"
vf "github.com/kata-containers/runtime/virtcontainers/factory"
"github.com/kata-containers/runtime/virtcontainers/pkg/oci"
"github.com/urfave/cli"
)
@@ -106,6 +107,25 @@ func create(containerID, bundlePath, console, pidFilePath string, detach bool,
return err
}
if runtimeConfig.FactoryConfig.Template {
factoryConfig := vf.Config{
Template: true,
VMConfig: vc.VMConfig{
HypervisorType: runtimeConfig.HypervisorType,
HypervisorConfig: runtimeConfig.HypervisorConfig,
AgentType: runtimeConfig.AgentType,
AgentConfig: runtimeConfig.AgentConfig,
},
}
kataLog.WithField("factory", factoryConfig).Info("load vm factory")
f, err := vf.NewFactory(factoryConfig, true)
if err != nil {
kataLog.WithError(err).Info("load vm factory failed")
} else {
vci.SetFactory(f)
}
}
disableOutput := noNeedForOutput(detach, ociSpec.Process.Terminal)
var process vc.Process