forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inspect.go
81 lines (73 loc) · 1.89 KB
/
inspect.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
73
74
75
76
77
78
79
80
81
package main
import (
"encoding/json"
"fmt"
"github.com/spf13/cobra"
)
// inspectDescription is used to describe inspect command in detail and auto generate command doc.
var inspectDescription = "Return detailed information on Pouch container"
// InspectCommand is used to implement 'inspect' command.
type InspectCommand struct {
baseCommand
}
// Init initializes InspectCommand command.
func (p *InspectCommand) Init(c *Cli) {
p.cli = c
p.cmd = &cobra.Command{
Use: "inspect [container]",
Short: "Get the detailed information of container",
Long: inspectDescription,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return p.runInpsect(args)
},
Example: inspectExample(),
}
}
// runInpsect is the entry of InspectCommand command.
func (p *InspectCommand) runInpsect(args []string) error {
apiClient := p.cli.Client()
name := args[0]
container, err := apiClient.ContainerGet(name)
if err != nil {
return err
}
containerjson, err := json.MarshalIndent(&container, "", " ")
if err != nil {
return err
}
fmt.Print(string(containerjson) + "\n")
return nil
}
// inspectExample shows examples in inspect command, and is used in auto-generated cli docs.
func inspectExample() string {
return `$ pouch inspect 08e
{
"Id": "08ee444faa3c6634ecdecea26de46e8a6a16efefd9afb72eb3457320b333fc60",
"Created": "2017-12-04 14:48:59",
"Path": "",
"Args": null,
"State": {
"StartedAt": "0001-01-01T00:00:00Z",
"Status": 0,
"FinishedAt": "0001-01-01T00:00:00Z",
"Pid": 25006,
"ExitCode": 0,
"Error": ""
},
"Image": "registry.docker-cn.com/library/centos:latest",
"ResolvConfPath": "",
"HostnamePath": "",
"HostsPath": "",
"LogPath": "",
"Name": "08ee44",
"RestartCount": 0,
"Driver": "",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": null,
"HostRootPath": ""
}`
}