From: Bastian Blank <waldi@debian.org>
To: xen-devel@lists.xen.org
Subject: [RFC] openvswitch support script
Date: Thu, 13 Sep 2012 10:33:02 +0200 [thread overview]
Message-ID: <20120913083302.GA27147@wavehammer.waldi.eu.org> (raw)
Hi
I wrote a vif script to support openvswitch. I use it on some of my
machines, so it works for non-qemu domains.
Ian asked me to send it here, maybe someone wants to take a look.
Bastian
#!/bin/bash
#============================================================================
# ${XEN_SCRIPT_DIR}/vif-openvswitch
#
# Script for configuring a vif in openvswitch mode.
# The hotplugging system will call this script if it is specified either in
# the device configuration given to Xend, or the default Xend configuration
# in ${XEN_CONFIG_DIR}/xend-config.sxp. If the script is specified in
# neither of those places, then this script is the default.
#
# Usage:
# vif-openvswitch (add|remove|online|offline)
#
# Environment vars:
# vif vif interface name (required).
# XENBUS_PATH path to this device's details in the XenStore (required).
#
# Read from the store:
# bridge openvswitch to add the vif to (required).
# ip list of IP networks for the vif, space-separated (optional).
#
# up:
# Enslaves the vif interface to the bridge and adds iptables rules
# for its ip addresses (if any).
#
# down:
# Removes the vif interface from the bridge and removes the iptables
# rules for its ip addresses (if any).
#============================================================================
dir=$(dirname "$0")
. "$dir/vif-common.sh"
openvswitch_external_id() {
local dev=$1
local key=$2
local value=$3
echo "-- set interface $dev external-ids:\"$key\"=\"$value\""
}
openvswitch_external_id_all() {
local dev=$1
local frontend_id=$(xenstore_read "$XENBUS_PATH/frontend-id")
local vm_path=$(xenstore_read "/local/domain/${frontend_id}/vm")
local name=$(xenstore_read "${vm_path}/name")
openvswitch_external_id $dev "xen-vm-name" "$name"
local uuid=$(xenstore_read "${vm_path}/uuid")
openvswitch_external_id $dev "xen-vm-uuid" "$uuid"
local mac=$(xenstore_read "$XENBUS_PATH/mac")
openvswitch_external_id $dev "attached-mac" "$mac"
}
add_to_openvswitch () {
local dev=$1
local bridge="$(xenstore_read_default "$XENBUS_PATH/bridge" "$bridge")"
local tag trunk
if [[ $bridge =~ ^([^.:]+)(\.([[:digit:]]+))?(:([[:digit:]]+(:[[:digit:]]+)*))?$ ]]; then
bridge="${BASH_REMATCH[1]}"
tag="${BASH_REMATCH[3]}"
trunk="${BASH_REMATCH[5]//:/,}"
else
fatal "No valid brdige was specified"
fi
if [ $trunk ]; then
local trunk_arg="trunk=$trunk"
fi
if [ $tag ]; then
local tag_arg="tag=$tag"
fi
local vif_details="$(openvswitch_external_id_all $dev)"
ovs-vsctl --timeout=30 -- --if-exists del-port $dev -- add-port "$bridge" $dev $tag_arg $trunk_arg $vif_details
ip link set $dev up
}
case "$command" in
add|online)
setup_virtual_bridge_port $dev
add_to_openvswitch $dev
;;
offline)
ovs-vsctl --timeout=30 -- --if-exists del-port $dev
;;
esac
if [ "$type_if" = vif ]; then
handle_iptable
fi
log debug "Successful vif-openvswitch $command for $dev."
if [ "$type_if" = vif -a "$command" = "online" ]; then
success
fi
--
Is truth not truth for all?
-- Natira, "For the World is Hollow and I have Touched
the Sky", stardate 5476.4.
reply other threads:[~2012-09-13 8:33 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120913083302.GA27147@wavehammer.waldi.eu.org \
--to=waldi@debian.org \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).