]> git.pld-linux.org Git - packages/xen.git/blame - vif-openvswitch
- updated to 4.13.4
[packages/xen.git] / vif-openvswitch
CommitLineData
2ea512d8
JR
1#!/bin/bash
2#============================================================================
3# ${XEN_SCRIPT_DIR}/vif-openvswitch
4#
5# Script for configuring a vif using Open vSwitch.
6#
7# Usage:
8# vif-openvswitch (add|remove|online|offline)
9#
10# Environment vars:
11# vif vif interface name (required).
12# XENBUS_PATH path to this device's details in the XenStore (required).
13#
14# Read from the store:
15# bridge bridge to add the vif to (optional). Defaults to searching for the
16# bridge itself.
17#
18# up:
19# Enslaves the vif interface to the bridge.
20#
21# down:
22# Removes the vif interface from the bridge.
23#============================================================================
24
25dir=$(dirname "$0")
26. "$dir/vif-common.sh"
27
28bridge=${bridge:-}
29bridge=$(xenstore_read_default "$XENBUS_PATH/bridge" "$bridge")
30
31if [ -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"
35 fi
36fi
37
38tag=${tag:-}
39
40# Domain on VLAN tagged bridge?
41if ! ovs-vsctl br-exists ${bridge}; then
42 if [[ $bridge =~ \.[[:digit:]]{1,4}$ ]]; then
43 tag=${bridge##*.}
44 bridge=${bridge%.[0-9]*}
45 else
46 fatal "Could not find bridge device ${bridge}"
47 fi
48fi
49
50if ! ovs-vsctl br-exists ${bridge}; then
51 fatal "Could not find bridge device ${bridge}"
52fi
53
54case "$command" in
55 online|add)
56 ip link set dev "${vif}" up
57 if [ -z $tag ]; then
58 ovs-vsctl -- --may-exist add-port ${bridge} ${vif}
59 else
60 ovs-vsctl -- --may-exist add-port ${bridge} ${vif} tag=${tag}
61 fi
62 ;;
63 offline)
64 do_without_error ovs-vsctl -- --if-exists del-port ${bridge} ${vif}
65 do_without_error ip link set dev "${vif}" down
66 ;;
67esac
68
69call_hooks vif post
70
71if [ -z "${tag}" ]; then
72 log debug "Successful vif-openvswitch $command for ${vif}, bridge ${bridge}."
73else
74 log debug "Successful vif-openvswitch $command for ${vif}, bridge ${bridge}, tag ${tag}."
75fi
76
77if [ "$command" == "online" ]; then
78 success
79fi
This page took 0.12697 seconds and 4 git commands to generate.