diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-11-12 19:40:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-12 19:40:31 +0100 |
commit | 2aa6a8577d088271251604b028100f00a442f5cd (patch) | |
tree | ba5f781412045c7bbd7a3313e306b36c4b92b208 /libpod/container.go | |
parent | 7774f63319be64a0a96fb7ec7c9f0b7c28faac03 (diff) | |
parent | 8d56eb5342ad8afa35750f7f14791c44e37a8c30 (diff) | |
download | podman-2aa6a8577d088271251604b028100f00a442f5cd.tar.gz podman-2aa6a8577d088271251604b028100f00a442f5cd.tar.bz2 podman-2aa6a8577d088271251604b028100f00a442f5cd.zip |
Merge pull request #8298 from mheon/db_network_connect
Add support for network connect / disconnect to DB
Diffstat (limited to 'libpod/container.go')
-rw-r--r-- | libpod/container.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/libpod/container.go b/libpod/container.go index ea5a6e09c..580fa7b3d 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -1085,3 +1085,31 @@ func (c *Container) Timezone() string { func (c *Container) Umask() string { return c.config.Umask } + +// Networks gets all the networks this container is connected to. +// Please do NOT use ctr.config.Networks, as this can be changed from those +// values at runtime via network connect and disconnect. +// If the container is configured to use CNI and this function returns an empty +// array, the container will still be connected to the default network. +func (c *Container) Networks() ([]string, error) { + if !c.batched { + c.lock.Lock() + defer c.lock.Unlock() + + if err := c.syncContainer(); err != nil { + return nil, err + } + } + + return c.networks() +} + +// Unlocked accessor for networks +func (c *Container) networks() ([]string, error) { + networks, err := c.runtime.state.GetNetworks(c) + if err != nil && errors.Cause(err) == define.ErrNoSuchNetwork { + return c.config.Networks, nil + } + + return networks, err +} |