-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathadd_virtio_channel.sh
executable file
·51 lines (46 loc) · 1.17 KB
/
add_virtio_channel.sh
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
#! /bin/bash
# Define virtio ports in some KVM virtual machine
#
# Usage: ./add_virtio_channel domain
virsh="virsh -c qemu:///system"
list=$($virsh list --all --name)
function usage
{
echo "Usage:"
echo " $0 <domain>"
echo
echo "Currently defined domains are:"
echo "$list" | sed 's/^/ /'
echo
exit 1
}
[ $# -eq 1 ] || usage
[ "$1" != "" ] || usage
[[ "$list" =~ "$1" ]] || usage
domain="$1"
function add_port
{
socket=/run/twopence/${domain}.sock
name=org.opensuse.twopence.0
grep -q "<target type='virtio' name='${name}'/>" $tmpfile
if [ $? -eq 0 ]; then
echo "Error: virtio port already exists in VM \"${domain}\""
echo
else
sed -i "/<devices>/ a\ \
<channel type='unix'>\n\
<source mode='bind' path='${socket}'/>\n\
<target type='virtio' name='${name}'/>\n\
</channel>" $tmpfile
echo "Virtio port added to VM \"${domain}\""
echo "Note: for a running VM, the changes will only be visible at next restart."
echo
fi
}
echo "Trying to add virtio ports to VM \"${domain}\"..."
echo
tmpfile=$(mktemp "/tmp/add_virtio_portsXXX.xml")
$virsh dumpxml $domain > $tmpfile
add_port
$virsh define $tmpfile > /dev/null
rm $tmpfile