#!/bin/bash
# invoke as invirt-remote-proxy-$TYPE, with "TYPE" in the remctl sense.

klist -s || kinit -k

TYPE="${0##*-}"
case "$TYPE" in
    control )
	MACHINE="$1"; SERVICE="$2"; shift; shift ;;
    * )
	SERVICE="$1"; shift ;;
esac

case "$TYPE/$SERVICE" in
    web/listvms )
	exec invirt-remote-listvms "$@" ;;
    web/vnccert )
        exec invirt-remote-vnccert "$@" ;;
    control/help )
        exec invirt-remctl-help ;;
    control/create|control/install )
	exec invirt-remote-create "$SERVICE" "$MACHINE" "$@" ;;
    control/listhost|control/list-host )
	exec invirt-remote-listhost "$MACHINE" "$@" ;;
    control/* )
	# Everything but create must go where the VM is already running.
	exec invirt-remote-control "$MACHINE" "$SERVICE" "$@" ;;
    * )
	exec remctl "$(invirt-getconf hosts.0.hostname)" remote "$TYPE" "$SERVICE" "$@" ;;
esac
