diff options
author | baude <bbaude@redhat.com> | 2019-10-17 13:28:38 -0500 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2019-10-17 13:28:38 -0500 |
commit | 7343de24e5961c33158f4002964e6b0178d8b740 (patch) | |
tree | 8772a20ea6f97769ca67a8c2c9ff5e60da22f3d9 /pkg/network/files.go | |
parent | f2d9a9d2abd1405d8ea5fb7b94715f6f87618226 (diff) | |
download | podman-7343de24e5961c33158f4002964e6b0178d8b740.tar.gz podman-7343de24e5961c33158f4002964e6b0178d8b740.tar.bz2 podman-7343de24e5961c33158f4002964e6b0178d8b740.zip |
check existing bridge names when creating networks
when creating a new networking, we should check existing networks for
their bridge names and make sure the proposed new name is not part of
this. reported by QE.
Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/network/files.go')
-rw-r--r-- | pkg/network/files.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/pkg/network/files.go b/pkg/network/files.go index d55ec2dfd..2f3932974 100644 --- a/pkg/network/files.go +++ b/pkg/network/files.go @@ -129,3 +129,29 @@ func GetInterfaceNameFromConfig(path string) (string, error) { } return name, nil } + +// GetBridgeNamesFromFileSystem is a convenience function to get all the bridge +// names from the configured networks +func GetBridgeNamesFromFileSystem() ([]string, error) { + var bridgeNames []string + networks, err := LoadCNIConfsFromDir(CNIConfigDir) + if err != nil { + return nil, err + } + for _, n := range networks { + var name string + // iterate network conflists + for _, cniplugin := range n.Plugins { + // iterate plugins + if cniplugin.Network.Type == "bridge" { + plugin := make(map[string]interface{}) + if err := json.Unmarshal(cniplugin.Bytes, &plugin); err != nil { + continue + } + name = plugin["bridge"].(string) + } + } + bridgeNames = append(bridgeNames, name) + } + return bridgeNames, nil +} |