From e9256b6e8e3403e1435e4f1b65726dbb5dd991eb Mon Sep 17 00:00:00 2001 From: Matthias Stecher Date: Sat, 4 Jul 2020 18:19:46 +0200 Subject: [PATCH] [__lxc_container] create: added backingstore and template options With some minor changes, the backingstore parameters and some more template options where added (incl. `man.rst`). --- cdist/conf/type/__lxc_container/gencode-local | 22 ++++++- .../conf/type/__lxc_container/gencode-remote | 56 ++++++++++++++---- cdist/conf/type/__lxc_container/man.rst | 59 +++++++++++++++++-- cdist/conf/type/__lxc_container/manifest | 39 ++++++++++-- .../type/__lxc_container/parameter/optional | 9 +++ cdist/conf/type/__lxc_container/todo.txt | 17 +----- 6 files changed, 161 insertions(+), 41 deletions(-) diff --git a/cdist/conf/type/__lxc_container/gencode-local b/cdist/conf/type/__lxc_container/gencode-local index 04935070..e0572bb4 100755 --- a/cdist/conf/type/__lxc_container/gencode-local +++ b/cdist/conf/type/__lxc_container/gencode-local @@ -4,9 +4,18 @@ # This uploads the diff of the configuration file, which is applied by gencode-remote -# Check desired state +# Get required parameters +name="$__object/parameter/name" +if [ -f "$name" ]; then + name="$(cat "$name")" +else + name="$__object_id" +fi + +state_is="$(cat "$__object/explorer/state")" state_should="$(cat "$__object/parameter/state")" + # Check the configurations only if the container exists if [ "$state_should" != "absent" ]; then # do changes @@ -22,6 +31,13 @@ if [ "$state_should" != "absent" ]; then my_target_host="${__target_host}" fi + # create remote container directory if container is not yet available + if [ "$state_is" = "absent" ]; then + # this must be done because the container will be created after the configuration is uploaded + # would also be possible to do everything in gencode-remote to keep the order + $__remote_exec $__target_host "mkdir $(dirname "$container_config")" + fi + # config-present # remove all config lines from config-present that are already set or absent anyway @@ -31,7 +47,7 @@ if [ "$state_should" != "absent" ]; then # get temp file name add_dest="$($__remote_exec $__target_host "mktemp $container_config-add.XXXXXXXXXX")" printf "%s" "$add_dest" > "$__object/files/remote-tmpfile_add" - # upload diff + # upload delta cat < "$__object/files/remote-tmpfile_del" - # upload diff + # upload delta cat <&2 echo "error: --bdev-dir is only possible for backingstore 'dir' or 'none'" + exit 2 + fi + fi + + if [ "$backingstore" != "lvm" ] && [ "$backingstore" != "loop" ]; then + if [ -f "$param/bdev-fstype" ] \ + || [ -f "$param/bdev-fssize" ] + then + >&2 echo "error: --bdev-fstype and --bdev-fssize only available for backingstore 'lvm' or 'loop'" + exit 2 + fi + fi + + if [ "$backingstore" != "lvm" ]; then + if [ -f "$param/bdev-lvname" ] \ + || [ -f "$param/bdev-vgname" ] \ + || [ -f "$param/bdev-thinpool" ] + then + >&2 echo "error: --bdev-{lv,vg}name and --bdev-thinpool only available for backingstore 'lvm'" + exit 2 + fi + fi +fi + diff --git a/cdist/conf/type/__lxc_container/parameter/optional b/cdist/conf/type/__lxc_container/parameter/optional index fc4bb71b..257283d8 100644 --- a/cdist/conf/type/__lxc_container/parameter/optional +++ b/cdist/conf/type/__lxc_container/parameter/optional @@ -6,5 +6,14 @@ template default-config release arch +mirror +ssh-key clone clonepath +backingstore +bdev-dir +bdev-fstype +bdev-fssize +bdev-lvname +bdev-vgname +bdev-thinpool diff --git a/cdist/conf/type/__lxc_container/todo.txt b/cdist/conf/type/__lxc_container/todo.txt index 17c4edaf..e5f8f471 100644 --- a/cdist/conf/type/__lxc_container/todo.txt +++ b/cdist/conf/type/__lxc_container/todo.txt @@ -1,28 +1,13 @@ # List of all featues that should be implemented -storage: - - backing_storage - - other settings prior to storage template: - type: a.E. debian, ubuntu -> what on change? - - release - - arch - - possible ssh auth key? - possible root_password? - possible packages? - - possible mirrors? - other options?? -auto..: +auto.. (lxc autostart): - group - start -lxc config .. -how to find lxc containers path? -lxc-copy: ephemeral containers? -> seperate type if it makes sense If config already created, it's considered the container is already created -> first create; then setup detection if template changed?? - - -lxc configuration at startup: - flag -f can used to set a default config (instead the system default) - there is no problem to change config before the first startup