aboutsummaryrefslogtreecommitdiffstats
path: root/xenstore-viewer.bash
blob: 1f1fc2003b75d1a15e8ec3d28865c1579d74dc50 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash
### Name: Simple XenStore Viewer
### Version: 1.2
### Release Date: 2012-08-17

function xenstoregetstatestr () {
    case "$1" in
        1)
            echo "Initializing"
            ;;
        2)
            echo "Waiting for initializing"
            ;;
        3)
            echo "Initialized"
            ;;
        4)
            echo "Connected"
            ;;
        5)
            echo "Closing"
            ;;
        6)
            echo "Closed"
            ;;
        *)
            echo "Unknown"
            ;;
    esac
}

function xenstoregetinfo () {
    case "$1" in
        m|h|'?'|'')
            echo " b Block device"
            echo " c Console"
            echo " n Network"
            echo " p Virtual CPUs"
            echo " r Memory"
            ;;
        b)
            vbdpath="$xenstorepath/device/vbd"
            for i in `xenstore-list $vbdpath`
            do
                echo "Virtual Device Name:              $i"
                echo "Virtual Device Type:              `xenstore-read $vbdpath/$i/device-type`"
                echo "Virtual Device State:             `xenstoregetstatestr $(xenstore-read $vbdpath/$i/state)`"
                vbdbackpath="`xenstore-read $vbdpath/$i/backend`"
                echo "Virtual Device Backend Name:      `xenstore-read $vbdbackpath/dev`"
                echo "Virtual Device Backend Type:      `xenstore-read $vbdbackpath/type`"
                echo "Virtual Device Backend Parameter: `xenstore-read $vbdbackpath/params`"
                echo -n "Other Information:                "
                case "`xenstore-read $vbdbackpath/online`" in
                    0)
                        echo -n "Offline"
                        ;;
                    1)
                        echo -n "Online"
                        ;;
                    *)
                        echo -n "Unknown"
                        ;;
                esac
                case "`xenstore-read $vbdbackpath/removable`" in
                    0)
                        echo -n ", Non-removable"
                        ;;
                    1)
                        echo -n ", Removable"
                        ;;
                    *)
                        echo -n ", Unknown"
                        ;;
                esac
                case "`xenstore-read $vbdbackpath/bootable`" in
                    0)
                        echo ", Non-bootable"
                        ;;
                    1)
                        echo ", Bootable"
                        ;;
                    *)
                        echo ", Unknown"
                        ;;
                esac
                echo ""
            done
            ;;
        c)
            conpath="$xenstorepath/console"
            echo "Xen Console Backend TTY:       `xenstore-read $conpath/tty`"
            echo "Xen Console Buffer Size Limit: `xenstore-read $conpath/limit`"
            echo "VNC Server Listen on:          `xenstore-read $conpath/vnc-listen`:`xenstore-read $conpath/vnc-port`"
            echo ""
            ;;
        n)
            vifpath="$xenstorepath/device/vif"
            for i in `xenstore-list $vifpath`
            do
                echo "Virtual Device Name:           $i"
                echo "Virtual Device State:          `xenstoregetstatestr $(xenstore-read $vifpath/$i/state)`"
                echo "Virtual Interface MAC Address: `xenstore-read $vifpath/$i/mac`"
                vifbackpath="`xenstore-read $vifpath/$i/backend`"
                echo "Bridge to:                     `xenstore-read $vifbackpath/bridge`"
                echo "Script used to create/stop:    `xenstore-read $vifbackpath/script`"
                echo ""
            done
            ;;
        p)
            cpupath="$xenstorepath/cpu"
            for i in `xenstore-list $cpupath`
            do
                echo "CPU $i: `xenstore-read $cpupath/$i/availability`"
            done
            ;;
        r)
            mempath="$xenstorepath/memory"
            echo "Memory Size:         `xenstore-read $mempath/target`"
            echo "Maximum Memory Size: `xenstore-read $mempath/static-max`"
            echo "Video Memory Size:   `xenstore-read $mempath/videoram`"
            ;;
        *)
            echo "Unrecognized command. Type m for help."
            echo "Use EOF (typically Control-D) to quit this script."
            ;;
    esac
}

[ "`id -u`" != "0" ] && echo "This script should be run as root." && exit 40

if [ -z "$1" ]
then
    read -p "Type a domain ID or domain name: " xendominput
else
    xendominput="$1"
fi

[ -z "$xendominput" ] && echo "Using default doamin 0" && xendominput=0

echo "Searching for domain $xendominput ..."

if xenstore-read /local/domain/$xendominput 1> /dev/null 2> /dev/null
then
    xenstorepath="/local/domain/$xendominput"
else
    for i in `xenstore-list /local/domain`
    do
        if [ "$xendominput" = "`xenstore-read /local/domain/$i/name 2> /dev/null`" ]
        then
            xenstorepath="/local/domain/$i"
            break
        fi
    done
fi

if [ -z "$xenstorepath" ]
then
    echo "Domain $xendominput not found." && exit 42
else
    echo "XenStore Path is $xenstorepath"
fi

if [ -z "$2" ]
then
    while read -p "XSView>>> " infocmdinput
    do
        xenstoregetinfo "$infocmdinput"
    done
else
    xenstoregetinfo "$2"
fi