-
Notifications
You must be signed in to change notification settings - Fork 3
/
vif-openvswitch
executable file
·85 lines (75 loc) · 2.08 KB
/
vif-openvswitch
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
#!/bin/bash
#============================================================================
# ${XEN_SCRIPT_DIR}/vif-openvswitch
#
# Script for configuring a vif using Open vSwitch.
#
# 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 bridge to add the vif to (optional). Defaults to searching for the
# bridge itself.
#
# up:
# Enslaves the vif interface to the bridge.
#
# down:
# Removes the vif interface from the bridge.
#============================================================================
dir=$(dirname "$0")
. "$dir/vif-common.sh"
bridge=${bridge:-}
bridge=$(xenstore_read_default "$XENBUS_PATH/bridge" "$bridge")
if [ -z "${bridge}" ]; then
bridge=$(ovs-vsctl list-br | head -n 1)
if [ -z "$bridge" ]; then
fatal "Could not find bridge, and none was specified"
fi
fi
tag=${tag:-}
# Domain on VLAN tagged bridge?
if ! ovs-vsctl br-exists ${bridge}; then
if [[ $bridge =~ \.[[:digit:]]{1,4}$ ]]; then
tag=${bridge##*.}
bridge=${bridge%.[0-9]*}
else
fatal "Could not find bridge device ${bridge}"
fi
fi
if ! ovs-vsctl br-exists ${bridge}; then
fatal "Could not find bridge device ${bridge}"
fi
case "$command" in
online|add)
ip link set dev "${vif}" up
ovs-vsctl --if-exists --with-iface del-port ${vif}
mtu="`ip link show $bridge | awk '/mtu/ { print $5 }'`"
if [ -n "$mtu" ] && [ "$mtu" -gt 0 ]
then
ip link set ${vif} mtu $mtu || :
fi
if [ -z $tag ]; then
ovs-vsctl -- --may-exist add-port ${bridge} ${vif}
else
ovs-vsctl -- --may-exist add-port ${bridge} ${vif} tag=${tag}
fi
;;
offline)
do_without_error ovs-vsctl -- --if-exists del-port ${bridge} ${vif}
do_without_error ip link set dev "${vif}" down
;;
esac
call_hooks vif post
if [ -z "${tag}" ]; then
log debug "Successful vif-openvswitch $command for ${vif}, bridge ${bridge}."
else
log debug "Successful vif-openvswitch $command for ${vif}, bridge ${bridge}, tag ${tag}."
fi
if [ "$command" == "online" ]; then
success
fi