summaryrefslogtreecommitdiff
path: root/cmd/podman/networks/list.go
diff options
context:
space:
mode:
authorPaul Holzinger <paul.holzinger@web.de>2020-12-01 22:12:16 +0100
committerPaul Holzinger <paul.holzinger@web.de>2020-12-02 10:27:00 +0100
commitc31a5c0d9c9db52f03caa443a3fdfdce194046e8 (patch)
treefe21af9d8e5b87e6fa4054bb8d30ce17ab673662 /cmd/podman/networks/list.go
parent9c5fe954cca8b4bcb8f552645e1f52a5d9824134 (diff)
downloadpodman-c31a5c0d9c9db52f03caa443a3fdfdce194046e8.tar.gz
podman-c31a5c0d9c9db52f03caa443a3fdfdce194046e8.tar.bz2
podman-c31a5c0d9c9db52f03caa443a3fdfdce194046e8.zip
Add support for network ids
The network ID is not stored. It is just the sha256 hash from the network name. There is a risk of a potential hash collision. However it's very unlikely and even if we hit this it will complain that more than network with this ID exists. The main benefit is that the compat api can have proper network ID support. Also this adds the support for `podman network ls --format "{{.ID}}"` and `--filter id=<ID>`. It also ensures that we can do network rm <ID> and network inspect <ID>. Since we use a hash this commit is backwards compatible even for already existing networks. Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
Diffstat (limited to 'cmd/podman/networks/list.go')
-rw-r--r--cmd/podman/networks/list.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/cmd/podman/networks/list.go b/cmd/podman/networks/list.go
index 6e6bbb07d..16ae980dc 100644
--- a/cmd/podman/networks/list.go
+++ b/cmd/podman/networks/list.go
@@ -37,6 +37,7 @@ var (
var (
networkListOptions entities.NetworkListOptions
filters []string
+ noTrunc bool
)
func networkListFlags(flags *pflag.FlagSet) {
@@ -45,6 +46,7 @@ func networkListFlags(flags *pflag.FlagSet) {
_ = networklistCommand.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteJSONFormat)
flags.BoolVarP(&networkListOptions.Quiet, "quiet", "q", false, "display only names")
+ flags.BoolVar(&noTrunc, "no-trunc", false, "Do not truncate the network ID")
filterFlagName := "filter"
flags.StringArrayVarP(&filters, filterFlagName, "f", nil, "Provide filter values (e.g. 'name=podman')")
@@ -96,6 +98,7 @@ func networkList(cmd *cobra.Command, args []string) error {
"Version": "version",
"Plugins": "plugins",
"Labels": "labels",
+ "ID": "network id",
})
renderHeaders := true
row := "{{.Name}}\t{{.Version}}\t{{.Plugins}}\n"
@@ -155,3 +158,11 @@ func (n ListPrintReports) Labels() string {
}
return strings.Join(list, ",")
}
+
+func (n ListPrintReports) ID() string {
+ length := 12
+ if noTrunc {
+ length = 64
+ }
+ return network.GetNetworkID(n.Name)[:length]
+}