summaryrefslogtreecommitdiff
path: root/pkg/network/devices.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-09-09 19:44:57 +0200
committerGitHub <noreply@github.com>2019-09-09 19:44:57 +0200
commit7042a3d7a539bae79ed63bdc87f432b8ec73afd8 (patch)
tree6f229373f5e436663c8908d0f2409fdbac2f6a2a /pkg/network/devices.go
parent511b0717454e0619d9d7d201cb10a41201cebef2 (diff)
parentee432cf2792c5dbe81953007f1fd5c87beb3ebd5 (diff)
downloadpodman-7042a3d7a539bae79ed63bdc87f432b8ec73afd8.tar.gz
podman-7042a3d7a539bae79ed63bdc87f432b8ec73afd8.tar.bz2
podman-7042a3d7a539bae79ed63bdc87f432b8ec73afd8.zip
Merge pull request #3862 from baude/networkcreate
podman network create
Diffstat (limited to 'pkg/network/devices.go')
-rw-r--r--pkg/network/devices.go41
1 files changed, 41 insertions, 0 deletions
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
+}