diff options
author | Jakub Filak <jakub.filak@sap.com> | 2019-09-18 00:26:48 +0200 |
---|---|---|
committer | Giuseppe Scrivano <gscrivan@redhat.com> | 2019-11-06 16:22:19 +0100 |
commit | 2497b6c77b41c70ecb4711de94de8b3a59b4c1b3 (patch) | |
tree | d0490dee84a606e35e22c63b3138367b33d30de0 /libpod/options.go | |
parent | 455f5b76169515dcc36cf4d7c1d51ead3be02e1f (diff) | |
download | podman-2497b6c77b41c70ecb4711de94de8b3a59b4c1b3.tar.gz podman-2497b6c77b41c70ecb4711de94de8b3a59b4c1b3.tar.bz2 podman-2497b6c77b41c70ecb4711de94de8b3a59b4c1b3.zip |
podman: add support for specifying MAC
I basically copied and adapted the statements for setting IP.
Closes #1136
Signed-off-by: Jakub Filak <jakub.filak@sap.com>
Diffstat (limited to 'libpod/options.go')
-rw-r--r-- | libpod/options.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/libpod/options.go b/libpod/options.go index 66e8ef93c..00b5626b4 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -1052,6 +1052,31 @@ func WithStaticIP(ip net.IP) CtrCreateOption { } } +// WithStaticMAC indicates that the container should request a static MAC from +// the CNI plugins. +// It cannot be set unless WithNetNS has already been passed. +// Further, it cannot be set if additional CNI networks to join have been +// specified. +func WithStaticMAC(mac net.HardwareAddr) CtrCreateOption { + return func(ctr *Container) error { + if ctr.valid { + return define.ErrCtrFinalized + } + + if !ctr.config.CreateNetNS { + return errors.Wrapf(define.ErrInvalidArg, "cannot set a static MAC if the container is not creating a network namespace") + } + + if len(ctr.config.Networks) != 0 { + return errors.Wrapf(define.ErrInvalidArg, "cannot set a static MAC if joining additional CNI networks") + } + + ctr.config.StaticMAC = mac + + return nil + } +} + // WithLogDriver sets the log driver for the container func WithLogDriver(driver string) CtrCreateOption { return func(ctr *Container) error { |