]>
Commit | Line | Data |
---|---|---|
1 | #! /bin/sh | |
2 | ||
3 | # Copyright (c) 2012, 2013 Nicira, Inc. | |
4 | # | |
5 | # Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | # you may not use this file except in compliance with the License. | |
7 | # You may obtain a copy of the License at: | |
8 | # | |
9 | # http://www.apache.org/licenses/LICENSE-2.0 | |
10 | # | |
11 | # Unless required by applicable law or agreed to in writing, software | |
12 | # distributed under the License is distributed on an "AS IS" BASIS, | |
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | # See the License for the specific language governing permissions and | |
15 | # limitations under the License. | |
16 | ||
17 | # Have a look at /usr/share/doc/openvswitch-switch/README.Debian | |
18 | # for more information about configuring the /etc/network/interfaces. | |
19 | ||
20 | if [ -z "${IF_OVS_TYPE}" ]; then | |
21 | exit 0 | |
22 | fi | |
23 | ||
24 | ovs_vsctl() { | |
25 | ovs-vsctl --timeout=5 "$@" | |
26 | } | |
27 | ||
28 | if (ovs_vsctl --version) > /dev/null 2>&1; then :; else | |
29 | exit 0 | |
30 | fi | |
31 | ||
32 | if /etc/init.d/openvswitch-switch status > /dev/null 2>&1; then :; else | |
33 | /etc/init.d/openvswitch-switch start | |
34 | fi | |
35 | ||
36 | if [ "${MODE}" = "start" ]; then | |
37 | eval OVS_EXTRA=\"${IF_OVS_EXTRA}\" | |
38 | ||
39 | case "${IF_OVS_TYPE}" in | |
40 | OVSBridge) | |
41 | ovs_vsctl -- --may-exist add-br "${IFACE}" ${IF_OVS_OPTIONS}\ | |
42 | ${OVS_EXTRA+-- $OVS_EXTRA} | |
43 | ||
44 | if [ ! -z "${IF_OVS_PORTS}" ]; then | |
45 | ifup --allow="${IFACE}" ${IF_OVS_PORTS} | |
46 | fi | |
47 | ;; | |
48 | OVSPort) | |
49 | ovs_vsctl -- --may-exist add-port "${IF_OVS_BRIDGE}"\ | |
50 | "${IFACE}" ${IF_OVS_OPTIONS} \ | |
51 | ${OVS_EXTRA+-- $OVS_EXTRA} | |
52 | ||
53 | ip link set "${IFACE}" up | |
54 | ;; | |
55 | OVSIntPort) | |
56 | ovs_vsctl -- --may-exist add-port "${IF_OVS_BRIDGE}"\ | |
57 | "${IFACE}" ${IF_OVS_OPTIONS} -- set Interface "${IFACE}"\ | |
58 | type=internal ${OVS_EXTRA+-- $OVS_EXTRA} | |
59 | ||
60 | ip link set "${IFACE}" up | |
61 | ;; | |
62 | OVSBond) | |
63 | ovs_vsctl -- --fake-iface add-bond "${IF_OVS_BRIDGE}"\ | |
64 | "${IFACE}" ${IF_OVS_BONDS} ${IF_OVS_OPTIONS} \ | |
65 | ${OVS_EXTRA+-- $OVS_EXTRA} | |
66 | ||
67 | ip link set "${IFACE}" up | |
68 | for slave in ${IF_OVS_BONDS} | |
69 | do | |
70 | ip link set "${IFACE}" up | |
71 | done | |
72 | ;; | |
73 | OVSPatchPort) | |
74 | ovs_vsctl -- --may-exist add-port "${IF_OVS_BRIDGE}"\ | |
75 | "${IFACE}" ${IF_OVS_OPTIONS} -- set Interface "${IFACE}" \ | |
76 | type=patch options:peer="${IF_OVS_PATCH_PEER}" \ | |
77 | ${OVS_EXTRA+-- $OVS_EXTRA} | |
78 | ;; | |
79 | OVSTunnel) | |
80 | ovs_vsctl -- --may-exist add-port "${IF_OVS_BRIDGE}"\ | |
81 | "${IFACE}" ${IF_OVS_OPTIONS} -- set Interface "${IFACE}" \ | |
82 | type=${IF_OVS_TUNNEL_TYPE} ${IF_OVS_TUNNEL_OPTIONS} \ | |
83 | ${OVS_EXTRA+-- $OVS_EXTRA} | |
84 | ;; | |
85 | *) | |
86 | exit 0 | |
87 | ;; | |
88 | esac | |
89 | elif [ "${MODE}" = "stop" ]; then | |
90 | case "${IF_OVS_TYPE}" in | |
91 | OVSBridge) | |
92 | if [ ! -z "${IF_OVS_PORTS}" ]; then | |
93 | ifdown --allow="${IFACE}" ${IF_OVS_PORTS} | |
94 | fi | |
95 | ||
96 | ovs_vsctl -- --if-exists del-br "${IFACE}" | |
97 | ;; | |
98 | OVSPort|OVSIntPort|OVSBond|OVSPatchPort|OVSTunnel) | |
99 | ovs_vsctl -- --if-exists del-port "${IF_OVS_BRIDGE}" "${IFACE}" | |
100 | ;; | |
101 | *) | |
102 | exit 0 | |
103 | ;; | |
104 | esac | |
105 | fi | |
106 | ||
107 | exit 0 |