summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--cmd/podman/networks/exists.go40
-rwxr-xr-xcontrib/cirrus/runner.sh3
-rw-r--r--docs/source/markdown/podman-build.1.md8
-rw-r--r--docs/source/markdown/podman-create.1.md36
-rw-r--r--docs/source/markdown/podman-image-tree.1.md2
-rw-r--r--docs/source/markdown/podman-images.1.md4
-rw-r--r--docs/source/markdown/podman-network-exists.1.md44
-rw-r--r--docs/source/markdown/podman-network.1.md1
-rw-r--r--docs/source/markdown/podman-run.1.md10
-rw-r--r--docs/source/markdown/podman-system-service.1.md4
-rw-r--r--docs/source/network.rst2
-rw-r--r--pkg/api/handlers/libpod/networks.go18
-rw-r--r--pkg/api/server/register_networks.go22
-rw-r--r--pkg/bindings/network/network.go13
-rw-r--r--pkg/bindings/network/types.go6
-rw-r--r--pkg/bindings/network/types_exists_options.go88
-rw-r--r--pkg/domain/entities/engine_container.go1
-rw-r--r--pkg/domain/infra/abi/network.go15
-rw-r--r--pkg/domain/infra/tunnel/network.go11
-rw-r--r--test/e2e/network_test.go16
21 files changed, 312 insertions, 34 deletions
diff --git a/Makefile b/Makefile
index 1083d0a95..5b31ecfae 100644
--- a/Makefile
+++ b/Makefile
@@ -383,7 +383,7 @@ MANPAGES ?= $(MANPAGES_MD:%.md=%)
MANPAGES_DEST ?= $(subst markdown,man, $(subst source,build,$(MANPAGES)))
$(MANPAGES): %: %.md .install.md2man docdir
- @sed -e 's/\((podman.*\.md)\)//' -e 's/\[\(podman.*\)\]/\1/' $< | $(GOMD2MAN) -in /dev/stdin -out $(subst source/markdown,build/man,$@)
+ @sed -e 's/\((podman.*\.md)\)//' -e 's/\[\(podman.*\)\]/\1/' -e 's;<\(/\)\?\(a[^>]*\|sup\)>;;g' $< | $(GOMD2MAN) -in /dev/stdin -out $(subst source/markdown,build/man,$@)
.PHONY: docs
docdir:
diff --git a/cmd/podman/networks/exists.go b/cmd/podman/networks/exists.go
new file mode 100644
index 000000000..2eb485b36
--- /dev/null
+++ b/cmd/podman/networks/exists.go
@@ -0,0 +1,40 @@
+package network
+
+import (
+ "github.com/containers/podman/v2/cmd/podman/common"
+ "github.com/containers/podman/v2/cmd/podman/registry"
+ "github.com/containers/podman/v2/pkg/domain/entities"
+ "github.com/spf13/cobra"
+)
+
+var (
+ networkExistsDescription = `If the named network exists, podman network exists exits with 0, otherwise the exit code will be 1.`
+ networkExistsCommand = &cobra.Command{
+ Use: "exists NETWORK",
+ Short: "network exists",
+ Long: networkExistsDescription,
+ RunE: networkExists,
+ Example: `podman network exists net1`,
+ Args: cobra.ExactArgs(1),
+ ValidArgsFunction: common.AutocompleteNetworks,
+ }
+)
+
+func init() {
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
+ Command: networkExistsCommand,
+ Parent: networkCmd,
+ })
+}
+
+func networkExists(cmd *cobra.Command, args []string) error {
+ response, err := registry.ContainerEngine().NetworkExists(registry.GetContext(), args[0])
+ if err != nil {
+ return err
+ }
+ if !response.Value {
+ registry.SetExitCode(1)
+ }
+ return nil
+}
diff --git a/contrib/cirrus/runner.sh b/contrib/cirrus/runner.sh
index e08bb5f19..e968fac45 100755
--- a/contrib/cirrus/runner.sh
+++ b/contrib/cirrus/runner.sh
@@ -214,7 +214,8 @@ function _run_release() {
bin/podman info
msg "Checking podman release (or potential release) criteria."
- dev=$(bin/podman info |& grep -- -dev)
+ # We're running under 'set -eo pipefail'; make sure this statement passes
+ dev=$(bin/podman info |& grep -- -dev || echo -n '')
if [[ -n "$dev" ]]; then
die "Releases must never contain '-dev' in output of 'podman info' ($dev)"
fi
diff --git a/docs/source/markdown/podman-build.1.md b/docs/source/markdown/podman-build.1.md
index 29f763d54..61c05fdef 100644
--- a/docs/source/markdown/podman-build.1.md
+++ b/docs/source/markdown/podman-build.1.md
@@ -394,7 +394,7 @@ Name of the manifest list to which the image will be added. Creates the manifest
if it does not exist. This option is useful for building multi architecture images.
#### **--memory**, **-m**=*LIMIT*
-Memory limit (format: <number>[<unit>], where unit = b (bytes), k (kilobytes),
+Memory limit (format: `<number>[<unit>]`, where unit = b (bytes), k (kilobytes),
m (megabytes), or g (gigabytes))
Allows you to constrain the memory available to a container. If the host
@@ -944,11 +944,11 @@ useradd to stop creating the lastlog file.
podman(1), buildah(1), containers-registries.conf(5), crun(8), runc(8), useradd(8), podman-ps(1), podman-rm(1)
## HISTORY
-Aug 2020, Additional options and .dockerignore added by Dan Walsh <dwalsh@redhat.com>
+Aug 2020, Additional options and .dockerignore added by Dan Walsh `<dwalsh@redhat.com>`
-May 2018, Minor revisions added by Joe Doss <joe@solidadmin.com>
+May 2018, Minor revisions added by Joe Doss `<joe@solidadmin.com>`
-December 2017, Originally compiled by Tom Sweeney <tsweeney@redhat.com>
+December 2017, Originally compiled by Tom Sweeney `<tsweeney@redhat.com>`
## FOOTNOTES
<a name="Footnote1">1</a>: The Podman project is committed to inclusivity, a
diff --git a/docs/source/markdown/podman-create.1.md b/docs/source/markdown/podman-create.1.md
index 8deaa8540..35d8474a6 100644
--- a/docs/source/markdown/podman-create.1.md
+++ b/docs/source/markdown/podman-create.1.md
@@ -114,10 +114,10 @@ Drop Linux capabilities
#### **--cgroupns**=*mode*
Set the cgroup namespace mode for the container.
- **host**: use the host's cgroup namespace inside the container.
- **container:<NAME|ID>**: join the namespace of the specified container.
- **ns:<PATH>**: join the namespace at the specified path.
- **private**: create a new cgroup namespace.
+ **`host`**: use the host's cgroup namespace inside the container.
+ **`container:<NAME|ID>`**: join the namespace of the specified container.
+ **`ns:<PATH>`**: join the namespace at the specified path.
+ **`private`**: create a new cgroup namespace.
If the host uses cgroups v1, the default is set to **host**. On cgroups v2 the default is **private**.
@@ -295,7 +295,7 @@ solely for scripting compatibility.
#### **--dns**=*dns*
-Set custom DNS servers. Invalid if using **--dns** and **--network** that is set to 'none' or 'container:<name|id>'.
+Set custom DNS servers. Invalid if using **--dns** and **--network** that is set to 'none' or `container:<name|id>`.
This option can be used to override the DNS
configuration passed to the container. Typically this is necessary when the
@@ -307,11 +307,11 @@ The **/etc/resolv.conf** file in the image will be used without changes.
#### **--dns-opt**=*option*
-Set custom DNS options. Invalid if using **--dns-opt** and **--network** that is set to 'none' or 'container:<name|id>'.
+Set custom DNS options. Invalid if using **--dns-opt** and **--network** that is set to 'none' or `container:<name|id>`.
#### **--dns-search**=*domain*
-Set custom DNS search domains. Invalid if using **--dns-search** and **--network** that is set to 'none' or 'container:<name|id>'. (Use --dns-search=. if you don't wish to set the search domain)
+Set custom DNS search domains. Invalid if using **--dns-search** and **--network** that is set to 'none' or `container:<name|id>`. (Use --dns-search=. if you don't wish to set the search domain)
#### **--entrypoint**=*"command"* | *'["command", "arg1", ...]'*
@@ -453,9 +453,9 @@ The address must be within the CNI network's IP address pool (default **10.88.0.
#### **--ipc**=*ipc*
Default is to create a private IPC namespace (POSIX SysV IPC) for the container
- 'container:<name|id>': reuses another container shared memory, semaphores and message queues
- 'host': use the host shared memory,semaphores and message queues inside the container. Note: the host mode gives the container full access to local shared memory and is therefore considered insecure.
- 'ns:<path>' path to an IPC namespace to join.
+ `container:<name|id>`: reuses another container shared memory, semaphores and message queues
+ `host`: use the host shared memory,semaphores and message queues inside the container. Note: the host mode gives the container full access to local shared memory and is therefore considered insecure.
+ `ns:<path>` path to an IPC namespace to join.
#### **--kernel-memory**=*number[unit]*
@@ -516,7 +516,7 @@ according to RFC4862.
#### **--memory**, **-m**=*limit*
-Memory limit (format: <number>[<unit>], where unit = b (bytes), k (kilobytes), m (megabytes), or g (gigabytes))
+Memory limit (format: `<number>[<unit>]`, where unit = b (bytes), k (kilobytes), m (megabytes), or g (gigabytes))
Allows you to constrain the memory available to a container. If the host
supports swap memory, then the **-m** memory setting can be larger than physical
@@ -526,7 +526,7 @@ system's page size (the value would be very large, that's millions of trillions)
#### **--memory-reservation**=*limit*
-Memory soft limit (format: <number>[<unit>], where unit = b (bytes), k (kilobytes), m (megabytes), or g (gigabytes))
+Memory soft limit (format: `<number>[<unit>]`, where unit = b (bytes), k (kilobytes), m (megabytes), or g (gigabytes))
After setting memory reservation, when the system detects memory contention
or low memory, containers are forced to restrict their consumption to their
@@ -860,7 +860,7 @@ Note: Labeling can be disabled for all containers by setting label=false in the
#### **--shm-size**=*size*
-Size of `/dev/shm` (format: <number>[<unit>], where unit = b (bytes), k (kilobytes), m (megabytes), or g (gigabytes))
+Size of `/dev/shm` (format: `<number>[<unit>]`, where unit = b (bytes), k (kilobytes), m (megabytes), or g (gigabytes))
If you omit the unit, the system uses bytes. If you omit the size entirely, the system uses `64m`.
When size is `0`, there is no limit on the amount of memory used for IPC by the container.
@@ -1133,7 +1133,7 @@ Mounting the volume with the nodev option means that no devices on the volume
will be able to be used by processes within the container. By default volumes
are mounted with `nodev`.
-If the <source-dir> is a mount point, then "dev", "suid", and "exec" options are
+If the `<source-dir>` is a mount point, then "dev", "suid", and "exec" options are
ignored by the kernel.
Use `df <source-dir>` to figure out the source mount and then use
@@ -1280,13 +1280,13 @@ NOTE: Use the environment variable `TMPDIR` to change the temporary storage loca
**podman-generate-systemd**(1) **podman-rm**(1), **subgid**(5), **subuid**(5), **containers.conf**(5), **systemd.unit**(5), **setsebool**(8), **slirp4netns**(1), **fuse-overlayfs**(1), **proc**(5)**.
## HISTORY
-October 2017, converted from Docker documentation to Podman by Dan Walsh for Podman <dwalsh@redhat.com>
+October 2017, converted from Docker documentation to Podman by Dan Walsh for Podman `<dwalsh@redhat.com>`
-November 2014, updated by Sven Dowideit <SvenDowideit@home.org.au>
+November 2014, updated by Sven Dowideit `<SvenDowideit@home.org.au>`
-September 2014, updated by Sven Dowideit <SvenDowideit@home.org.au>
+September 2014, updated by Sven Dowideit `<SvenDowideit@home.org.au>`
-August 2014, updated by Sven Dowideit <SvenDowideit@home.org.au>
+August 2014, updated by Sven Dowideit `<SvenDowideit@home.org.au>`
## FOOTNOTES
<a name="Footnote1">1</a>: The Podman project is committed to inclusivity, a core value of open source. The `master` and `slave` mount propagation terminology used here is problematic and divisive, and should be changed. However, these terms are currently used within the Linux kernel and must be used as-is at this time. When the kernel maintainers rectify this usage, Podman will follow suit immediately.
diff --git a/docs/source/markdown/podman-image-tree.1.md b/docs/source/markdown/podman-image-tree.1.md
index 9a52e8444..fe36929cc 100644
--- a/docs/source/markdown/podman-image-tree.1.md
+++ b/docs/source/markdown/podman-image-tree.1.md
@@ -85,4 +85,4 @@ Image Layers
podman(1)
## HISTORY
-Feb 2019, Originally compiled by Kunal Kushwaha <kushwaha_kunal_v7@lab.ntt.co.jp>
+Feb 2019, Originally compiled by Kunal Kushwaha `<kushwaha_kunal_v7@lab.ntt.co.jp>`
diff --git a/docs/source/markdown/podman-images.1.md b/docs/source/markdown/podman-images.1.md
index 9ee62ef2b..23cce450a 100644
--- a/docs/source/markdown/podman-images.1.md
+++ b/docs/source/markdown/podman-images.1.md
@@ -36,7 +36,7 @@ Filter output based on conditions provided
Filter on images created before the given IMAGE (name or tag).
**dangling=true|false**
- Show dangling images. Dangling images are a file system layer that was used in a previous build of an image and is no longer referenced by any active images. They are denoted with the <none> tag, consume disk space and serve no active purpose.
+ Show dangling images. Dangling images are a file system layer that was used in a previous build of an image and is no longer referenced by any active images. They are denoted with the `<none>` tag, consume disk space and serve no active purpose.
**label**
Filter by images labels key and/or value.
@@ -191,4 +191,4 @@ docker.io/library/alpine latest 3fd9065eaf02 5 months ago 4.41 MB
podman(1), containers-storage.conf(5)
## HISTORY
-March 2017, Originally compiled by Dan Walsh <dwalsh@redhat.com>
+March 2017, Originally compiled by Dan Walsh `<dwalsh@redhat.com>`
diff --git a/docs/source/markdown/podman-network-exists.1.md b/docs/source/markdown/podman-network-exists.1.md
new file mode 100644
index 000000000..c7edc2ac7
--- /dev/null
+++ b/docs/source/markdown/podman-network-exists.1.md
@@ -0,0 +1,44 @@
+% podman-network-exists(1)
+
+## NAME
+podman\-network\-exists - Check if the given network exists
+
+## SYNOPSIS
+**podman network exists** *network*
+
+## DESCRIPTION
+**podman network exists** checks if a network exists. The **Name** or **ID**
+of the network may be used as input. Podman will return an exit code
+of `0` when the network is found. A `1` will be returned otherwise. An exit code of
+`125` indicates there was an other issue.
+
+
+## OPTIONS
+
+#### **--help**, **-h**
+
+Print usage statement
+
+## EXAMPLE
+
+Check if a network called `net1` exists (the network does actually exist).
+```
+$ podman network exists net1
+$ echo $?
+0
+$
+```
+
+Check if an network called `webbackend` exists (the network does not actually exist).
+```
+$ podman network exists webbackend
+$ echo $?
+1
+$
+```
+
+## SEE ALSO
+podman(1), podman-network-create(1), podman-network-rm(1)
+
+## HISTORY
+January 2021, Originally compiled by Paul Holzinger <paul.holzinger@web.de>
diff --git a/docs/source/markdown/podman-network.1.md b/docs/source/markdown/podman-network.1.md
index 41e2ae885..3ad37b8bf 100644
--- a/docs/source/markdown/podman-network.1.md
+++ b/docs/source/markdown/podman-network.1.md
@@ -16,6 +16,7 @@ The network command manages CNI networks for Podman.
| connect | [podman-network-connect(1)](podman-network-connect.1.md) | Connect a container to a network |
| create | [podman-network-create(1)](podman-network-create.1.md) | Create a Podman CNI network |
| disconnect | [podman-network-disconnect(1)](podman-network-disconnect.1.md) | Disconnect a container from a network |
+| exists | [podman-network-exists(1)](podman-network-exists.1.md) | Check if the given network exists |
| inspect | [podman-network-inspect(1)](podman-network-inspect.1.md) | Displays the raw CNI network configuration for one or more networks |
| ls | [podman-network-ls(1)](podman-network-ls.1.md) | Display a summary of CNI networks |
| reload | [podman-network-reload(1)](podman-network-reload.1.md) | Reload network configuration for containers |
diff --git a/docs/source/markdown/podman-run.1.md b/docs/source/markdown/podman-run.1.md
index 74c231184..89f05c308 100644
--- a/docs/source/markdown/podman-run.1.md
+++ b/docs/source/markdown/podman-run.1.md
@@ -1632,15 +1632,15 @@ NOTE: Use the environment variable `TMPDIR` to change the temporary storage loca
**podman-generate-systemd**(1) **podman-rm**(1), **subgid**(5), **subuid**(5), **containers.conf**(5), **systemd.unit**(5), **setsebool**(8), **slirp4netns**(1), **fuse-overlayfs**(1), **proc**(5)**.
## HISTORY
-September 2018, updated by Kunal Kushwaha <kushwaha_kunal_v7@lab.ntt.co.jp>
+September 2018, updated by Kunal Kushwaha `<kushwaha_kunal_v7@lab.ntt.co.jp>`
-October 2017, converted from Docker documentation to Podman by Dan Walsh for Podman <dwalsh@redhat.com>
+October 2017, converted from Docker documentation to Podman by Dan Walsh for Podman `<dwalsh@redhat.com>`
-November 2015, updated by Sally O'Malley <somalley@redhat.com>
+November 2015, updated by Sally O'Malley `<somalley@redhat.com>`
-June 2014, updated by Sven Dowideit <SvenDowideit@home.org.au>
+June 2014, updated by Sven Dowideit `<SvenDowideit@home.org.au>`
-April 2014, Originally compiled by William Henry <whenry@redhat.com> based on docker.com source material and internal work.
+April 2014, Originally compiled by William Henry `<whenry@redhat.com>` based on docker.com source material and internal work.
## FOOTNOTES
<a name="Footnote1">1</a>: The Podman project is committed to inclusivity, a core value of open source. The `master` and `slave` mount propagation terminology used here is problematic and divisive, and should be changed. However, these terms are currently used within the Linux kernel and must be used as-is at this time. When the kernel maintainers rectify this usage, Podman will follow suit immediately.
diff --git a/docs/source/markdown/podman-system-service.1.md b/docs/source/markdown/podman-system-service.1.md
index 0905830c5..70764823c 100644
--- a/docs/source/markdown/podman-system-service.1.md
+++ b/docs/source/markdown/podman-system-service.1.md
@@ -41,5 +41,5 @@ podman system service --timeout 5000
podman(1), podman-system-service(1), podman-system-connection(1)
## HISTORY
-January 2020, Originally compiled by Brent Baude<bbaude@redhat.com>
-November 2020, Updated by Jhon Honce <jhonce at redhat.com>
+January 2020, Originally compiled by Brent Baude `<bbaude@redhat.com>`
+November 2020, Updated by Jhon Honce (jhonce at redhat dot com)
diff --git a/docs/source/network.rst b/docs/source/network.rst
index 2ecb97858..b5829876e 100644
--- a/docs/source/network.rst
+++ b/docs/source/network.rst
@@ -7,6 +7,8 @@ Network
:doc:`disconnect <markdown/podman-network-disconnect.1>` network disconnect
+:doc:`exists <markdown/podman-network-exists.1>` network exists
+
:doc:`inspect <markdown/podman-network-inspect.1>` network inspect
:doc:`ls <markdown/podman-network-ls.1>` network list
diff --git a/pkg/api/handlers/libpod/networks.go b/pkg/api/handlers/libpod/networks.go
index 8511e2733..d3bf06988 100644
--- a/pkg/api/handlers/libpod/networks.go
+++ b/pkg/api/handlers/libpod/networks.go
@@ -157,3 +157,21 @@ func Connect(w http.ResponseWriter, r *http.Request) {
}
utils.WriteResponse(w, http.StatusOK, "OK")
}
+
+// ExistsNetwork check if a network exists
+func ExistsNetwork(w http.ResponseWriter, r *http.Request) {
+ runtime := r.Context().Value("runtime").(*libpod.Runtime)
+ name := utils.GetName(r)
+
+ ic := abi.ContainerEngine{Libpod: runtime}
+ report, err := ic.NetworkExists(r.Context(), name)
+ if err != nil {
+ utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err)
+ return
+ }
+ if !report.Value {
+ utils.Error(w, "network not found", http.StatusNotFound, define.ErrNoSuchNetwork)
+ return
+ }
+ utils.WriteResponse(w, http.StatusNoContent, "")
+}
diff --git a/pkg/api/server/register_networks.go b/pkg/api/server/register_networks.go
index 967d7da76..3d9e7fb89 100644
--- a/pkg/api/server/register_networks.go
+++ b/pkg/api/server/register_networks.go
@@ -226,6 +226,28 @@ func (s *APIServer) registerNetworkHandlers(r *mux.Router) error {
// 500:
// $ref: "#/responses/InternalError"
r.HandleFunc(VersionedPath("/libpod/networks/{name}/json"), s.APIHandler(libpod.InspectNetwork)).Methods(http.MethodGet)
+ // swagger:operation GET /libpod/networks/{name}/exists libpod libpodExistsNetwork
+ // ---
+ // tags:
+ // - networks
+ // summary: Network exists
+ // description: Check if network exists
+ // parameters:
+ // - in: path
+ // name: name
+ // type: string
+ // required: true
+ // description: the name or ID of the network
+ // produces:
+ // - application/json
+ // responses:
+ // 204:
+ // description: network exists
+ // 404:
+ // $ref: '#/responses/NoSuchNetwork'
+ // 500:
+ // $ref: '#/responses/InternalError'
+ r.Handle(VersionedPath("/libpod/networks/{name}/exists"), s.APIHandler(libpod.ExistsNetwork)).Methods(http.MethodGet)
// swagger:operation GET /libpod/networks/json libpod libpodListNetwork
// ---
// tags:
diff --git a/pkg/bindings/network/network.go b/pkg/bindings/network/network.go
index 7cd251b0e..8debeee84 100644
--- a/pkg/bindings/network/network.go
+++ b/pkg/bindings/network/network.go
@@ -167,3 +167,16 @@ func Connect(ctx context.Context, networkName string, ContainerNameOrId string,
}
return response.Process(nil)
}
+
+// Exists returns true if a given network exists
+func Exists(ctx context.Context, nameOrID string, options *ExistsOptions) (bool, error) {
+ conn, err := bindings.GetClient(ctx)
+ if err != nil {
+ return false, err
+ }
+ response, err := conn.DoRequest(nil, http.MethodGet, "/networks/%s/exists", nil, nil, nameOrID)
+ if err != nil {
+ return false, err
+ }
+ return response.IsSuccess(), nil
+}
diff --git a/pkg/bindings/network/types.go b/pkg/bindings/network/types.go
index 2a7e500dd..91cbcf044 100644
--- a/pkg/bindings/network/types.go
+++ b/pkg/bindings/network/types.go
@@ -68,3 +68,9 @@ type ConnectOptions struct {
// when using the dns plugin
Aliases *[]string
}
+
+//go:generate go run ../generator/generator.go ExistsOptions
+// ExistsOptions are optional options for checking
+// if a network exists
+type ExistsOptions struct {
+}
diff --git a/pkg/bindings/network/types_exists_options.go b/pkg/bindings/network/types_exists_options.go
new file mode 100644
index 000000000..8076a18e8
--- /dev/null
+++ b/pkg/bindings/network/types_exists_options.go
@@ -0,0 +1,88 @@
+package network
+
+import (
+ "net/url"
+ "reflect"
+ "strconv"
+ "strings"
+
+ jsoniter "github.com/json-iterator/go"
+ "github.com/pkg/errors"
+)
+
+/*
+This file is generated automatically by go generate. Do not edit.
+*/
+
+// Changed
+func (o *ExistsOptions) Changed(fieldName string) bool {
+ r := reflect.ValueOf(o)
+ value := reflect.Indirect(r).FieldByName(fieldName)
+ return !value.IsNil()
+}
+
+// ToParams
+func (o *ExistsOptions) ToParams() (url.Values, error) {
+ params := url.Values{}
+ if o == nil {
+ return params, nil
+ }
+ json := jsoniter.ConfigCompatibleWithStandardLibrary
+ s := reflect.ValueOf(o)
+ if reflect.Ptr == s.Kind() {
+ s = s.Elem()
+ }
+ sType := s.Type()
+ for i := 0; i < s.NumField(); i++ {
+ fieldName := sType.Field(i).Name
+ if !o.Changed(fieldName) {
+ continue
+ }
+ fieldName = strings.ToLower(fieldName)
+ f := s.Field(i)
+ if reflect.Ptr == f.Kind() {
+ f = f.Elem()
+ }
+ switch f.Kind() {
+ case reflect.Bool:
+ params.Set(fieldName, strconv.FormatBool(f.Bool()))
+ case reflect.String:
+ params.Set(fieldName, f.String())
+ case reflect.Int, reflect.Int64:
+ // f.Int() is always an int64
+ params.Set(fieldName, strconv.FormatInt(f.Int(), 10))
+ case reflect.Uint, reflect.Uint64:
+ // f.Uint() is always an uint64
+ params.Set(fieldName, strconv.FormatUint(f.Uint(), 10))
+ case reflect.Slice:
+ typ := reflect.TypeOf(f.Interface()).Elem()
+ switch typ.Kind() {
+ case reflect.String:
+ sl := f.Slice(0, f.Len())
+ s, ok := sl.Interface().([]string)
+ if !ok {
+ return nil, errors.New("failed to convert to string slice")
+ }
+ for _, val := range s {
+ params.Add(fieldName, val)
+ }
+ default:
+ return nil, errors.Errorf("unknown slice type %s", f.Kind().String())
+ }
+ case reflect.Map:
+ lowerCaseKeys := make(map[string][]string)
+ iter := f.MapRange()
+ for iter.Next() {
+ lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string)
+
+ }
+ s, err := json.MarshalToString(lowerCaseKeys)
+ if err != nil {
+ return nil, err
+ }
+
+ params.Set(fieldName, s)
+ }
+ }
+ return params, nil
+}
diff --git a/pkg/domain/entities/engine_container.go b/pkg/domain/entities/engine_container.go
index d2552770c..7b43ac961 100644
--- a/pkg/domain/entities/engine_container.go
+++ b/pkg/domain/entities/engine_container.go
@@ -60,6 +60,7 @@ type ContainerEngine interface {
NetworkConnect(ctx context.Context, networkname string, options NetworkConnectOptions) error
NetworkCreate(ctx context.Context, name string, options NetworkCreateOptions) (*NetworkCreateReport, error)
NetworkDisconnect(ctx context.Context, networkname string, options NetworkDisconnectOptions) error
+ NetworkExists(ctx context.Context, networkname string) (*BoolReport, error)
NetworkInspect(ctx context.Context, namesOrIds []string, options InspectOptions) ([]NetworkInspectReport, []error, error)
NetworkList(ctx context.Context, options NetworkListOptions) ([]*NetworkListReport, error)
NetworkReload(ctx context.Context, names []string, options NetworkReloadOptions) ([]*NetworkReloadReport, error)
diff --git a/pkg/domain/infra/abi/network.go b/pkg/domain/infra/abi/network.go
index e5ecf5c72..bc4328fcd 100644
--- a/pkg/domain/infra/abi/network.go
+++ b/pkg/domain/infra/abi/network.go
@@ -140,3 +140,18 @@ func (ic *ContainerEngine) NetworkDisconnect(ctx context.Context, networkname st
func (ic *ContainerEngine) NetworkConnect(ctx context.Context, networkname string, options entities.NetworkConnectOptions) error {
return ic.Libpod.ConnectContainerToNetwork(options.Container, networkname, options.Aliases)
}
+
+// NetworkExists checks if the given network exists
+func (ic *ContainerEngine) NetworkExists(ctx context.Context, networkname string) (*entities.BoolReport, error) {
+ config, err := ic.Libpod.GetConfig()
+ if err != nil {
+ return nil, err
+ }
+ exists, err := network.Exists(config, networkname)
+ if err != nil {
+ return nil, err
+ }
+ return &entities.BoolReport{
+ Value: exists,
+ }, nil
+}
diff --git a/pkg/domain/infra/tunnel/network.go b/pkg/domain/infra/tunnel/network.go
index d4e827580..bdb1beb03 100644
--- a/pkg/domain/infra/tunnel/network.go
+++ b/pkg/domain/infra/tunnel/network.go
@@ -78,3 +78,14 @@ func (ic *ContainerEngine) NetworkConnect(ctx context.Context, networkname strin
options := new(network.ConnectOptions).WithAliases(opts.Aliases)
return network.Connect(ic.ClientCtx, networkname, opts.Container, options)
}
+
+// NetworkExists checks if the given network exists
+func (ic *ContainerEngine) NetworkExists(ctx context.Context, networkname string) (*entities.BoolReport, error) {
+ exists, err := network.Exists(ic.ClientCtx, networkname, nil)
+ if err != nil {
+ return nil, err
+ }
+ return &entities.BoolReport{
+ Value: exists,
+ }, nil
+}
diff --git a/test/e2e/network_test.go b/test/e2e/network_test.go
index 4e8ab5ad5..98512f01a 100644
--- a/test/e2e/network_test.go
+++ b/test/e2e/network_test.go
@@ -456,4 +456,20 @@ var _ = Describe("Podman network", func() {
nc.WaitWithDefaultTimeout()
Expect(nc.ExitCode()).To(Equal(0))
})
+
+ It("podman network exists", func() {
+ net := "net" + stringid.GenerateNonCryptoID()
+ session := podmanTest.Podman([]string{"network", "create", net})
+ session.WaitWithDefaultTimeout()
+ defer podmanTest.removeCNINetwork(net)
+ Expect(session.ExitCode()).To(BeZero())
+
+ session = podmanTest.Podman([]string{"network", "exists", net})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.Podman([]string{"network", "exists", stringid.GenerateNonCryptoID()})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(1))
+ })
})