This repository has been archived by the owner on Feb 8, 2021. It is now read-only.
/
exec.go
72 lines (57 loc) · 1.88 KB
/
exec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package daemon
import (
"fmt"
"io"
"github.com/golang/glog"
)
func (daemon *Daemon) ExitCode(containerId, execId string) (int, error) {
p, id, ok := daemon.PodList.GetByContainerIdOrName(containerId)
if !ok {
err := fmt.Errorf("cannot find container %s", containerId)
glog.Error(err)
return 255, err
}
glog.V(1).Infof("Get Exec Code for container %s", containerId)
code, err := p.GetExitCode(id, execId)
return int(code), err
}
func (daemon *Daemon) CreateExec(containerId, cmd string, terminal bool) (string, error) {
p, id, ok := daemon.PodList.GetByContainerIdOrName(containerId)
if !ok {
err := fmt.Errorf("cannot find container %s", containerId)
glog.Error(err)
return "", err
}
glog.V(1).Infof("Create Exec for container %s", containerId)
return p.CreateExec(id, cmd, terminal)
}
func (daemon *Daemon) StartExec(stdin io.ReadCloser, stdout io.WriteCloser, containerId, execId string) error {
p, id, ok := daemon.PodList.GetByContainerIdOrName(containerId)
if !ok {
err := fmt.Errorf("cannot find container %s", containerId)
glog.Error(err)
return err
}
glog.V(1).Infof("Start Exec for container %s", containerId)
return p.StartExec(stdin, stdout, id, execId)
}
func (daemon *Daemon) KillExec(containerId string, execId string, signal int64) error {
p, _, ok := daemon.PodList.GetByContainerIdOrName(containerId)
if !ok {
err := fmt.Errorf("cannot find container %s", containerId)
glog.Error(err)
return err
}
glog.V(1).Infof("Kill Exec for container %s", containerId)
return p.KillExec(execId, signal)
}
func (daemon *Daemon) ExecVM(podID, cmd string, stdin io.ReadCloser, stdout, stderr io.WriteCloser) (int, error) {
glog.V(3).Infof("Starting ExecVM for pod %s", podID)
p, ok := daemon.PodList.Get(podID)
if !ok {
err := fmt.Errorf("cannot find pod %s", podID)
glog.Error(err)
return -1, err
}
return p.ExecVM(cmd, stdin, stdout, stderr)
}