diff options
author | 2012-03-17 16:40:57 -0400 | |
---|---|---|
committer | 2012-03-17 16:44:44 -0400 | |
commit | eb70edb705d8456c43ebf52a5eae2d91b6b61ecd (patch) | |
tree | 2947a6a47c9faae6dbe65ae41d9fb8f6b5deac56 /qtap-manipulate | |
parent | initial commit of the init script, a sample config and Readme. (diff) | |
download | kvm-tools-eb70edb705d8456c43ebf52a5eae2d91b6b61ecd.tar.gz kvm-tools-eb70edb705d8456c43ebf52a5eae2d91b6b61ecd.tar.bz2 kvm-tools-eb70edb705d8456c43ebf52a5eae2d91b6b61ecd.zip |
Many small changes
Eliminate bashisms
Include missing qtap-manipulate script
Make indentation use tabs to match other scripts in Gentoo
Eliminate boot=on flag being removed from upstream QEMU
Switch from default binary from kvm to qemu-kvm
Diffstat (limited to 'qtap-manipulate')
-rwxr-xr-x | qtap-manipulate | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/qtap-manipulate b/qtap-manipulate new file mode 100755 index 0000000..b75c5ef --- /dev/null +++ b/qtap-manipulate @@ -0,0 +1,55 @@ +#!/bin/sh +[ -z "$1" ] || ( [ "$1" != "create" ] && [ -z "$2" ] ) && { echo "invalid usage, require create [device] || |destroy device"; exit 1; } + +#KVM_USER="kvm-envs" + +has() { + local desired=$1 x + shift + for x in "$@"; do + [ "$desired" = "$x" ] && return 0; + done + return 1 +} + +find_node() { + local val=$(ifconfig -a | grep -i ^qtap | cut -d ' ' -f1) + local pos=0 + while has qtap${pos} $val; do + pos=$(( $pos + 1 )) + done + echo qtap${pos} +} + +create_node() { + tunctl -b -u "${KVM_USER}" -t ${1} > /dev/null || { echo "tunctl failed"; exit 2; } + brctl addif br0 ${1} || { echo "brctl failed"; exit 2; } + ifconfig ${1} up 0.0.0.0 promisc || { echo "ifconfig failed"; exit 2; } +} + +destroy_node() { + issue= + ifconfig ${1} down || { echo "ifconfig failed";issue=1; } + brctl delif br0 ${1} || { echo "brctl failed";issue=2; } + tunctl -d ${1} > /dev/null || { echo "tunctl failed";issue=3;} + [ -n "${issue}" ] && exit -$(( $issue )) +} + +command=$1 +qtap=$2 + +if [ -z "$qtap" ]; then + qtap=$(find_node) +fi + +if [ "$command" = "create" ]; then + create_node "$qtap" + [ "$2" != "${qtap}" ] && echo "${qtap}" +elif [ "$command" = "destroy" ]; then + destroy_node "$qtap" +else + echo "$command isn't a valid command; must be create or destroy"; + exit 1 +fi + +exit 0 |