summaryrefslogtreecommitdiff
path: root/pkg/network/network.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-03-15 14:25:30 -0400
committerGitHub <noreply@github.com>2021-03-15 14:25:30 -0400
commite7dc59252bd722377938ac3e6b4fd7e077f05293 (patch)
tree6a51b88aa97db1ff7dfa0313876b28844764aab1 /pkg/network/network.go
parentfc02d16e728dfdd5a5f2e3bc622bbceb7f8c0d24 (diff)
parent8de56070393ad449dc54ae622d9b82f28a6a5c52 (diff)
downloadpodman-e7dc59252bd722377938ac3e6b4fd7e077f05293.tar.gz
podman-e7dc59252bd722377938ac3e6b4fd7e077f05293.tar.bz2
podman-e7dc59252bd722377938ac3e6b4fd7e077f05293.zip
Merge pull request #9716 from Luap99/remote-libpod
Do not leak libpod package into the remote client
Diffstat (limited to 'pkg/network/network.go')
-rw-r--r--pkg/network/network.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/pkg/network/network.go b/pkg/network/network.go
new file mode 100644
index 000000000..44132ca28
--- /dev/null
+++ b/pkg/network/network.go
@@ -0,0 +1,27 @@
+package network
+
+import (
+ "crypto/sha256"
+ "encoding/hex"
+ "strings"
+
+ "github.com/containernetworking/cni/libcni"
+)
+
+// GetCNIPlugins returns a list of plugins that a given network
+// has in the form of a string
+func GetCNIPlugins(list *libcni.NetworkConfigList) string {
+ plugins := make([]string, 0, len(list.Plugins))
+ for _, plug := range list.Plugins {
+ plugins = append(plugins, plug.Network.Type)
+ }
+ return strings.Join(plugins, ",")
+}
+
+// GetNetworkID return the network ID for a given name.
+// It is just the sha256 hash but this should be good enough.
+// The caller has to make sure it is only called with the network name.
+func GetNetworkID(name string) string {
+ hash := sha256.Sum256([]byte(name))
+ return hex.EncodeToString(hash[:])
+}