#!/usr/bin/env bash
# fake juju: status emits a fixture; ssh emits a ,DOWN, line iff the target unit == $HAPROXY_DOWN.
sub="${1:-}"
case "$sub" in
  whoami) echo "Controller:  juju-controller"; echo "Model:       ${FAKE_MODEL:-openstack}"; echo "User:        jessea123" ;;
  models) printf '{"models":[{"name":"admin/%s"}]}\n' "${FAKE_MODEL:-openstack}" ;;
  status) cat "${FIXTURE:?FIXTURE env not set}" ;;
  ssh)
    shift; unit=""
    while [ $# -gt 0 ]; do
      case "$1" in
        -m) shift 2; continue ;;
        --) shift; break ;;
        -*) shift; continue ;;
        *) unit="$1"; shift ;;
      esac
    done
    if [ -n "${HAPROXY_DOWN:-}" ] && [ "$unit" = "$HAPROXY_DOWN" ]; then
      echo "nova-api,nova-api-2-10-12-12-109,0,0,,0,,,,2,DOWN,1/1,..."
    fi
    ;;
  *) echo "fake juju: unhandled subcommand: $sub" >&2; exit 1 ;;
esac
