Skip to content

Instantly share code, notes, and snippets.

@bjori
Last active September 28, 2015 17:39
Show Gist options
  • Save bjori/ccc8c3c3216f6e2c60c3 to your computer and use it in GitHub Desktop.
Save bjori/ccc8c3c3216f6e2c60c3 to your computer and use it in GitHub Desktop.
Use mongo-orchestration to launch relevant topology type to test against. Based on the mongo-c-driver .mci config file
#compdef mo
#autoload
# mo zsh completion
_mo() {
local curcontext="$curcontext" state line
local dir="/home/bjori/Sources/mongo-c-driver/orchestration_configs"
typeset -A opt_args
tops=`/bin/ls -1 $dir`
_arguments -s \
"1:Options:(--topology --noauth --auth)" \
"2:--topology:($tops)" \
"3:action:(--auth restart start stop)" \
"4:launch:(restart start stop)"
}
_mo "$@"
#!/usr/bin/env bash
ORCHESTRATION_ROOT="/home/bjori/Sources/mongo-c-driver/orchestration_configs"
log() {
if test $# -eq 2; then
echo -e "\033[37;44m$1 \033[0m ⮀ \033[42;30m $2\033[0m"
else
printf "\033[37;44m$@\033[0m\n"
fi
}
abort() {
printf "\033[31mError: $@\033[0m\n" && exit 1
}
topology_type=""
orchestration_file="basic.json";
while test $# -gt 0; do
case "$1" in
-h|--help)
log "Some help"
log "Some help" "That does stuff"
exit 0
;;
--topology)
shift
log "Configuring topology" "$1"
if test $# -gt 0; then
if test -d "$ORCHESTRATION_ROOT/$1"; then
topology_type=$1
else
abort "Cannot find topology for '$1' in $ORCHESTRATION_ROOT"
fi
else
abort "No topology provided."
fi
shift
;;
--noauth)
shift
log "Disabling authentication"
unset MONGOC_TEST_USER
unset MONGOC_TEST_PASSWORD
orchestration_file="basic.json"
;;
--auth)
shift
log "Enabling authentication"
export MONGOC_TEST_USER=bob
export MONGOC_TEST_PASSWORD=pwd123
log "Username" "$MONGOC_TEST_USER"
log "Password" "$MONGOC_TEST_PASSWORD"
orchestration_file="auth.json"
;;
stop)
shift
log "Stopping mongo-orchestration"
mongo-orchestration stop
;;
start)
shift
log "Starting mongo-orchestration"
mongo-orchestration -s wsgiref --socket-timeout-ms=60000 start
;;
restart)
shift
log "Restarting mongo-orchestration"
mongo-orchestration stop
mongo-orchestration -s wsgiref --socket-timeout-ms=60000 start
;;
*)
abort "Invalid argument '$1'"
shift
;;
esac
done
if test -n "${topology_type}"; then
log "Launching" "${topology_type}"
ORCHESTRATION_FILE="orchestration_configs/${topology_type}/${orchestration_file}"
ORCHESTRATION_URL="http://localhost:8889/v1/${topology_type}"
curl -s --data @"$ORCHESTRATION_FILE" "$ORCHESTRATION_URL"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment