2016-03-18 14:53:27 -04:00
|
|
|
package libcontainerd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"syscall"
|
|
|
|
|
2016-07-15 17:12:07 -04:00
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
2016-03-18 14:53:27 -04:00
|
|
|
"github.com/Microsoft/hcsshim"
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type client struct {
|
|
|
|
clientCommon
|
|
|
|
|
|
|
|
// Platform specific properties below here (none presently on Windows)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Win32 error codes that are used for various workarounds
|
|
|
|
// These really should be ALL_CAPS to match golangs syscall library and standard
|
|
|
|
// Win32 error conventions, but golint insists on CamelCase.
|
|
|
|
const (
|
|
|
|
CoEClassstring = syscall.Errno(0x800401F3) // Invalid class string
|
|
|
|
ErrorNoNetwork = syscall.Errno(1222) // The network is not present or not started
|
|
|
|
ErrorBadPathname = syscall.Errno(161) // The specified path is invalid
|
|
|
|
ErrorInvalidObject = syscall.Errno(0x800710D8) // The object identifier does not represent a valid object
|
|
|
|
)
|
|
|
|
|
|
|
|
// defaultOwner is a tag passed to HCS to allow it to differentiate between
|
|
|
|
// container creator management stacks. We hard code "docker" in the case
|
|
|
|
// of docker.
|
|
|
|
const defaultOwner = "docker"
|
|
|
|
|
|
|
|
// Create is the entrypoint to create a container from a spec, and if successfully
|
|
|
|
// created, start it too.
|
2016-05-12 10:52:00 -04:00
|
|
|
func (clnt *client) Create(containerID string, checkpoint string, checkpointDir string, spec Spec, options ...CreateOption) error {
|
2016-07-22 18:20:14 -04:00
|
|
|
logrus.Debugln("libcontainerd: client.Create() with spec", spec)
|
2016-03-18 14:53:27 -04:00
|
|
|
|
2016-05-23 19:12:06 -04:00
|
|
|
configuration := &hcsshim.ContainerConfig{
|
2016-03-18 14:53:27 -04:00
|
|
|
SystemType: "Container",
|
|
|
|
Name: containerID,
|
|
|
|
Owner: defaultOwner,
|
|
|
|
|
|
|
|
VolumePath: spec.Root.Path,
|
|
|
|
IgnoreFlushesDuringBoot: spec.Windows.FirstStart,
|
|
|
|
LayerFolderPath: spec.Windows.LayerFolder,
|
|
|
|
HostName: spec.Hostname,
|
|
|
|
}
|
|
|
|
|
|
|
|
if spec.Windows.Networking != nil {
|
2016-05-23 19:12:06 -04:00
|
|
|
configuration.EndpointList = spec.Windows.Networking.EndpointList
|
2016-03-18 14:53:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if spec.Windows.Resources != nil {
|
|
|
|
if spec.Windows.Resources.CPU != nil {
|
|
|
|
if spec.Windows.Resources.CPU.Shares != nil {
|
2016-05-23 19:12:06 -04:00
|
|
|
configuration.ProcessorWeight = *spec.Windows.Resources.CPU.Shares
|
2016-03-18 14:53:27 -04:00
|
|
|
}
|
|
|
|
if spec.Windows.Resources.CPU.Percent != nil {
|
2016-05-23 19:12:06 -04:00
|
|
|
configuration.ProcessorMaximum = *spec.Windows.Resources.CPU.Percent * 100 // ProcessorMaximum is a value between 1 and 10000
|
2016-03-18 14:53:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if spec.Windows.Resources.Memory != nil {
|
|
|
|
if spec.Windows.Resources.Memory.Limit != nil {
|
2016-05-23 19:12:06 -04:00
|
|
|
configuration.MemoryMaximumInMB = *spec.Windows.Resources.Memory.Limit / 1024 / 1024
|
2016-03-18 14:53:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if spec.Windows.Resources.Storage != nil {
|
|
|
|
if spec.Windows.Resources.Storage.Bps != nil {
|
2016-05-23 19:12:06 -04:00
|
|
|
configuration.StorageBandwidthMaximum = *spec.Windows.Resources.Storage.Bps
|
2016-03-18 14:53:27 -04:00
|
|
|
}
|
|
|
|
if spec.Windows.Resources.Storage.Iops != nil {
|
2016-05-23 19:12:06 -04:00
|
|
|
configuration.StorageIOPSMaximum = *spec.Windows.Resources.Storage.Iops
|
2016-03-18 14:53:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-06 20:08:24 -04:00
|
|
|
if spec.Windows.HvRuntime != nil {
|
2016-06-29 19:10:57 -04:00
|
|
|
configuration.VolumePath = "" // Always empty for Hyper-V containers
|
2016-05-23 19:12:06 -04:00
|
|
|
configuration.HvPartition = true
|
|
|
|
configuration.HvRuntime = &hcsshim.HvRuntime{
|
2016-04-06 20:08:24 -04:00
|
|
|
ImagePath: spec.Windows.HvRuntime.ImagePath,
|
|
|
|
}
|
2016-06-24 18:24:06 -04:00
|
|
|
|
2016-07-03 13:58:11 -04:00
|
|
|
// Images with build version < 14350 don't support running with clone, but
|
2016-06-24 18:24:06 -04:00
|
|
|
// Windows cannot automatically detect this. Explicitly block cloning in this
|
|
|
|
// case.
|
|
|
|
if build := buildFromVersion(spec.Platform.OSVersion); build > 0 && build < 14350 {
|
|
|
|
configuration.HvRuntime.SkipTemplate = true
|
|
|
|
}
|
2016-04-06 20:08:24 -04:00
|
|
|
}
|
2016-03-18 14:53:27 -04:00
|
|
|
|
2016-05-23 19:12:06 -04:00
|
|
|
if configuration.HvPartition {
|
|
|
|
configuration.SandboxPath = filepath.Dir(spec.Windows.LayerFolder)
|
|
|
|
} else {
|
|
|
|
configuration.VolumePath = spec.Root.Path
|
|
|
|
configuration.LayerFolderPath = spec.Windows.LayerFolder
|
|
|
|
}
|
|
|
|
|
2016-04-13 16:34:07 -04:00
|
|
|
for _, option := range options {
|
|
|
|
if s, ok := option.(*ServicingOption); ok {
|
2016-05-23 19:12:06 -04:00
|
|
|
configuration.Servicing = s.IsServicing
|
2016-04-13 16:34:07 -04:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-18 14:53:27 -04:00
|
|
|
for _, layerPath := range spec.Windows.LayerPaths {
|
|
|
|
_, filename := filepath.Split(layerPath)
|
|
|
|
g, err := hcsshim.NameToGuid(filename)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-05-23 19:12:06 -04:00
|
|
|
configuration.Layers = append(configuration.Layers, hcsshim.Layer{
|
2016-03-18 14:53:27 -04:00
|
|
|
ID: g.ToString(),
|
|
|
|
Path: layerPath,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the mounts (volumes, bind mounts etc) to the structure
|
2016-05-23 19:12:06 -04:00
|
|
|
mds := make([]hcsshim.MappedDir, len(spec.Mounts))
|
2016-03-18 14:53:27 -04:00
|
|
|
for i, mount := range spec.Mounts {
|
2016-05-23 19:12:06 -04:00
|
|
|
mds[i] = hcsshim.MappedDir{
|
2016-03-18 14:53:27 -04:00
|
|
|
HostPath: mount.Source,
|
|
|
|
ContainerPath: mount.Destination,
|
|
|
|
ReadOnly: mount.Readonly}
|
|
|
|
}
|
2016-05-23 19:12:06 -04:00
|
|
|
configuration.MappedDirectories = mds
|
2016-03-18 14:53:27 -04:00
|
|
|
|
2016-05-23 19:12:06 -04:00
|
|
|
hcsContainer, err := hcsshim.CreateContainer(containerID, configuration)
|
2016-03-18 14:53:27 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construct a container object for calling start on it.
|
|
|
|
container := &container{
|
|
|
|
containerCommon: containerCommon{
|
|
|
|
process: process{
|
|
|
|
processCommon: processCommon{
|
|
|
|
containerID: containerID,
|
|
|
|
client: clnt,
|
|
|
|
friendlyName: InitFriendlyName,
|
|
|
|
},
|
2016-03-20 18:58:23 -04:00
|
|
|
commandLine: strings.Join(spec.Process.Args, " "),
|
2016-03-18 14:53:27 -04:00
|
|
|
},
|
|
|
|
processes: make(map[string]*process),
|
|
|
|
},
|
2016-05-23 19:12:06 -04:00
|
|
|
ociSpec: spec,
|
|
|
|
hcsContainer: hcsContainer,
|
2016-03-18 14:53:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
container.options = options
|
|
|
|
for _, option := range options {
|
|
|
|
if err := option.Apply(container); err != nil {
|
2016-07-22 18:20:14 -04:00
|
|
|
logrus.Errorf("libcontainerd: %v", err)
|
2016-03-18 14:53:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call start, and if it fails, delete the container from our
|
2016-05-25 14:08:15 -04:00
|
|
|
// internal structure, start will keep HCS in sync by deleting the
|
2016-03-18 14:53:27 -04:00
|
|
|
// container there.
|
2016-07-22 18:20:14 -04:00
|
|
|
logrus.Debugf("libcontainerd: Create() id=%s, Calling start()", containerID)
|
2016-03-18 14:53:27 -04:00
|
|
|
if err := container.start(); err != nil {
|
|
|
|
clnt.deleteContainer(containerID)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-07-22 18:20:14 -04:00
|
|
|
logrus.Debugf("libcontainerd: Create() id=%s completed successfully", containerID)
|
2016-03-18 14:53:27 -04:00
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddProcess is the handler for adding a process to an already running
|
|
|
|
// container. It's called through docker exec.
|
2016-07-15 17:12:07 -04:00
|
|
|
func (clnt *client) AddProcess(ctx context.Context, containerID, processFriendlyName string, procToAdd Process) error {
|
2016-03-18 14:53:27 -04:00
|
|
|
clnt.lock(containerID)
|
|
|
|
defer clnt.unlock(containerID)
|
|
|
|
container, err := clnt.getContainer(containerID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-05-23 19:12:06 -04:00
|
|
|
// Note we always tell HCS to
|
|
|
|
// create stdout as it's required regardless of '-i' or '-t' options, so that
|
|
|
|
// docker can always grab the output through logs. We also tell HCS to always
|
|
|
|
// create stdin, even if it's not used - it will be closed shortly. Stderr
|
|
|
|
// is only created if it we're not -t.
|
|
|
|
createProcessParms := hcsshim.ProcessConfig{
|
|
|
|
EmulateConsole: procToAdd.Terminal,
|
|
|
|
ConsoleSize: procToAdd.InitialConsoleSize,
|
|
|
|
CreateStdInPipe: true,
|
|
|
|
CreateStdOutPipe: true,
|
|
|
|
CreateStdErrPipe: !procToAdd.Terminal,
|
2016-03-18 14:53:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Take working directory from the process to add if it is defined,
|
|
|
|
// otherwise take from the first process.
|
|
|
|
if procToAdd.Cwd != "" {
|
|
|
|
createProcessParms.WorkingDirectory = procToAdd.Cwd
|
|
|
|
} else {
|
|
|
|
createProcessParms.WorkingDirectory = container.ociSpec.Process.Cwd
|
|
|
|
}
|
|
|
|
|
|
|
|
// Configure the environment for the process
|
|
|
|
createProcessParms.Environment = setupEnvironmentVariables(procToAdd.Env)
|
|
|
|
createProcessParms.CommandLine = strings.Join(procToAdd.Args, " ")
|
|
|
|
|
2016-07-22 18:20:14 -04:00
|
|
|
logrus.Debugf("libcontainerd: commandLine: %s", createProcessParms.CommandLine)
|
2016-03-18 14:53:27 -04:00
|
|
|
|
2016-05-23 19:12:06 -04:00
|
|
|
// Start the command running in the container.
|
2016-03-18 14:53:27 -04:00
|
|
|
var stdout, stderr io.ReadCloser
|
2016-05-23 19:12:06 -04:00
|
|
|
var stdin io.WriteCloser
|
|
|
|
newProcess, err := container.hcsContainer.CreateProcess(&createProcessParms)
|
|
|
|
if err != nil {
|
2016-07-22 18:20:14 -04:00
|
|
|
logrus.Errorf("libcontainerd: AddProcess(%s) CreateProcess() failed %s", containerID, err)
|
2016-05-23 19:12:06 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
stdin, stdout, stderr, err = newProcess.Stdio()
|
2016-03-18 14:53:27 -04:00
|
|
|
if err != nil {
|
2016-07-22 18:20:14 -04:00
|
|
|
logrus.Errorf("libcontainerd: %s getting std pipes failed %s", containerID, err)
|
2016-03-18 14:53:27 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-05-23 19:12:06 -04:00
|
|
|
iopipe := &IOPipe{Terminal: procToAdd.Terminal}
|
|
|
|
iopipe.Stdin = createStdInCloser(stdin, newProcess)
|
|
|
|
|
2016-05-20 22:04:20 -04:00
|
|
|
// TEMP: Work around Windows BS/DEL behavior.
|
2016-05-25 15:15:34 -04:00
|
|
|
iopipe.Stdin = fixStdinBackspaceBehavior(iopipe.Stdin, container.ociSpec.Platform.OSVersion, procToAdd.Terminal)
|
2016-05-20 22:04:20 -04:00
|
|
|
|
2016-03-18 14:53:27 -04:00
|
|
|
// Convert io.ReadClosers to io.Readers
|
|
|
|
if stdout != nil {
|
|
|
|
iopipe.Stdout = openReaderFromPipe(stdout)
|
|
|
|
}
|
|
|
|
if stderr != nil {
|
|
|
|
iopipe.Stderr = openReaderFromPipe(stderr)
|
|
|
|
}
|
|
|
|
|
2016-05-23 19:12:06 -04:00
|
|
|
pid := newProcess.Pid()
|
|
|
|
|
|
|
|
proc := &process{
|
|
|
|
processCommon: processCommon{
|
|
|
|
containerID: containerID,
|
|
|
|
friendlyName: processFriendlyName,
|
|
|
|
client: clnt,
|
|
|
|
systemPid: uint32(pid),
|
|
|
|
},
|
|
|
|
commandLine: createProcessParms.CommandLine,
|
|
|
|
hcsProcess: newProcess,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the process to the container's list of processes
|
|
|
|
container.processes[processFriendlyName] = proc
|
2016-03-18 14:53:27 -04:00
|
|
|
|
|
|
|
// Make sure the lock is not held while calling back into the daemon
|
|
|
|
clnt.unlock(containerID)
|
|
|
|
|
|
|
|
// Tell the engine to attach streams back to the client
|
|
|
|
if err := clnt.backend.AttachStreams(processFriendlyName, *iopipe); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lock again so that the defer unlock doesn't fail. (I really don't like this code)
|
|
|
|
clnt.lock(containerID)
|
|
|
|
|
|
|
|
// Spin up a go routine waiting for exit to handle cleanup
|
2016-05-23 19:12:06 -04:00
|
|
|
go container.waitExit(proc, false)
|
2016-03-18 14:53:27 -04:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Signal handles `docker stop` on Windows. While Linux has support for
|
|
|
|
// the full range of signals, signals aren't really implemented on Windows.
|
|
|
|
// We fake supporting regular stop and -9 to force kill.
|
|
|
|
func (clnt *client) Signal(containerID string, sig int) error {
|
|
|
|
var (
|
|
|
|
cont *container
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
// Get the container as we need it to find the pid of the process.
|
|
|
|
clnt.lock(containerID)
|
|
|
|
defer clnt.unlock(containerID)
|
|
|
|
if cont, err = clnt.getContainer(containerID); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-05-10 19:02:44 -04:00
|
|
|
cont.manualStopRequested = true
|
|
|
|
|
2016-07-22 18:20:14 -04:00
|
|
|
logrus.Debugf("libcontainerd: Signal() containerID=%s sig=%d pid=%d", containerID, sig, cont.systemPid)
|
2016-03-18 14:53:27 -04:00
|
|
|
|
|
|
|
if syscall.Signal(sig) == syscall.SIGKILL {
|
|
|
|
// Terminate the compute system
|
2016-05-23 19:12:06 -04:00
|
|
|
if err := cont.hcsContainer.Terminate(); err != nil {
|
2016-08-03 20:47:43 -04:00
|
|
|
if !hcsshim.IsPending(err) {
|
2016-07-22 18:20:14 -04:00
|
|
|
logrus.Errorf("libcontainerd: failed to terminate %s - %q", containerID, err)
|
2016-05-23 19:12:06 -04:00
|
|
|
}
|
2016-03-18 14:53:27 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Terminate Process
|
2016-08-03 20:47:43 -04:00
|
|
|
if err := cont.hcsProcess.Kill(); err != nil && !hcsshim.IsAlreadyStopped(err) {
|
2016-06-22 13:40:32 -04:00
|
|
|
// ignore errors
|
2016-07-22 18:20:14 -04:00
|
|
|
logrus.Warnf("libcontainerd: failed to terminate pid %d in %s: %q", cont.systemPid, containerID, err)
|
2016-03-18 14:53:27 -04:00
|
|
|
}
|
|
|
|
}
|
2016-05-10 19:02:44 -04:00
|
|
|
|
2016-03-18 14:53:27 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-04-18 05:48:13 -04:00
|
|
|
// While Linux has support for the full range of signals, signals aren't really implemented on Windows.
|
|
|
|
// We try to terminate the specified process whatever signal is requested.
|
|
|
|
func (clnt *client) SignalProcess(containerID string, processFriendlyName string, sig int) error {
|
|
|
|
clnt.lock(containerID)
|
|
|
|
defer clnt.unlock(containerID)
|
|
|
|
cont, err := clnt.getContainer(containerID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, p := range cont.processes {
|
|
|
|
if p.friendlyName == processFriendlyName {
|
2016-08-08 17:03:12 -04:00
|
|
|
return p.hcsProcess.Kill()
|
2016-04-18 05:48:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("SignalProcess could not find process %s in %s", processFriendlyName, containerID)
|
|
|
|
}
|
|
|
|
|
2016-03-18 14:53:27 -04:00
|
|
|
// Resize handles a CLI event to resize an interactive docker run or docker exec
|
|
|
|
// window.
|
|
|
|
func (clnt *client) Resize(containerID, processFriendlyName string, width, height int) error {
|
|
|
|
// Get the libcontainerd container object
|
|
|
|
clnt.lock(containerID)
|
|
|
|
defer clnt.unlock(containerID)
|
|
|
|
cont, err := clnt.getContainer(containerID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-05-23 19:12:06 -04:00
|
|
|
h, w := uint16(height), uint16(width)
|
|
|
|
|
2016-03-18 14:53:27 -04:00
|
|
|
if processFriendlyName == InitFriendlyName {
|
2016-07-22 18:20:14 -04:00
|
|
|
logrus.Debugln("libcontainerd: resizing systemPID in", containerID, cont.process.systemPid)
|
2016-05-23 19:12:06 -04:00
|
|
|
return cont.process.hcsProcess.ResizeConsole(w, h)
|
2016-03-18 14:53:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, p := range cont.processes {
|
|
|
|
if p.friendlyName == processFriendlyName {
|
2016-07-22 18:20:14 -04:00
|
|
|
logrus.Debugln("libcontainerd: resizing exec'd process", containerID, p.systemPid)
|
2016-05-23 19:12:06 -04:00
|
|
|
return p.hcsProcess.ResizeConsole(w, h)
|
2016-03-18 14:53:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("Resize could not find containerID %s to resize", containerID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pause handles pause requests for containers
|
|
|
|
func (clnt *client) Pause(containerID string) error {
|
|
|
|
return errors.New("Windows: Containers cannot be paused")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resume handles resume requests for containers
|
|
|
|
func (clnt *client) Resume(containerID string) error {
|
|
|
|
return errors.New("Windows: Containers cannot be paused")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stats handles stats requests for containers
|
|
|
|
func (clnt *client) Stats(containerID string) (*Stats, error) {
|
|
|
|
return nil, errors.New("Windows: Stats not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restore is the handler for restoring a container
|
|
|
|
func (clnt *client) Restore(containerID string, unusedOnWindows ...CreateOption) error {
|
2016-03-18 23:29:27 -04:00
|
|
|
// TODO Windows: Implement this. For now, just tell the backend the container exited.
|
2016-07-22 18:20:14 -04:00
|
|
|
logrus.Debugf("libcontainerd: Restore(%s)", containerID)
|
2016-03-18 14:53:27 -04:00
|
|
|
return clnt.backend.StateChanged(containerID, StateInfo{
|
2016-04-01 20:02:38 -04:00
|
|
|
CommonStateInfo: CommonStateInfo{
|
|
|
|
State: StateExit,
|
|
|
|
ExitCode: 1 << 31,
|
|
|
|
}})
|
2016-03-18 14:53:27 -04:00
|
|
|
}
|
|
|
|
|
2016-03-20 18:58:23 -04:00
|
|
|
// GetPidsForContainer returns a list of process IDs running in a container.
|
|
|
|
// Although implemented, this is not used in Windows.
|
2016-03-18 14:53:27 -04:00
|
|
|
func (clnt *client) GetPidsForContainer(containerID string) ([]int, error) {
|
2016-03-20 18:58:23 -04:00
|
|
|
var pids []int
|
|
|
|
clnt.lock(containerID)
|
|
|
|
defer clnt.unlock(containerID)
|
|
|
|
cont, err := clnt.getContainer(containerID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the first process
|
|
|
|
pids = append(pids, int(cont.containerCommon.systemPid))
|
|
|
|
// And add all the exec'd processes
|
|
|
|
for _, p := range cont.processes {
|
|
|
|
pids = append(pids, int(p.processCommon.systemPid))
|
|
|
|
}
|
|
|
|
return pids, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Summary returns a summary of the processes running in a container.
|
|
|
|
// This is present in Windows to support docker top. In linux, the
|
|
|
|
// engine shells out to ps to get process information. On Windows, as
|
|
|
|
// the containers could be Hyper-V containers, they would not be
|
|
|
|
// visible on the container host. However, libcontainerd does have
|
|
|
|
// that information.
|
|
|
|
func (clnt *client) Summary(containerID string) ([]Summary, error) {
|
2016-08-17 18:46:28 -04:00
|
|
|
|
|
|
|
// Get the libcontainerd container object
|
2016-03-20 18:58:23 -04:00
|
|
|
clnt.lock(containerID)
|
|
|
|
defer clnt.unlock(containerID)
|
2016-08-17 18:46:28 -04:00
|
|
|
container, err := clnt.getContainer(containerID)
|
2016-03-20 18:58:23 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-08-17 18:46:28 -04:00
|
|
|
p, err := container.hcsContainer.ProcessList()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2016-03-20 18:58:23 -04:00
|
|
|
}
|
2016-08-17 18:46:28 -04:00
|
|
|
pl := make([]Summary, len(p))
|
|
|
|
for i := range p {
|
|
|
|
pl[i] = Summary(p[i])
|
|
|
|
}
|
|
|
|
return pl, nil
|
2016-03-18 14:53:27 -04:00
|
|
|
}
|
|
|
|
|
2016-03-18 23:29:27 -04:00
|
|
|
// UpdateResources updates resources for a running container.
|
2016-03-18 14:53:27 -04:00
|
|
|
func (clnt *client) UpdateResources(containerID string, resources Resources) error {
|
|
|
|
// Updating resource isn't supported on Windows
|
|
|
|
// but we should return nil for enabling updating container
|
|
|
|
return nil
|
|
|
|
}
|
2016-05-12 10:52:00 -04:00
|
|
|
|
|
|
|
func (clnt *client) CreateCheckpoint(containerID string, checkpointID string, checkpointDir string, exit bool) error {
|
|
|
|
return errors.New("Windows: Containers do not support checkpoints")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (clnt *client) DeleteCheckpoint(containerID string, checkpointID string, checkpointDir string) error {
|
|
|
|
return errors.New("Windows: Containers do not support checkpoints")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (clnt *client) ListCheckpoints(containerID string, checkpointDir string) (*Checkpoints, error) {
|
|
|
|
return nil, errors.New("Windows: Containers do not support checkpoints")
|
|
|
|
}
|