Created
April 30, 2014 23:07
-
-
Save DimShadoWWW/530290137237b5419dd4 to your computer and use it in GitHub Desktop.
configuring vulcand from bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function genID() { | |
| echo $RANDOM | |
| } | |
| function addHost() { | |
| if [[ -z $3 ]] | |
| then | |
| "addHost hostname ipaddress port" | |
| exit 1 | |
| fi | |
| NAME=${1}.local | |
| IP=$2 | |
| PORT=$3 | |
| echo create host $NAME | |
| etcdctl ls /vulcand/hosts/$NAME | |
| [[ $? > 0 ]] && etcdctl mkdir /vulcand/hosts/$NAME # not exists | |
| echo added location "http://$IP:$PORT" | |
| etcdctl ls /vulcand/hosts/$NAME/locations/ | |
| [[ $? == 0 ]] && for i in $(etcdctl ls /vulcand/hosts/$NAME/locations/) | |
| do | |
| for j in $(etcdctl ls /vulcand/upstreams/$(etcdctl get $i/upstream)/endpoints/) | |
| do | |
| if [[ $(etcdctl get $j) == "http://$IP:$PORT" ]] | |
| then | |
| echo "Already in configured endpoints" | |
| return 0 | |
| fi | |
| done | |
| done | |
| echo create upstream | |
| id=`genID` | |
| etcdctl ls /vulcand/upstreams/$id | |
| while [[ $? != 4 ]] | |
| do | |
| id=`genID` | |
| etcdctl ls /vulcand/upstreams/$id | |
| done | |
| upstreamId=$id | |
| etcdctl mkdir /vulcand/upstreams/$upstreamId | |
| echo create endpoint | |
| id=`genID` | |
| etcdctl ls /vulcand/upstreams/$upstreamId/endpoints/$id | |
| while [[ $? != 4 ]] | |
| do | |
| id=`genID` | |
| etcdctl ls /vulcand/upstreams/$upstreamId/endpoints/$id | |
| done | |
| endpointId=$id | |
| etcdctl set /vulcand/upstreams/$upstreamId/endpoints/$endpointId http://$IP:$PORT | |
| # etcdctl ls /vulcand/hosts/$NAME/locations | |
| id=`genID` | |
| etcdctl ls /vulcand/hosts/$NAME/locations/$id | |
| while [[ $? != 4 ]] | |
| do | |
| id=`genID` | |
| etcdctl ls /vulcand/hosts/$NAME/locations/$id | |
| done | |
| locationId=$id | |
| etcdctl set /vulcand/hosts/$NAME/locations/$id/path "/.*" | |
| etcdctl set /vulcand/hosts/$NAME/locations/$id/upstream $upstreamId | |
| } | |
| function delHost() { | |
| if [[ -z $3 ]] | |
| then | |
| "delHost hostname ipaddress port" | |
| exit 1 | |
| fi | |
| NAME=${1}.local | |
| IP=$2 | |
| PORT=$3 | |
| echo remove host $NAME | |
| etcdctl ls /vulcand/hosts/$NAME | |
| [[ $? > 0 ]] || etcdctl mkdir /vulcand/hosts/$NAME # not exists | |
| etcdctl ls /vulcand/hosts/$NAME/locations/ | |
| [[ $? == 0 ]] && for i in $(etcdctl ls /vulcand/hosts/$NAME/locations/) | |
| do | |
| for j in $(etcdctl ls /vulcand/upstreams/$(etcdctl get $i/upstream)/endpoints/) | |
| do | |
| if [[ $(etcdctl get $j) == "http://$IP:$PORT" ]] | |
| then | |
| etcdctl rm $i/path # remove path | |
| etcdctl rm $i/upstream # remove upstream id from host's locations | |
| etcdctl rmdir $i # try to remove host's locations | |
| etcdctl rmdir $j # try to remove upstream's endpoints | |
| etcdctl rmdir $(dirname $j) # remove upstream id | |
| etcdctl rmdir $(dirname $i) # remove host locations | |
| etcdctl rmdir $(dirname $(dirname $j)) # remove upstream | |
| etcdctl rmdir $(dirname $(dirname $i)) # remove host | |
| return 0 | |
| fi | |
| done | |
| done | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment