aboutsummaryrefslogtreecommitdiff
path: root/pkg/network/network.go
blob: 44132ca286f2d5deb826110a83fc3fd4b568e2a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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[:])
}