From a3a101267fb69b2019d72f98c6e1e202358a585a Mon Sep 17 00:00:00 2001 From: Richard Su Date: Wed, 6 Aug 2014 19:33:10 -0700 Subject: [PATCH] Remove hard-coded ports form ring builder script The swift ring builder script was hard-coded with the default ports. The script now reads the ports from the configuration files under /etc/swift if bind_port is specified. If bind_port is not specified then the default ports are used. Change-Id: Ic1b53d896f2deb23a0f31a7a457eeb20dd38ab5f --- .../os-refresh-config/configure.d/73-swift | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/elements/swift/os-refresh-config/configure.d/73-swift b/elements/swift/os-refresh-config/configure.d/73-swift index 0dc9c2d04..9b74c2794 100755 --- a/elements/swift/os-refresh-config/configure.d/73-swift +++ b/elements/swift/os-refresh-config/configure.d/73-swift @@ -1,6 +1,6 @@ #!/bin/bash -set -eu +set -eux set -o pipefail PARTPOWER=$(os-apply-config --key swift.part-power --key-default 10) @@ -8,6 +8,24 @@ REPLICAS=$(os-apply-config --key swift.replicas --key-default 1) DEVICES=$(os-apply-config --key swift.devices --key-default "" --type raw) ZONES=$(os-apply-config --key swift.zones --key-default 1) +get_bind_port () { + # first argument is the config file path + # second argument is a default port number if it is not found + # in the config file + bind_string=$(grep bind_port $1) + if [ "$bind_string" != "" ]; then + equals_index=$(expr index "$bind_string" "=") + port_number=${bind_string:$equals_index} + echo ${port_number/ /} + else + echo $2 + fi +} + +OBJECT_PORT=$(get_bind_port /etc/swift/object-server.conf 6000) +CONTAINER_PORT=$(get_bind_port /etc/swift/container-server.conf 6001) +ACCOUNT_PORT=$(get_bind_port /etc/swift/account-server.conf 6002) + if [ -z "$DEVICES" ] ; then echo "No swift devices to configure" exit 1 @@ -28,9 +46,9 @@ function place_in_zone () { for DEVICE in ${DEVICES//,/ } ; do DEVICE=$(place_in_zone $DEVICE) - swift-ring-builder /etc/swift/object.builder add ${DEVICE/\%PORT\%/6000} 100 - swift-ring-builder /etc/swift/container.builder add ${DEVICE/\%PORT\%/6001} 100 - swift-ring-builder /etc/swift/account.builder add ${DEVICE/\%PORT\%/6002} 100 + swift-ring-builder /etc/swift/object.builder add ${DEVICE/\%PORT\%/$OBJECT_PORT} 100 + swift-ring-builder /etc/swift/container.builder add ${DEVICE/\%PORT\%/$CONTAINER_PORT} 100 + swift-ring-builder /etc/swift/account.builder add ${DEVICE/\%PORT\%/$ACCOUNT_PORT} 100 done swift-ring-builder /etc/swift/object.builder rebalance 999