From 91f9bf171d1dedd6bde3add4b4b265cd77fb38e4 Mon Sep 17 00:00:00 2001 From: Gitouche <26656-gitouche@users.noreply.framagit.org> Date: Fri, 4 Jun 2021 15:33:24 +0200 Subject: [PATCH] functions : add pod functions --- functions.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/functions.sh b/functions.sh index f67bbb0..4766614 100644 --- a/functions.sh +++ b/functions.sh @@ -141,3 +141,53 @@ ensure_container_not_running () { return 0 fi } + +# check: pod $1 exists? +check_pod_exists () { + podman pod exists ${1} +} + +# ok if pod exists +ensure_pod_exists () { + if ! check_pod_exists ${1}; then + echo "ERROR : pod ${1} does not exists" + exit 1 + else + return 0 + fi +} + +# ok if pod does not exists +ensure_pod_not_exists () { + if check_pod_exists ${1}; then + echo "ERROR : pod ${1} exists" + exit 1 + else + return 0 + fi +} + +# check: pod ${1} is running? +check_pod_running () { + [[ "podman pod inspect -f '{{.State}}' ${1}" == "Running" ]] +} + +# ok if pod is running +ensure_pod_running () { + if ! check_pod_running ${1}; then + echo "ERROR : pod ${1} is not running" + exit 1 + else + return 0 + fi +} + +# ok if pod is not running +ensure_pod_not_running () { + if check_pod_running ${1}; then + echo "ERROR : pod ${1} is running" + exit 1 + else + return 0 + fi +}