-
Notifications
You must be signed in to change notification settings - Fork 947
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add inspect command to get pid of container (#213)
feature: add inspect command to get pid of container
- Loading branch information
1 parent
c8cb371
commit 432a53d
Showing
7 changed files
with
164 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package types | ||
|
||
// ContainerJSON contains response of Remote API: | ||
// GET "/containers/{name:.*}/json" | ||
type ContainerJSON struct { | ||
ID string `json:"Id"` | ||
Created string | ||
Path string | ||
Args []string | ||
State *ContainerState | ||
Image string | ||
ResolvConfPath string | ||
HostnamePath string | ||
HostsPath string | ||
LogPath string | ||
Name string | ||
RestartCount int | ||
Driver string | ||
MountLabel string | ||
ProcessLabel string | ||
AppArmorProfile string | ||
ExecIDs []string | ||
HostConfig *HostConfig | ||
SizeRw *int64 `json:",omitempty"` | ||
SizeRootFs *int64 `json:",omitempty"` | ||
HostRootPath string | ||
} | ||
|
||
// TODO | ||
// ContainerJSON is newly used struct along with MountPoint | ||
//type ContainerJSON struct { | ||
// *ContainerJSONBase | ||
// Mounts []MountPoint | ||
// Config *container.Config | ||
// NetworkSettings *NetworkSettings | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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": "" | ||
}` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters