Fix XVM's classic networking problem.
[invirt/packages/invirt-remote.git] / host / usr / sbin / invirt-vmcontrol
1 #!/bin/bash
2 # invirt-vmcontrol MACHINE ACTION
3 #
4 # remctl should have already verified that the user is authorized to
5 # control the machine.  So, we just need to execute the action requested.
6 #
7 # $0 and $1 come from the trusted remctl source.
8 #
9 # $2 and so on are user-provided, and thus sketchy.
10
11 ORIGMACHINE="$1"
12 ACTION="$2"
13 MACHINE="d_$ORIGMACHINE"
14
15 case "$ACTION" in
16     list|vcpu-list|uptime)
17         xm "$ACTION" "$MACHINE"
18         ;;
19     destroy|shutdown|reboot)
20         xm "$ACTION" "$MACHINE"
21         /usr/sbin/invirt-update-conserver </dev/null >/dev/null 2>&1 &
22         ;;
23     install|create)
24         shift; shift;
25         if [ -f "/etc/invirt/nocreate" ]; then
26                 echo "Host $HOSTNAME is currently refusing VM creation." && exit 2
27         fi
28         xm list "$MACHINE" >/dev/null 2>/dev/null && echo "$MACHINE already exists" && exit 1
29         if [ "$ACTION" = "install" ]; then
30             xm create invirt-database machine_name="$ORIGMACHINE" installer_options="$(printf '%q ' "$@")"
31         elif [ -n "$1" ]; then
32             xm create invirt-database machine_name="$ORIGMACHINE" cdrom_image="$1"
33         else
34             xm create invirt-database machine_name="$ORIGMACHINE"
35         fi
36         (sleep 4; /usr/sbin/invirt-update-conserver) </dev/null >/dev/null 2>&1 &
37         ;;
38     list-long)
39         xm list --long "$MACHINE"
40         ;;
41     vnctoken)
42         invirt-vnc-authtoken "$ORIGMACHINE"
43         ;;
44     arp)
45         iface=`invirt-getconf xen.iface`
46         xs_prefix="/local/domain/0/backend/vif"
47         domid=`xm domid $MACHINE`
48         for vif in `xenstore-list $xs_prefix/$domid`; do
49             ip=`xenstore-read $xs_prefix/$domid/$vif/ip`
50             script=`xenstore-read $xs_prefix/$domid/$vif/script`
51             gw=`echo $script | sed -ne 's/.* gateway=\([0-9\.]*\).*/\1/p'`
52             oip=`echo $script | sed -ne 's/.* other_ip=\([0-9\.]*\).*/\1/p'`
53             ogw=`echo $script | sed -ne 's/.* other_gateway=\([0-9\.]*\).*/\1/p'`
54             timeout -s KILL 5 /usr/sbin/arpspoof -i $iface -t $gw $ip
55             if [ -n "$oip" ]; then
56                 timeout -s KILL 5 /usr/sbin/arpspoof -i $iface -t $ogw $oip
57             fi
58         done
59         ;;
60     *)
61         echo "ERROR: Invalid Command"
62         exit 34
63         ;;
64 esac