Newer
Older
openstack-caracal-ipv4 / scripts / maas
@JANeumatrix JANeumatrix 6 hours ago 894 bytes Scripts update
#!/usr/bin/env bash
# fake maas: serves read endpoints from fixtures. `vlans read <fab>` is filtered by
# fabric_id and MIMICS REAL MAAS by erroring (non-JSON, non-zero) on an unknown/absent
# fabric id -- this is what tripped the live run when a placeholder id leaked through.
prof="${1:-}"; obj="${2:-}"; act="${3:-}"; fab="${4:-}"
case "$obj $act" in
  "subnets read")  cat "${FIX_SUBNETS:?}";  exit 0 ;;
  "spaces read")   cat "${FIX_SPACES:?}";   exit 0 ;;
  "ipranges read") cat "${FIX_IPRANGES:?}"; exit 0 ;;
  "fabrics read")  cat "${FIX_FABRICS:?}";  exit 0 ;;
  "vlans read")
    if jq -e --arg f "$fab" 'any(.[]; (.fabric_id|tostring)==$f)' "${FIX_VLANS:?}" >/dev/null 2>&1; then
      jq --arg f "$fab" '[.[]|select((.fabric_id|tostring)==$f)]' "${FIX_VLANS:?}"; exit 0
    fi
    echo "Unable to find fabric with id '$fab'." >&2; echo "Not Found"; exit 2 ;;
esac
echo "{}"; exit 0