diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2018-10-11 10:40:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-11 10:40:37 -0700 |
commit | 6983e00a2808b29481d1cb460aab2eea1db6ef73 (patch) | |
tree | 2ee6bc368cc698e13d5dd5249061ecd2e2f93f6e /libpod/options.go | |
parent | 3c23bfca807eab55c145092c73dd8eb1e6599f38 (diff) | |
parent | 112e1402c9e2ee29a387cd84a973471c1888e4b9 (diff) | |
download | podman-6983e00a2808b29481d1cb460aab2eea1db6ef73.tar.gz podman-6983e00a2808b29481d1cb460aab2eea1db6ef73.tar.bz2 podman-6983e00a2808b29481d1cb460aab2eea1db6ef73.zip |
Merge pull request #1623 from mheon/static_ip
Add ability to specify static IPs with --ip flag
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 977f3f4c2..9f966cead 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -828,6 +828,31 @@ func WithNetNS(portMappings []ocicni.PortMapping, postConfigureNetNS bool, netwo } } +// WithStaticIP indicates that the container should request a static IP 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 WithStaticIP(ip net.IP) CtrCreateOption { + return func(ctr *Container) error { + if ctr.valid { + return ErrCtrFinalized + } + + if !ctr.config.CreateNetNS { + return errors.Wrapf(ErrInvalidArg, "cannot set a static IP if the container is not creating a network namespace") + } + + if len(ctr.config.Networks) != 0 { + return errors.Wrapf(ErrInvalidArg, "cannot set a static IP if joining additional CNI networks") + } + + ctr.config.StaticIP = ip + + return nil + } +} + // WithLogPath sets the path to the log file. func WithLogPath(path string) CtrCreateOption { return func(ctr *Container) error { |