blob: 26101b6f7629eaea7bdf165dbfc4e18257b380ed (
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
28
29
30
31
32
33
34
35
36
37
38
39
40
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
}
|