From 58ea422ea287196758d8d9e4ac206520401a45f5 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 1 Sep 2015 12:21:28 +0100 Subject: [PATCH 1/3] Optional address argument to dns-add/dns-remove --- weave | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/weave b/weave index 7d093c6609..a1c4039b1e 100755 --- a/weave +++ b/weave @@ -67,8 +67,8 @@ weave run [--with-dns | --without-dns] [ ...] weave start [ ...] weave attach [ ...] weave detach [ ...] -weave dns-add [ ...] [-h ] -weave dns-remove [ ...] [-h ] +weave dns-add [ ...] [-h ] +weave dns-remove [ ...] [-h ] weave dns-lookup weave expose [ ...] [-h ] weave hide [ ...] @@ -735,6 +735,12 @@ echo_addresses() { echo $1 $2 $3 } +echo_ips() { + for CIDR in $3; do + echo ${3%/*} + done +} + peer_args() { res='' sep='' @@ -1502,9 +1508,12 @@ case "$COMMAND" in dns-add) collect_ip_args "$@" shift $IP_COUNT - [ $IP_COUNT -gt 0 -a \( $# -eq 1 -o \( $# -eq 3 -a "$2" = "-h" \) \) ] || usage + [ $# -eq 1 -o \( $# -eq 3 -a "$2" = "-h" \) ] || usage check_running $CONTAINER_NAME CONTAINER=$(container_id $1) + if [ $IP_COUNT -eq 0 ] ; then + IP_ARGS=$(with_container_addresses echo_ips $CONTAINER) + fi if [ $# -eq 1 ] ; then with_container_fqdn $CONTAINER put_dns_fqdn $IP_ARGS else @@ -1514,9 +1523,12 @@ case "$COMMAND" in dns-remove) collect_ip_args "$@" shift $IP_COUNT - [ $IP_COUNT -gt 0 -a \( $# -eq 1 -o \( $# -eq 3 -a "$2" = "-h" \) \) ] || usage + [ $# -eq 1 -o \( $# -eq 3 -a "$2" = "-h" \) ] || usage check_running $CONTAINER_NAME CONTAINER=$(container_id $1) + if [ $IP_COUNT -eq 0 ] ; then + IP_ARGS=$(with_container_addresses echo_ips $CONTAINER) + fi if [ $# -eq 1 ] ; then delete_dns $CONTAINER $IP_ARGS else From 1472e35011bef3cd44f195b39704d56dc26873ee Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 1 Sep 2015 12:25:37 +0100 Subject: [PATCH 2/3] Update documentation --- site/weavedns.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/site/weavedns.md b/site/weavedns.md index a562c692d2..9a697f2ce6 100644 --- a/site/weavedns.md +++ b/site/weavedns.md @@ -148,18 +148,20 @@ If you want to give the container a name in DNS *other* than its hostname, you can register it using the `dns-add` command. For example: ```bash -$ C=$(docker run -e WEAVE_CIDR=10.2.1.27/24 -ti ubuntu) -$ weave dns-add 10.2.1.27 $C -h pingme2.weave.local +$ C=$(docker run -ti ubuntu) +$ weave dns-add $C -h pingme2.weave.local ``` You can also use `dns-add` to add the container's configured hostname -and domain, simply by omitting `-h `. +and domain simply by omitting `-h `, or specify additional IP +addresses to be registered against the container's hostname e.g. +`weave dns-add 10.2.1.27 $C`. The inverse operation can be carried out using the `dns-remove` command: ```bash -$ weave dns-remove 10.2.1.27 $C +$ weave dns-remove $C ``` ## Resolve weaveDNS entries from host From 0125e67b35aa803f8699c8c7efdac6052d73f642 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 1 Sep 2015 12:38:15 +0100 Subject: [PATCH 3/3] Implement smoke test --- test/240_dns_add_name_test.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/240_dns_add_name_test.sh b/test/240_dns_add_name_test.sh index 87badd50eb..10efa62180 100755 --- a/test/240_dns_add_name_test.sh +++ b/test/240_dns_add_name_test.sh @@ -20,7 +20,7 @@ weave_on $HOST1 dns-add $C2 c2 -h $NAME2 assert_dns_record $HOST1 c1 $NAME2 $C2 weave_on $HOST1 dns-add $C1 c1 -h $NAME1 -weave_on $HOST1 dns-add $C1 c1 -h $NAME3 +weave_on $HOST1 dns-add c1 -h $NAME3 assert_dns_a_record $HOST1 c1 $NAME1 $C1 assert_dns_a_record $HOST1 c1 $NAME3 $C1 @@ -30,4 +30,8 @@ weave_on $HOST1 dns-remove $C1 c1 -h $NAME1 assert_no_dns_record $HOST1 c1 $NAME1 assert_dns_a_record $HOST1 c1 $NAME3 $C1 +weave_on $HOST1 dns-remove c1 -h $NAME3 + +assert_no_dns_record $HOST1 c1 $NAME3 + end_suite