mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-04 02:56:18 +00:00
cli: support factory status command
It checks vm factory status and prints the result. Fixes: #545 Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
parent
16600efc1d
commit
03f2459388
@ -18,6 +18,7 @@ import (
|
|||||||
var factorySubCmds = []cli.Command{
|
var factorySubCmds = []cli.Command{
|
||||||
initFactoryCommand,
|
initFactoryCommand,
|
||||||
destroyFactoryCommand,
|
destroyFactoryCommand,
|
||||||
|
statusFactoryCommand,
|
||||||
}
|
}
|
||||||
|
|
||||||
var factoryCLICommand = cli.Command{
|
var factoryCLICommand = cli.Command{
|
||||||
@ -96,3 +97,37 @@ var destroyFactoryCommand = cli.Command{
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var statusFactoryCommand = cli.Command{
|
||||||
|
Name: "status",
|
||||||
|
Usage: "query the status of VM factory",
|
||||||
|
Action: func(context *cli.Context) error {
|
||||||
|
runtimeConfig, ok := context.App.Metadata["runtimeConfig"].(oci.RuntimeConfig)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("invalid runtime config")
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
fmt.Println("vm factory is off")
|
||||||
|
} else {
|
||||||
|
f.CloseFactory()
|
||||||
|
fmt.Println("vm factory is on")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Println("vm factory not enabled")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
@ -115,3 +115,39 @@ func TestFactoryCLIFunctionDestroy(t *testing.T) {
|
|||||||
err = fn(ctx)
|
err = fn(ctx)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFactoryCLIFunctionStatus(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
tmpdir, err := ioutil.TempDir("", "")
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
|
runtimeConfig, err := newTestRuntimeConfig(tmpdir, testConsole, true)
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
set := flag.NewFlagSet("", 0)
|
||||||
|
|
||||||
|
set.String("console-socket", "", "")
|
||||||
|
|
||||||
|
app := cli.NewApp()
|
||||||
|
ctx := cli.NewContext(app, set, nil)
|
||||||
|
app.Name = "foo"
|
||||||
|
|
||||||
|
// No template
|
||||||
|
ctx.App.Metadata = map[string]interface{}{
|
||||||
|
"runtimeConfig": runtimeConfig,
|
||||||
|
}
|
||||||
|
fn, ok := statusFactoryCommand.Action.(func(context *cli.Context) error)
|
||||||
|
assert.True(ok)
|
||||||
|
err = fn(ctx)
|
||||||
|
assert.Nil(err)
|
||||||
|
|
||||||
|
// With template
|
||||||
|
runtimeConfig.FactoryConfig.Template = true
|
||||||
|
runtimeConfig.HypervisorType = vc.MockHypervisor
|
||||||
|
runtimeConfig.AgentType = vc.NoopAgentType
|
||||||
|
ctx.App.Metadata["runtimeConfig"] = runtimeConfig
|
||||||
|
err = fn(ctx)
|
||||||
|
assert.Nil(err)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user