diff options
author | Ashley Cui <acui@redhat.com> | 2020-10-15 09:23:26 -0400 |
---|---|---|
committer | Ashley Cui <acui@redhat.com> | 2020-10-27 14:42:54 -0400 |
commit | 61deec451f279cdc09b4415fe4988c2f8548e55a (patch) | |
tree | 091ff5d3f319d57cf788889a31d38d18e8e42cea /cmd/podman/volumes | |
parent | 5c0849534d7bed20ec588d8ec0099a8b60df7e25 (diff) | |
download | podman-61deec451f279cdc09b4415fe4988c2f8548e55a.tar.gz podman-61deec451f279cdc09b4415fe4988c2f8548e55a.tar.bz2 podman-61deec451f279cdc09b4415fe4988c2f8548e55a.zip |
Add pod, volume, network to inspect package
podman inspect only had the capabilities to inspect containers and images. if a user wanted to inspect a pod, volume, or network, they would have to use `podman network inspect`, `podman pod inspect` etc. Docker's cli allowed users to inspect both volumes and networks using regular inspect, so this commit gives the user the functionality
If the inspect type is not specified using --type, the order of inspection is:
containers
images
volumes
networks
pods
meaning if container that has the same name as an image, podman inspect would return the container inspect.
To avoid duplicate code, podman network inspect and podman volume inspect now use the inspect package as well. Podman pod inspect does not because podman pod inspect returns a single json object while podman inspect can return multiple)
Signed-off-by: Ashley Cui <acui@redhat.com>
Diffstat (limited to 'cmd/podman/volumes')
-rw-r--r-- | cmd/podman/volumes/inspect.go | 40 |
1 files changed, 8 insertions, 32 deletions
diff --git a/cmd/podman/volumes/inspect.go b/cmd/podman/volumes/inspect.go index 732a67333..c6edcf809 100644 --- a/cmd/podman/volumes/inspect.go +++ b/cmd/podman/volumes/inspect.go @@ -1,16 +1,11 @@ package volumes import ( - "fmt" - "os" - "text/template" - - "github.com/containers/common/pkg/report" + "github.com/containers/podman/v2/cmd/podman/inspect" "github.com/containers/podman/v2/cmd/podman/registry" "github.com/containers/podman/v2/pkg/domain/entities" "github.com/pkg/errors" "github.com/spf13/cobra" - "golang.org/x/net/context" ) var ( @@ -21,7 +16,7 @@ var ( Use: "inspect [options] VOLUME [VOLUME...]", Short: "Display detailed information on one or more volumes", Long: volumeInspectDescription, - RunE: inspect, + RunE: volumeInspect, Example: `podman volume inspect myvol podman volume inspect --all podman volume inspect --format "{{.Driver}} {{.Scope}}" myvol`, @@ -29,8 +24,7 @@ var ( ) var ( - inspectOpts = entities.VolumeInspectOptions{} - inspectFormat string + inspectOpts *entities.InspectOptions ) func init() { @@ -39,34 +33,16 @@ func init() { Command: inspectCommand, Parent: volumeCmd, }) + inspectOpts = new(entities.InspectOptions) flags := inspectCommand.Flags() flags.BoolVarP(&inspectOpts.All, "all", "a", false, "Inspect all volumes") - flags.StringVarP(&inspectFormat, "format", "f", "json", "Format volume output using Go template") + flags.StringVarP(&inspectOpts.Format, "format", "f", "json", "Format volume output using Go template") } -func inspect(cmd *cobra.Command, args []string) error { +func volumeInspect(cmd *cobra.Command, args []string) error { if (inspectOpts.All && len(args) > 0) || (!inspectOpts.All && len(args) < 1) { return errors.New("provide one or more volume names or use --all") } - responses, err := registry.ContainerEngine().VolumeInspect(context.Background(), args, inspectOpts) - if err != nil { - return err - } - - switch { - case report.IsJSON(inspectFormat), inspectFormat == "": - jsonOut, err := json.MarshalIndent(responses, "", " ") - if err != nil { - return errors.Wrapf(err, "error marshalling inspect JSON") - } - fmt.Println(string(jsonOut)) - default: - row := "{{range . }}" + report.NormalizeFormat(inspectFormat) + "{{end}}" - tmpl, err := template.New("volumeInspect").Parse(row) - if err != nil { - return err - } - return tmpl.Execute(os.Stdout, responses) - } - return nil + inspectOpts.Type = inspect.VolumeType + return inspect.Inspect(args, *inspectOpts) } |