diff --git a/snapcraft.yaml b/snapcraft.yaml index 6ee634366..4523405f6 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -59,6 +59,11 @@ source-code: https://github.com/canonical/lxd website: https://ubuntu.com/lxd confinement: strict +plugs: + ceph-conf: + interface: content + target: "$SNAP_DATA/microceph" + apps: # Main commands activate: diff --git a/snapcraft/hooks/connect-plug-ceph-conf b/snapcraft/hooks/connect-plug-ceph-conf new file mode 100755 index 000000000..df2b58b2c --- /dev/null +++ b/snapcraft/hooks/connect-plug-ceph-conf @@ -0,0 +1,31 @@ +#!/bin/sh + +# Utility functions +get_bool() { + value=$(echo "${1:-}" | tr '[:upper:]' '[:lower:]') + + # See if it's true + for yes in "true" "1" "yes" "on"; do + if [ "${value}" = "${yes}" ]; then + echo "true" + return + fi + done + + # See if it's false + for no in "false" "0" "no" "off"; do + if [ "${value}" = "${no}" ]; then + echo "false" + return + fi + done + + # Invalid value (or not set) + return +} + +ceph_builtin=$(get_bool "$(snapctl get ceph.builtin)") + +if ! [ "${ceph_builtin:-"false"}" = "true" ]; then + ln -snf ${SNAP_DATA}/microceph/conf/ /etc/ceph +fi diff --git a/snapcraft/hooks/disconnect-plug-ceph-conf b/snapcraft/hooks/disconnect-plug-ceph-conf new file mode 100755 index 000000000..b169f23d8 --- /dev/null +++ b/snapcraft/hooks/disconnect-plug-ceph-conf @@ -0,0 +1,34 @@ +#!/bin/sh + +# Utility functions +get_bool() { + value=$(echo "${1:-}" | tr '[:upper:]' '[:lower:]') + + # See if it's true + for yes in "true" "1" "yes" "on"; do + if [ "${value}" = "${yes}" ]; then + echo "true" + return + fi + done + + # See if it's false + for no in "false" "0" "no" "off"; do + if [ "${value}" = "${no}" ]; then + echo "false" + return + fi + done + + # Invalid value (or not set) + return +} + +ceph_builtin=$(get_bool "$(snapctl get ceph.builtin)") + +if [ "${ceph_builtin:-"false"}" = "true" ]; then + mkdir -p "${SNAP_COMMON}/ceph" + ln -snf "${SNAP_COMMON}/ceph" /etc/ceph +else + ln -snf /var/lib/snapd/hostfs/etc/ceph /etc/ceph +fi