]> git.pld-linux.org Git - packages/xen.git/blob - vif-openvswitch
- updated to 4.17.3
[packages/xen.git] / vif-openvswitch
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
25 dir=$(dirname "$0")
26 . "$dir/vif-common.sh"
27
28 bridge=${bridge:-}
29 bridge=$(xenstore_read_default "$XENBUS_PATH/bridge" "$bridge")
30
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"
35         fi
36 fi
37
38 tag=${tag:-}
39
40 # Domain on VLAN tagged bridge?
41 if ! 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
48 fi
49
50 if ! ovs-vsctl br-exists ${bridge}; then
51         fatal "Could not find bridge device ${bridge}"
52 fi
53
54 case "$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         ;;
67 esac
68
69 call_hooks vif post
70
71 if [ -z "${tag}" ]; then
72         log debug "Successful vif-openvswitch $command for ${vif}, bridge ${bridge}."
73 else
74         log debug "Successful vif-openvswitch $command for ${vif}, bridge ${bridge}, tag ${tag}."
75 fi
76
77 if [ "$command" == "online" ]; then
78         success
79 fi
This page took 0.068793 seconds and 3 git commands to generate.