From a89b549c40dd3e3e51b791596c702e08dc8b1d85 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 10 Jun 2015 15:44:43 +0100 Subject: [PATCH] Change command-line syntax to net: prefix instead of --subnet --- site/ipam.md | 8 ++++---- test/100_cross_hosts_test.sh | 8 ++++---- test/500_weave_multi_cidr_test.sh | 16 ++++++++-------- weave | 19 ++++++------------- 4 files changed, 22 insertions(+), 29 deletions(-) diff --git a/site/ipam.md b/site/ipam.md index f97086e7..c2b4856f 100644 --- a/site/ipam.md +++ b/site/ipam.md @@ -33,16 +33,16 @@ allocation, and `-ipsubnet` is the subnet that will be used when you don't explicitly specify one. Then, to request the allocation of an address from a subnet other than -the default, use `--subnet`: +the default, use the `net:` prefix: - host1# C=$(weave run --subnet 10.2.7.0/24 -ti ubuntu) + host1# C=$(weave run net:10.2.7.0/24 -ti ubuntu) -To explicitly request the default subnet, use `--subnet default`. +To explicitly request the default subnet, use `net:default`. And, you can ask for multiple addresses in different subnets and add in manually-assigned addresses on the same line, for instance: - host1# C=$(weave run --subnet 10.2.7.0/24 --subnet 10.2.8.0/24 10.3.9.1/24 -ti ubuntu) + host1# C=$(weave run net:10.2.7.0/24 net:10.2.8.0/24 ip:10.3.9.1/24 -ti ubuntu) Note that `-iprange` can be smaller than `-ipsubnet`, if you want to use a mixture of automatically-allocated addresses and manually-chosen diff --git a/test/100_cross_hosts_test.sh b/test/100_cross_hosts_test.sh index 425749e9..2266b9dd 100755 --- a/test/100_cross_hosts_test.sh +++ b/test/100_cross_hosts_test.sh @@ -14,16 +14,16 @@ weave_on $HOST1 launch -iprange $UNIVERSE -ipsubnet $SUBNET_1 weave_on $HOST2 launch -iprange $UNIVERSE -ipsubnet $SUBNET_1 $HOST1 start_container $HOST1 $C1/24 --name=c1 -start_container $HOST2 $C2/24 --name=c2 +start_container $HOST2 ip:$C2/24 --name=c2 assert_raises "exec_on $HOST1 c1 $PING $C2" start_container $HOST1 --name=c3 -start_container $HOST2 --subnet default --name=c4 +start_container $HOST2 net:default --name=c4 C4=$(container_ip $HOST2 c4) assert_raises "exec_on $HOST1 c3 $PING $C4" -start_container $HOST1 --subnet $SUBNET_2 --name=c5 -start_container $HOST2 --subnet $SUBNET_2 --name=c6 +start_container $HOST1 net:$SUBNET_2 --name=c5 +start_container $HOST2 net:$SUBNET_2 --name=c6 C6=$(container_ip $HOST2 c6) assert_raises "exec_on $HOST1 c5 $PING $C6" diff --git a/test/500_weave_multi_cidr_test.sh b/test/500_weave_multi_cidr_test.sh index b400ad1d..2d392715 100755 --- a/test/500_weave_multi_cidr_test.sh +++ b/test/500_weave_multi_cidr_test.sh @@ -42,7 +42,7 @@ assert_bridge_cidrs() { start_suite "Weave run/start/attach/detach with multiple cidr arguments" -# NOTE: in these tests, --subnet arguments are checked against a +# NOTE: in these tests, net: arguments are checked against a # specific address, i.e. we are assuming that IPAM always returns the # lowest available address in the subnet @@ -50,37 +50,37 @@ weave_on $HOST1 launch -debug -iprange 10.2.3.0/24 weave_on $HOST1 launch-dns 10.254.254.254/24 # Run container with three cidrs -CID=$(start_container $HOST1 10.2.1.1/24 10.2.2.1/24 --subnet 10.2.3.0/24 --name=multicidr -h $NAME | cut -b 1-12) +CID=$(start_container $HOST1 ip:10.2.1.1/24 10.2.2.1/24 net:10.2.3.0/24 --name=multicidr -h $NAME | cut -b 1-12) assert_container_cidrs $HOST1 $CID 10.2.1.1/24 10.2.2.1/24 10.2.3.1/24 assert_zone_records $HOST1 $CID $NAME. 10.2.1.1 10.2.2.1 10.2.3.1 # Remove two of them -weave_on $HOST1 detach 10.2.1.1/24 --subnet 10.2.3.0/24 $CID +weave_on $HOST1 detach 10.2.1.1/24 net:10.2.3.0/24 $CID assert_container_cidrs $HOST1 $CID 10.2.2.1/24 assert_zone_records $HOST1 $CID $NAME. 10.2.2.1 # Put them both back -weave_on $HOST1 attach 10.2.1.1/24 --subnet 10.2.3.0/24 $CID +weave_on $HOST1 attach ip:10.2.1.1/24 net:10.2.3.0/24 $CID assert_container_cidrs $HOST1 $CID 10.2.2.1/24 10.2.1.1/24 10.2.3.1/24 assert_zone_records $HOST1 $CID $NAME. 10.2.2.1 10.2.1.1 10.2.3.1 # Stop the container, restart with three IPs docker_on $HOST1 stop $CID -weave_on $HOST1 start 10.2.1.1/24 10.2.2.1/24 --subnet 10.2.3.0/24 $CID +weave_on $HOST1 start 10.2.1.1/24 ip:10.2.2.1/24 net:10.2.3.0/24 $CID assert_container_cidrs $HOST1 $CID 10.2.1.1/24 10.2.2.1/24 10.2.3.1/24 assert_zone_records $HOST1 $CID $NAME. 10.2.1.1 10.2.2.1 10.2.3.1 # Expose some cidrs -weave_on $HOST1 expose 10.2.1.2/24 10.2.2.2/24 --subnet 10.2.3.0/24 +weave_on $HOST1 expose 10.2.1.2/24 10.2.2.2/24 net:10.2.3.0/24 assert_bridge_cidrs $HOST1 weave 10.2.1.2/24 10.2.2.2/24 10.2.3.2/24 # Hide some cidrs -weave_on $HOST1 hide 10.2.1.2/24 --subnet 10.2.3.0/24 +weave_on $HOST1 hide 10.2.1.2/24 net:10.2.3.0/24 assert_bridge_cidrs $HOST1 weave 10.2.2.2/24 # Now detach and run another container to check we have released IPs in IPAM weave_on $HOST1 detach $CID -CID2=$(start_container $HOST1 --subnet 10.2.3.0/24) +CID2=$(start_container $HOST1 net:10.2.3.0/24) assert_container_cidrs $HOST1 $CID2 10.2.3.1/24 end_suite diff --git a/weave b/weave index 5bcf1b29..8f3153fb 100755 --- a/weave +++ b/weave @@ -55,7 +55,7 @@ usage() { echo "where = [:]" echo " = /" echo " = or weave internal peer ID" - echo " = | --subnet | --subnet default" + echo " = [ip:] | net: | net:default" echo "
= [tcp://][]:" exit 1 } @@ -106,15 +106,9 @@ validate_cidr() { collect_cidr_args() { CIDR_ARGS="" CIDR_ARG_COUNT=0 - while is_cidr "$1" || [ "$1" = "--subnet" ] ; do - CIDR_ARGS="$CIDR_ARGS $1" + while [ "$1" = "net:default" ] || is_cidr "$1" || is_cidr "${1#ip:}" || is_cidr "${1#net:}" ; do + CIDR_ARGS="$CIDR_ARGS ${1#ip:}" CIDR_ARG_COUNT=$((CIDR_ARG_COUNT + 1)) - # only accept 'default' after '--subnet', in case someone has a container called 'default' - if [ "$1" = "--subnet" -a "$2" = "default" ] ; then - CIDR_ARGS="$CIDR_ARGS $2" - CIDR_ARG_COUNT=$((CIDR_ARG_COUNT + 1)) - shift 1 - fi shift 1 done } @@ -776,12 +770,11 @@ ipam_cidrs() { ALL_CIDRS="$IPAM_CIDRS" fi while [ $# -gt 0 ] ; do - if [ $# -gt 1 -a "$1" = "--subnet" ] ; then - shift 1 - if [ "$1" = "default" ] ; then + if [ "${1%:*}" = "net" ] ; then + if [ "$1" = "net:default" ] ; then CIDR=$(http_call $CONTAINER_NAME $HTTP_PORT POST /ip/$CONTAINER_ID) else - CIDR=$(http_call $CONTAINER_NAME $HTTP_PORT POST /ip/$CONTAINER_ID/$1) + CIDR=$(http_call $CONTAINER_NAME $HTTP_PORT POST /ip/$CONTAINER_ID/"${1#net:}") fi if [ "$CIDR" = "404 page not found" ] ; then echo "IP address allocation must be enabled to use --subnet (use the -iprange option on 'weave launch')" >&2