summaryrefslogtreecommitdiff
path: root/libpod/network/files.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-12-02 15:27:14 +0100
committerGitHub <noreply@github.com>2020-12-02 15:27:14 +0100
commit7210b86d9ee5aa38a07829e58038049d224cad61 (patch)
tree3c040ea73c85ff2797c1950d41adec3d37c78c7a /libpod/network/files.go
parentd28874b2f4bc4f522ed2dc63412e9ddfea011fac (diff)
parentc31a5c0d9c9db52f03caa443a3fdfdce194046e8 (diff)
downloadpodman-7210b86d9ee5aa38a07829e58038049d224cad61.tar.gz
podman-7210b86d9ee5aa38a07829e58038049d224cad61.tar.bz2
podman-7210b86d9ee5aa38a07829e58038049d224cad61.zip
Merge pull request #8549 from Luap99/network-id-support
Add support for network ids
Diffstat (limited to 'libpod/network/files.go')
-rw-r--r--libpod/network/files.go18
1 files changed, 15 insertions, 3 deletions
diff --git a/libpod/network/files.go b/libpod/network/files.go
index 83cb1c23a..33cf01064 100644
--- a/libpod/network/files.go
+++ b/libpod/network/files.go
@@ -50,13 +50,15 @@ func LoadCNIConfsFromDir(dir string) ([]*libcni.NetworkConfigList, error) {
return configs, nil
}
-// GetCNIConfigPathByName finds a CNI network by name and
+// GetCNIConfigPathByNameOrID finds a CNI network by name and
// returns its configuration file path
-func GetCNIConfigPathByName(config *config.Config, name string) (string, error) {
+func GetCNIConfigPathByNameOrID(config *config.Config, name string) (string, error) {
files, err := libcni.ConfFiles(GetCNIConfDir(config), []string{".conflist"})
if err != nil {
return "", err
}
+ idMatch := 0
+ file := ""
for _, confFile := range files {
conf, err := libcni.ConfListFromFile(confFile)
if err != nil {
@@ -65,6 +67,16 @@ func GetCNIConfigPathByName(config *config.Config, name string) (string, error)
if conf.Name == name {
return confFile, nil
}
+ if strings.HasPrefix(GetNetworkID(conf.Name), name) {
+ idMatch++
+ file = confFile
+ }
+ }
+ if idMatch == 1 {
+ return file, nil
+ }
+ if idMatch > 1 {
+ return "", errors.Errorf("more than one result for network ID %s", name)
}
return "", errors.Wrap(define.ErrNoSuchNetwork, fmt.Sprintf("unable to find network configuration for %s", name))
}
@@ -72,7 +84,7 @@ func GetCNIConfigPathByName(config *config.Config, name string) (string, error)
// ReadRawCNIConfByName reads the raw CNI configuration for a CNI
// network by name
func ReadRawCNIConfByName(config *config.Config, name string) ([]byte, error) {
- confFile, err := GetCNIConfigPathByName(config, name)
+ confFile, err := GetCNIConfigPathByNameOrID(config, name)
if err != nil {
return nil, err
}