mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-10 18:04:27 +01:00
Refine the changes made on #468 by adding the containerID log field as soon as possible (before *any* virtcontainers calls). This requires that `setExternalLoggers()` be called more times, but it's essential to ensure the correct log fields are available as early as possible. Partially fixes #519. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
// Copyright (c) 2014,2015,2016 Docker, Inc.
|
|
// Copyright (c) 2017 Intel Corporation
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package main
|
|
|
|
import (
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
var noteText = `Use "` + name + ` list" to identify container statuses.`
|
|
|
|
var pauseCLICommand = cli.Command{
|
|
Name: "pause",
|
|
Usage: "suspend all processes in a container",
|
|
ArgsUsage: `<container-id>
|
|
|
|
Where "<container-id>" is the container name to be paused.`,
|
|
Description: `The pause command suspends all processes in a container.
|
|
|
|
` + noteText,
|
|
Action: func(context *cli.Context) error {
|
|
return toggleContainerPause(context.Args().First(), true)
|
|
},
|
|
}
|
|
|
|
var resumeCLICommand = cli.Command{
|
|
Name: "resume",
|
|
Usage: "unpause all previously paused processes in a container",
|
|
ArgsUsage: `<container-id>
|
|
|
|
Where "<container-id>" is the container name to be resumed.`,
|
|
Description: `The resume command unpauses all processes in a container.
|
|
|
|
` + noteText,
|
|
Action: func(context *cli.Context) error {
|
|
return toggleContainerPause(context.Args().First(), false)
|
|
},
|
|
}
|
|
|
|
func toggleContainerPause(containerID string, pause bool) (err error) {
|
|
kataLog = kataLog.WithField("container", containerID)
|
|
setExternalLoggers(kataLog)
|
|
|
|
// Checks the MUST and MUST NOT from OCI runtime specification
|
|
status, sandboxID, err := getExistingContainerInfo(containerID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
containerID = status.ID
|
|
|
|
kataLog = kataLog.WithFields(logrus.Fields{
|
|
"container": containerID,
|
|
"sandbox": sandboxID,
|
|
})
|
|
|
|
setExternalLoggers(kataLog)
|
|
|
|
if pause {
|
|
err = vci.PauseContainer(sandboxID, containerID)
|
|
} else {
|
|
err = vci.ResumeContainer(sandboxID, containerID)
|
|
}
|
|
|
|
return err
|
|
}
|