Merge pull request #1073 from weaveworks/971_check_container_alive_in_api
make container aliveness check part of the ipam & dns API
This commit is contained in:
commit
33921c2cfe
4 files changed
+19
-25
No files matched your search
@@ -767,12 +767,17 @@ with_container_fqdn() {
|
||||
|
||||
# Register FQDN in $2 as names for addresses $3.. under full container ID $1
|
||||
put_dns_fqdn() {
|
||||
CHECK_ALIVE="-d check-alive=true"
|
||||
if [ "$1" = "--no-check-alive" ] ; then
|
||||
CHECK_ALIVE=
|
||||
shift 1
|
||||
fi
|
||||
CONTAINER_ID="$1"
|
||||
FQDN="$2"
|
||||
shift 2
|
||||
|
||||
for ADDR in "$@" ; do
|
||||
call_dns PUT /name/$CONTAINER_ID/${ADDR%/*} --data-urlencode fqdn=$FQDN || true
|
||||
call_dns PUT /name/$CONTAINER_ID/${ADDR%/*} --data-urlencode fqdn=$FQDN $CHECK_ALIVE || true
|
||||
done
|
||||
}
|
||||
|
||||
@@ -827,13 +832,18 @@ ipam_claim() {
|
||||
# $1 is the full container id and following args are previously parsed CIDR_ARGS.
|
||||
# Returns ALL_CIDRS and IPAM_CIDRS
|
||||
ipam_cidrs() {
|
||||
CHECK_ALIVE="?check-alive=true"
|
||||
if [ "$1" = "--no-check-alive" ] ; then
|
||||
CHECK_ALIVE=
|
||||
shift 1
|
||||
fi
|
||||
CONTAINER_ID="$1"
|
||||
shift 1
|
||||
ALL_CIDRS=""
|
||||
IPAM_CIDRs=""
|
||||
if [ $# -eq 0 ] ; then
|
||||
# If no addresses passed in, get one in the default subnet
|
||||
IPAM_CIDRS=$(call_weave POST /ip/$CONTAINER_ID) || return 1
|
||||
IPAM_CIDRS=$(call_weave POST /ip/$CONTAINER_ID$CHECK_ALIVE) || return 1
|
||||
if [ "$IPAM_CIDRS" = "404 page not found" ] ; then
|
||||
echo "No IP address supplied (use the -iprange option on 'weave launch' to enable IP address allocation)" >&2
|
||||
return 1
|
||||
@@ -847,7 +857,7 @@ ipam_cidrs() {
|
||||
else
|
||||
IPAM_URL=/ip/$CONTAINER_ID/"${1#net:}"
|
||||
fi
|
||||
CIDR=$(call_weave POST $IPAM_URL) || return 1
|
||||
CIDR=$(call_weave POST $IPAM_URL$CHECK_ALIVE) || return 1
|
||||
if [ "$CIDR" = "404 page not found" ] ; then
|
||||
echo "IP address allocation must be enabled to use 'net:'" >&2
|
||||
return 1
|
||||
@@ -1353,7 +1363,7 @@ case "$COMMAND" in
|
||||
expose)
|
||||
collect_cidr_args "$@"
|
||||
shift $CIDR_ARG_COUNT
|
||||
ipam_cidrs weave:expose $CIDR_ARGS
|
||||
ipam_cidrs --no-check-alive weave:expose $CIDR_ARGS
|
||||
if [ $# -eq 0 ] ; then
|
||||
FQDN=""
|
||||
else
|
||||
@@ -1368,7 +1378,7 @@ case "$COMMAND" in
|
||||
add_iptables_rule nat WEAVE -d $CIDR ! -s $CIDR -j MASQUERADE
|
||||
add_iptables_rule nat WEAVE -s $CIDR ! -d $CIDR -j MASQUERADE
|
||||
if [ -n "$FQDN" ] ; then
|
||||
when_dns_running put_dns_fqdn weave:expose $FQDN $CIDR
|
||||
when_dns_running put_dns_fqdn --no-check-alive weave:expose $FQDN $CIDR
|
||||
fi
|
||||
fi
|
||||
done
|
||||
@@ -1377,7 +1387,7 @@ case "$COMMAND" in
|
||||
hide)
|
||||
collect_cidr_args "$@"
|
||||
shift $CIDR_ARG_COUNT
|
||||
ipam_cidrs weave:expose $CIDR_ARGS
|
||||
ipam_cidrs --no-check-alive weave:expose $CIDR_ARGS
|
||||
create_bridge --without-ethtool
|
||||
for CIDR in $ALL_CIDRS ; do
|
||||
if ip addr show dev $BRIDGE | grep -qF $CIDR ; then
|
||||
|
||||
Reference in new issue
Block a user