From 762148deb6be6925d17bd12f219f7385e1402439 Mon Sep 17 00:00:00 2001
From: Paul Holzinger <paul.holzinger@web.de>
Date: Mon, 15 Mar 2021 10:45:24 +0100
Subject: Split libpod/network package

The `libpod/network` package should only be used on the backend and not the
client. The client used this package only for two functions so move them
into a new `pkg/network` package.

This is needed so we can put linux only code into `libpod/network`, see #9710.

[NO TESTS NEEDED]

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
---
 pkg/network/network.go | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 pkg/network/network.go

(limited to 'pkg/network')

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[:])
+}
-- 
cgit v1.2.3-54-g00ecf