confd: refactor how container networks are sent to container helper

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2024-02-25 19:49:27 +01:00
parent aa7ea66a0d
commit f1bf02eda5
2 changed files with 11 additions and 8 deletions
+7 -4
View File
@@ -26,9 +26,6 @@ create()
# args="$args --log-opt tag=$name"
pidfn=/run/container:${name}.pid
for net in "$@"; do
network="$network --net $net"
done
log "---------------------------------------"
log "Got name: $name image: $image"
log "Got networks: $network"
@@ -47,9 +44,10 @@ create()
# --syslog --log-level info
log "Calling \"podman create --name $name --conmon-pidfile=$pidfn $hostname $env $network $port $args $image\""
set -x
if podman create --name "$name" --conmon-pidfile="$pidfn" $hostname $env $network $port $args "$image"; then
log "Successfully created container $name from $image"
rm "/run/containers/env/${name}.env"
rm -f "/run/containers/env/${name}.env"
initctl show "container:$name" |grep -q manual:yes || initctl -bq start "container:$name"
initctl -nbq cond set container:$name
exit 0
@@ -88,6 +86,7 @@ options:
-f, --force Force operation, e.g. remove
-h, --help Show this help text
--hostname NAME Set hostname when creating container
--net NETWORK Set network(s) when creating container
-p, --publish PORT Publish ports when creating container
Syntax: [[ip:][hostPort]:]containerPort[/protocol]
-s, --simple Show output in simplified format
@@ -134,6 +133,10 @@ while [ "$1" != "" ]; do
shift
hostname="--hostname $1"
;;
--net)
shift
network="$network --net $1"
;;
-p | --publish)
shift
port="$port -p $1"
+4 -4
View File
@@ -68,15 +68,13 @@ static int add(const char *name, struct lyd_node *cif)
fprintf(fp, " -e /run/containers/env/%s.env", name);
}
fprintf(fp, " create %s %s", name, image);
LYX_LIST_FOR_EACH(lyd_child(cif), node, "network") {
struct lyd_node *opt;
const char *name;
int first = 1;
name = lydx_get_cattr(node, "name");
fprintf(fp, " %s", name);
fprintf(fp, " --net %s", name);
LYX_LIST_FOR_EACH(lyd_child(node), opt, "option") {
const char *option = lyd_get_value(opt);
@@ -86,7 +84,9 @@ static int add(const char *name, struct lyd_node *cif)
}
if (lydx_is_enabled(cif, "host-network"))
fprintf(fp, " host");
fprintf(fp, " --net host");
fprintf(fp, " create %s %s", name, image);
fprintf(fp, "\n");
fchmod(fileno(fp), 0700);