From 7c77658ff84fdfb459d76ecc9b1b895f84408c73 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Fri, 22 Jan 2016 11:25:44 +0700 Subject: [PATCH] new: allow relations to avoid creating any links. This is done through a new ``tech-dep`` attribute in the definition of the relation (done in the ``provide`` part of the ``metadata.yml`` of a charm). This replaces the ``reverse-tech-dep`` as it no allows 3 values. The default one is ``True`` which simply allow the creation of a ``link`` in the ``docker-compose`` file. The value ``False`` will prevent creation of any ``link``, and the ``reversed`` value will reverse the ``link`` created. --- bin/compose | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/bin/compose b/bin/compose index 92aa56a..005bfd2 100755 --- a/bin/compose +++ b/bin/compose @@ -212,12 +212,12 @@ _get_docker_compose_links() { master_charm=$(_get_top_master_charm_for_service "$service") || return 1 deps=() - while read-0 relation_name target_service relation_config reverse; do + while read-0 relation_name target_service relation_config tech_dep; do master_target_charm="$(_get_top_master_charm_for_service "$target_service")" [ "$master_charm" == "$master_target_charm" ] && continue - if [ "$reverse" ]; then + if [ "$tech_dep" == "reversed" ]; then deps+=("$(echo -en "$master_target_charm:\n links:\n - $master_charm")") - else + elif [ "$tech_dep" == "True" ]; then deps+=("$(echo -en "$master_charm:\n links:\n - $master_target_charm")") fi done < <(get_compose_relations "$service") || return 1 @@ -580,7 +580,7 @@ get_charm_relation_def () { export -f get_charm_relation_def -get_charm_reverse_tech_dep_relation() { +get_charm_tech_dep_orientation_for_relation() { local charm="$1" relation_name="$2" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" \ relation_def metadata value if [ -e "$cache_file" ]; then @@ -589,14 +589,15 @@ get_charm_reverse_tech_dep_relation() { return 0 fi relation_def=$(get_charm_relation_def "$charm" "$relation_name" 2>/dev/null) - value=$(echo "$relation_def" | shyaml get-value 'reverse-tech-dep' 2>/dev/null) + value=$(echo "$relation_def" | shyaml get-value 'tech-dep' 2>/dev/null) + value=${value:-True} echo "$value" | tee "$cache_file" } -export -f get_charm_reverse_tech_dep_relation +export -f get_charm_tech_dep_orientation_for_relation ## ## Use compose file to get deps, and relation definition in metadata.yml -## for reverse-tech-dep attribute. +## for tech-dep attribute. get_service_deps() { local service="$1" cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" if [ -e "$cache_file" ]; then @@ -607,7 +608,7 @@ get_service_deps() { ( set -o pipefail get_compose_relations "$service" | \ - while read-0 relation_name target_service _relation_config reverse; do + while read-0 relation_name target_service _relation_config tech_dep; do echo "$target_service" done | tee "$cache_file" ) || return 1 @@ -923,19 +924,19 @@ get_compose_relations () { case "$(echo "$relation_def" | shyaml get-type 2>/dev/null)" in "str") target_service="$(echo "$relation_def" | shyaml get-value 2>/dev/null)" - reverse="$(get_charm_reverse_tech_dep_relation "$target_service" "$relation_name")" - echo -en "$relation_name\0$target_service\0\0$reverse\0" + tech_dep="$(get_charm_tech_dep_orientation_for_relation "$target_service" "$relation_name")" + echo -en "$relation_name\0$target_service\0\0$tech_dep\0" ;; "sequence") while read-0 target_service; do - reverse="$(get_charm_reverse_tech_dep_relation "$target_service" "$relation_name")" - echo -en "$relation_name\0$target_service\0\0$reverse\0" + tech_dep="$(get_charm_tech_dep_orientation_for_relation "$target_service" "$relation_name")" + echo -en "$relation_name\0$target_service\0\0$tech_dep\0" done < <(echo "$relation_def" | shyaml get-values-0 2>/dev/null) ;; "struct") while read-0 target_service relation_config; do - reverse="$(get_charm_reverse_tech_dep_relation "$target_service" "$relation_name")" - echo -en "$relation_name\0$target_service\0$relation_config\0$reverse\0" + tech_dep="$(get_charm_tech_dep_orientation_for_relation "$target_service" "$relation_name")" + echo -en "$relation_name\0$target_service\0$relation_config\0$tech_dep\0" done < <(echo "$relation_def" | shyaml key-values-0 2>/dev/null) ;; esac @@ -961,7 +962,7 @@ run_service_relations () { for subservice in $(get_service_deps "$service") "$service"; do [ "${loaded[$subservice]}" ] && continue # debug " Relations of ${DARKYELLOW}$subservice${NORMAL}:" - while read-0 relation_name target_service relation_config reverse; do + while read-0 relation_name target_service relation_config tech_dep; do export relation_config Wrap -d "Building $DARKYELLOW$subservice$NORMAL --$DARKBLUE$relation_name$NORMAL--> $DARKYELLOW$target_service$NORMAL" <