refactor: introduce a small helper so we don't repeat ourselves
This commit is contained in:
1 parent
82ac69be4e
commit
27f477a075
1 file changed
+7
-3
@@ -1277,6 +1277,10 @@ collect_dns_add_remove_args() {
|
|||||||
# IP Allocation Management helpers
|
# IP Allocation Management helpers
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
check_overlap() {
|
||||||
|
! command_exists netcheck || netcheck --ignore-iface=$BRIDGE $1
|
||||||
|
}
|
||||||
|
|
||||||
# Claim addresses for a container in IPAM. Expects to be called from
|
# Claim addresses for a container in IPAM. Expects to be called from
|
||||||
# with_container_addresses.
|
# with_container_addresses.
|
||||||
ipam_reclaim() {
|
ipam_reclaim() {
|
||||||
@@ -1337,7 +1341,7 @@ ipam_cidrs() {
|
|||||||
else
|
else
|
||||||
if [ "$METHOD" = "POST" ] ; then
|
if [ "$METHOD" = "POST" ] ; then
|
||||||
# Assignment of a plain IP address; warn if it clashes but carry on
|
# Assignment of a plain IP address; warn if it clashes but carry on
|
||||||
command_exists netcheck && netcheck --ignore-iface=$BRIDGE $arg || true
|
check_overlap $arg || true
|
||||||
if container_ip $CONTAINER_NAME 2>/dev/null ; then
|
if container_ip $CONTAINER_NAME 2>/dev/null ; then
|
||||||
http_call $CONTAINER_IP:$HTTP_PORT PUT /ip/$CONTAINER_ID/${arg%/*} >&2
|
http_call $CONTAINER_IP:$HTTP_PORT PUT /ip/$CONTAINER_ID/${arg%/*} >&2
|
||||||
fi
|
fi
|
||||||
@@ -1594,13 +1598,13 @@ launch_router() {
|
|||||||
eval "set -- $ARGS"
|
eval "set -- $ARGS"
|
||||||
if [ -z "$IPRANGE_SPECIFIED" ] ; then
|
if [ -z "$IPRANGE_SPECIFIED" ] ; then
|
||||||
IPRANGE="10.32.0.0/12"
|
IPRANGE="10.32.0.0/12"
|
||||||
if command_exists netcheck && ! netcheck --ignore-iface=$BRIDGE $IPRANGE ; then
|
if ! check_overlap $IPRANGE ; then
|
||||||
echo "ERROR: Default --ipalloc-range $IPRANGE overlaps with existing route on host." >&2
|
echo "ERROR: Default --ipalloc-range $IPRANGE overlaps with existing route on host." >&2
|
||||||
echo "You must pick another range and set it on all hosts." >&2
|
echo "You must pick another range and set it on all hosts." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ -n "$IPRANGE" ] && command_exists netcheck && ! netcheck --ignore-iface=$BRIDGE $IPRANGE ; then
|
if [ -n "$IPRANGE" ] && ! check_overlap $IPRANGE ; then
|
||||||
echo "WARNING: Specified --ipalloc-range $IPRANGE overlaps with existing route on host." >&2
|
echo "WARNING: Specified --ipalloc-range $IPRANGE overlaps with existing route on host." >&2
|
||||||
echo "Unless this is deliberate, you must pick another range and set it on all hosts." >&2
|
echo "Unless this is deliberate, you must pick another range and set it on all hosts." >&2
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in new issue
Block a user