diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-12-09 07:53:55 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-09 07:53:55 -0800 |
commit | c2dab75f0ec1502e075cf5174d1b308267648fda (patch) | |
tree | 4c000064fd0f3a660446ce6cdf2bd1bc97992bf5 /pkg/adapter/network.go | |
parent | 7287f69b52e5bcb59f9977b261ee488942465ecb (diff) | |
parent | ef872dcd21c60af70ab1848a7e0c873f142f6f44 (diff) | |
download | podman-c2dab75f0ec1502e075cf5174d1b308267648fda.tar.gz podman-c2dab75f0ec1502e075cf5174d1b308267648fda.tar.bz2 podman-c2dab75f0ec1502e075cf5174d1b308267648fda.zip |
Merge pull request #4517 from baude/macvlan
macvlan networks
Diffstat (limited to 'pkg/adapter/network.go')
-rw-r--r-- | pkg/adapter/network.go | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/pkg/adapter/network.go b/pkg/adapter/network.go index 9659ae339..160e334e9 100644 --- a/pkg/adapter/network.go +++ b/pkg/adapter/network.go @@ -153,8 +153,8 @@ func (r *LocalRuntime) removeNetwork(ctx context.Context, name string, container return nil } -// NetworkCreate creates a CNI network -func (r *LocalRuntime) NetworkCreate(cli *cliconfig.NetworkCreateValues) (string, error) { +// NetworkCreateBridge creates a CNI network +func (r *LocalRuntime) NetworkCreateBridge(cli *cliconfig.NetworkCreateValues) (string, error) { isGateway := true ipMasq := true subnet := &cli.Network @@ -262,3 +262,50 @@ func (r *LocalRuntime) NetworkCreate(cli *cliconfig.NetworkCreateValues) (string err = ioutil.WriteFile(cniPathName, b, 0644) return cniPathName, err } + +// NetworkCreateMacVLAN creates a CNI network +func (r *LocalRuntime) NetworkCreateMacVLAN(cli *cliconfig.NetworkCreateValues) (string, error) { + var ( + name string + plugins []network.CNIPlugins + ) + liveNetNames, err := network.GetLiveNetworkNames() + if err != nil { + return "", err + } + // Make sure the host-device exists + if !util.StringInSlice(cli.MacVLAN, liveNetNames) { + return "", errors.Errorf("failed to find network interface %q", cli.MacVLAN) + } + if len(cli.InputArgs) > 0 { + name = cli.InputArgs[0] + netNames, err := network.GetNetworkNamesFromFileSystem() + if err != nil { + return "", err + } + if util.StringInSlice(name, netNames) { + return "", errors.Errorf("the network name %s is already used", name) + } + } + if len(name) < 1 { + name, err = network.GetFreeDeviceName() + if err != nil { + return "", err + } + } + ncList := network.NewNcList(name, cniversion.Current()) + macvlan := network.NewMacVLANPlugin(cli.MacVLAN) + plugins = append(plugins, macvlan) + ncList["plugins"] = plugins + b, err := json.MarshalIndent(ncList, "", " ") + if err != nil { + return "", err + } + cniConfigPath, err := getCNIConfDir(r) + if err != nil { + return "", err + } + cniPathName := filepath.Join(cniConfigPath, fmt.Sprintf("%s.conflist", name)) + err = ioutil.WriteFile(cniPathName, b, 0644) + return cniPathName, err +} |