2 #============================================================================
3 # ${XEN_SCRIPT_DIR}/vif-openvswitch
5 # Script for configuring a vif using Open vSwitch.
8 # vif-openvswitch (add|remove|online|offline)
11 # vif vif interface name (required).
12 # XENBUS_PATH path to this device's details in the XenStore (required).
14 # Read from the store:
15 # bridge bridge to add the vif to (optional). Defaults to searching for the
19 # Enslaves the vif interface to the bridge.
22 # Removes the vif interface from the bridge.
23 #============================================================================
26 . "$dir/vif-common.sh"
29 bridge=$(xenstore_read_default "$XENBUS_PATH/bridge" "$bridge")
31 if [ -z "${bridge}" ]; then
32 bridge=$(ovs-vsctl list-br | head -n 1)
33 if [ -z "$bridge" ]; then
34 fatal "Could not find bridge, and none was specified"
40 # Domain on VLAN tagged bridge?
41 if ! ovs-vsctl br-exists ${bridge}; then
42 if [[ $bridge =~ \.[[:digit:]]{1,4}$ ]]; then
44 bridge=${bridge%.[0-9]*}
46 fatal "Could not find bridge device ${bridge}"
50 if ! ovs-vsctl br-exists ${bridge}; then
51 fatal "Could not find bridge device ${bridge}"
56 ip link set dev "${vif}" up
58 ovs-vsctl -- --may-exist add-port ${bridge} ${vif}
60 ovs-vsctl -- --may-exist add-port ${bridge} ${vif} tag=${tag}
64 do_without_error ovs-vsctl -- --if-exists del-port ${bridge} ${vif}
65 do_without_error ip link set dev "${vif}" down
71 if [ -z "${tag}" ]; then
72 log debug "Successful vif-openvswitch $command for ${vif}, bridge ${bridge}."
74 log debug "Successful vif-openvswitch $command for ${vif}, bridge ${bridge}, tag ${tag}."
77 if [ "$command" == "online" ]; then