summaryrefslogtreecommitdiff
path: root/cmd/podman/networks
diff options
context:
space:
mode:
authorAshley Cui <acui@redhat.com>2020-10-15 09:23:26 -0400
committerAshley Cui <acui@redhat.com>2020-10-27 14:42:54 -0400
commit61deec451f279cdc09b4415fe4988c2f8548e55a (patch)
tree091ff5d3f319d57cf788889a31d38d18e8e42cea /cmd/podman/networks
parent5c0849534d7bed20ec588d8ec0099a8b60df7e25 (diff)
downloadpodman-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/networks')
-rw-r--r--cmd/podman/networks/inspect.go44
1 files changed, 6 insertions, 38 deletions
diff --git a/cmd/podman/networks/inspect.go b/cmd/podman/networks/inspect.go
index 47503fd4b..25ee7e574 100644
--- a/cmd/podman/networks/inspect.go
+++ b/cmd/podman/networks/inspect.go
@@ -1,13 +1,7 @@
package network
import (
- "encoding/json"
- "fmt"
- "os"
- "text/tabwriter"
- "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/spf13/cobra"
@@ -23,10 +17,7 @@ var (
Example: `podman network inspect podman`,
Args: cobra.MinimumNArgs(1),
}
-)
-
-var (
- networkInspectOptions entities.NetworkInspectOptions
+ inspectOpts *entities.InspectOptions
)
func init() {
@@ -35,36 +26,13 @@ func init() {
Command: networkinspectCommand,
Parent: networkCmd,
})
+ inspectOpts = new(entities.InspectOptions)
flags := networkinspectCommand.Flags()
- flags.StringVarP(&networkInspectOptions.Format, "format", "f", "", "Pretty-print network to JSON or using a Go template")
+ flags.StringVarP(&inspectOpts.Format, "format", "f", "", "Pretty-print network to JSON or using a Go template")
}
func networkInspect(_ *cobra.Command, args []string) error {
- responses, err := registry.ContainerEngine().NetworkInspect(registry.Context(), args, entities.NetworkInspectOptions{})
- if err != nil {
- return err
- }
-
- switch {
- case report.IsJSON(networkInspectOptions.Format) || networkInspectOptions.Format == "":
- b, err := json.MarshalIndent(responses, "", " ")
- if err != nil {
- return err
- }
- fmt.Println(string(b))
- default:
- row := report.NormalizeFormat(networkInspectOptions.Format)
- // There can be more than 1 in the inspect output.
- row = "{{range . }}" + row + "{{end}}"
- tmpl, err := template.New("inspectNetworks").Parse(row)
- if err != nil {
- return err
- }
+ inspectOpts.Type = inspect.NetworkType
+ return inspect.Inspect(args, *inspectOpts)
- w := tabwriter.NewWriter(os.Stdout, 8, 2, 0, ' ', 0)
- defer w.Flush()
-
- return tmpl.Execute(w, responses)
- }
- return nil
}