forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontainer_exec.go
47 lines (37 loc) · 1.27 KB
/
container_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
package client
import (
"bufio"
"context"
"net"
"net/url"
"github.com/alibaba/pouch/apis/types"
)
// ContainerCreateExec creates exec process.
func (client *APIClient) ContainerCreateExec(ctx context.Context, name string, config *types.ExecCreateConfig) (*types.ExecCreateResp, error) {
response, err := client.post(ctx, "/containers/"+name+"/exec", url.Values{}, config, nil)
if err != nil {
return nil, err
}
body := &types.ExecCreateResp{}
err = decodeBody(body, response.Body)
ensureCloseReader(response)
return body, err
}
// ContainerStartExec starts exec process.
func (client *APIClient) ContainerStartExec(ctx context.Context, execid string, config *types.ExecStartConfig) (net.Conn, *bufio.Reader, error) {
header := map[string][]string{
"Content-Type": {"text/plain"},
}
return client.hijack(ctx, "/exec/"+execid+"/start", url.Values{}, config, header)
}
// ContainerExecInspect get exec info with a specified exec id.
func (client *APIClient) ContainerExecInspect(ctx context.Context, execid string) (*types.ContainerExecInspect, error) {
resp, err := client.get(ctx, "/exec/"+execid+"/json", nil, nil)
if err != nil {
return nil, err
}
body := &types.ContainerExecInspect{}
err = decodeBody(body, resp.Body)
ensureCloseReader(resp)
return body, err
}