From ee432cf2792c5dbe81953007f1fd5c87beb3ebd5 Mon Sep 17 00:00:00 2001 From: baude Date: Thu, 8 Aug 2019 06:01:00 -0500 Subject: podman network create initial implementation of network create. we only support bridging networks with this first pass. Signed-off-by: baude --- pkg/network/devices.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 pkg/network/devices.go (limited to 'pkg/network/devices.go') diff --git a/pkg/network/devices.go b/pkg/network/devices.go new file mode 100644 index 000000000..26101b6f7 --- /dev/null +++ b/pkg/network/devices.go @@ -0,0 +1,41 @@ +package network + +import ( + "fmt" + "github.com/containers/libpod/pkg/util" + + "github.com/sirupsen/logrus" +) + +// GetFreeDeviceName returns a device name that is unused; used when no network +// name is provided by user +func GetFreeDeviceName() (string, error) { + var ( + deviceNum uint + deviceName string + ) + networkNames, err := GetNetworkNamesFromFileSystem() + if err != nil { + return "", err + } + liveNetworksNames, err := GetLiveNetworkNames() + if err != nil { + return "", err + } + for { + deviceName = fmt.Sprintf("%s%d", CNIDeviceName, deviceNum) + logrus.Debugf("checking if device name %s exists in other cni networks", deviceName) + if util.StringInSlice(deviceName, networkNames) { + deviceNum++ + continue + } + logrus.Debugf("checking if device name %s exists in live networks", deviceName) + if !util.StringInSlice(deviceName, liveNetworksNames) { + break + } + // TODO Still need to check the bridge names for a conflict but I dont know + // how to get them yet! + deviceNum++ + } + return deviceName, nil +} -- cgit v1.2.3-54-g00ecf