1 # Spec file for Open vSwitch.
3 # Copyright (C) 2009, 2010, 2011 Nicira Networks, Inc.
5 # Copying and distribution of this file, with or without modification,
6 # are permitted in any medium without royalty provided the copyright
7 # notice and this notice are preserved. This file is offered as-is,
8 # without warranty of any kind.
10 # When building, the rpmbuild command line should define
11 # openvswitch_version, xen_version, and build_number using -D arguments.
14 # rpmbuild -D "openvswitch_version 0.8.9~1+build123" -D "xen_version 2.6.18-128.1.1.el5.xs5.1.0.483.1000xen" -D "build_number --with-build-number=123" -bb /usr/src/redhat/SPECS/openvswitch-xen.spec
16 %define version %{openvswitch_version}-%{xen_version}
18 # bump this when breaking compatibility with userspace
19 %define module_abi_version 0
21 # extract kernel type (xen or kdump)
22 %define binsuffix -%(echo '%{xen_version}' | sed -r 's/^.*[0-9]+//')
23 # kernel version string w/o kernel type
24 %define kernel_version %(echo '%{xen_version}' | sed -r 's/[a-z]+$//')
25 # build-supplemental-pack.sh requires this naming for kernel module packages
26 %define module_package modules%{binsuffix}-%{kernel_version}
29 Summary: Open vSwitch daemon/database/utilities
30 Group: System Environment/Daemons
31 URL: http://www.openvswitch.org/
32 Vendor: Nicira Networks, Inc.
33 Version: %{openvswitch_version}
37 Source: openvswitch-%{openvswitch_version}.tar.gz
38 Buildroot: /tmp/openvswitch-xen-rpm
39 Requires: openvswitch_mod.ko.%{module_abi_version}
42 Open vSwitch provides standard network bridging functions augmented with
43 support for the OpenFlow protocol for remote per-flow control of
46 %package %{module_package}
47 Summary: Open vSwitch kernel module
48 Group: System Environment/Kernel
50 Provides: %{name}-modules = %{kernel_version}, openvswitch_mod.ko.%{module_abi_version}
51 Requires: kernel%{binsuffix} = %{kernel_version}
53 %description %{module_package}
54 Open vSwitch Linux kernel module compiled against kernel version
58 %setup -q -n openvswitch-%{openvswitch_version}
61 ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=%{_localstatedir} --with-l26=/lib/modules/%{xen_version}/build --enable-ssl %{build_number}
65 rm -rf $RPM_BUILD_ROOT
66 make install DESTDIR=$RPM_BUILD_ROOT
67 install -d -m 755 $RPM_BUILD_ROOT/etc
68 install -d -m 755 $RPM_BUILD_ROOT/etc/init.d
69 install -m 755 xenserver/etc_init.d_openvswitch \
70 $RPM_BUILD_ROOT/etc/init.d/openvswitch
71 install -m 755 xenserver/etc_init.d_openvswitch-xapi-update \
72 $RPM_BUILD_ROOT/etc/init.d/openvswitch-xapi-update
73 install -d -m 755 $RPM_BUILD_ROOT/etc/sysconfig
74 install -d -m 755 $RPM_BUILD_ROOT/etc/logrotate.d
75 install -m 755 xenserver/etc_logrotate.d_openvswitch \
76 $RPM_BUILD_ROOT/etc/logrotate.d/openvswitch
77 install -d -m 755 $RPM_BUILD_ROOT/etc/profile.d
78 install -m 755 xenserver/etc_profile.d_openvswitch.sh \
79 $RPM_BUILD_ROOT/etc/profile.d/openvswitch.sh
80 install -d -m 755 $RPM_BUILD_ROOT/etc/xapi.d/plugins
81 install -m 755 xenserver/etc_xapi.d_plugins_openvswitch-cfg-update \
82 $RPM_BUILD_ROOT/etc/xapi.d/plugins/openvswitch-cfg-update
83 install -d -m 755 $RPM_BUILD_ROOT/etc/xensource/bugtool/network-status
84 install -m 644 xenserver/etc_xensource_bugtool_network-status_openvswitch.xml \
85 $RPM_BUILD_ROOT/etc/xensource/bugtool/network-status/openvswitch.xml
86 install -d -m 755 $RPM_BUILD_ROOT/etc/xensource/bugtool/kernel-info
87 install -m 644 xenserver/etc_xensource_bugtool_kernel-info_openvswitch.xml \
88 $RPM_BUILD_ROOT/etc/xensource/bugtool/kernel-info/openvswitch.xml
89 install -d -m 755 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts
90 install -m 644 vswitchd/vswitch.ovsschema \
91 $RPM_BUILD_ROOT/usr/share/openvswitch/vswitch.ovsschema
92 install -m 755 xenserver/opt_xensource_libexec_interface-reconfigure \
93 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/interface-reconfigure
94 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigure.py \
95 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigure.py
96 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureBridge.py \
97 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
98 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py \
99 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
100 install -m 755 xenserver/etc_xensource_scripts_vif \
101 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/vif
102 install -m 755 xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync \
103 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/ovs-xapi-sync
104 install -m 755 xenserver/usr_share_openvswitch_scripts_sysconfig.template \
105 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/sysconfig.template
106 install -m 755 xenserver/usr_share_openvswitch_scripts_xen-bugtool-tc-class-show \
107 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/xen-bugtool-tc-class-show
108 install -m 755 utilities/ovs-save \
109 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/ovs-save
110 install -d -m 755 $RPM_BUILD_ROOT/usr/lib/xsconsole/plugins-base
112 xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py \
113 $RPM_BUILD_ROOT/usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
115 install -d -m 755 $RPM_BUILD_ROOT/lib/modules/%{xen_version}/extra/openvswitch
116 find datapath/linux-2.6 -name *.ko -exec install -m 755 \{\} $RPM_BUILD_ROOT/lib/modules/%{xen_version}/extra/openvswitch \;
117 install xenserver/uuid.py $RPM_BUILD_ROOT/usr/share/openvswitch/python
119 # Get rid of stuff we don't want to make RPM happy.
121 $RPM_BUILD_ROOT/usr/bin/ovs-controller \
122 $RPM_BUILD_ROOT/usr/bin/ovs-openflowd \
123 $RPM_BUILD_ROOT/usr/bin/ovs-pki \
124 $RPM_BUILD_ROOT/usr/share/man/man8/ovs-controller.8 \
125 $RPM_BUILD_ROOT/usr/share/man/man8/ovs-openflowd.8 \
126 $RPM_BUILD_ROOT/usr/share/man/man8/ovs-pki.8
128 install -d -m 755 $RPM_BUILD_ROOT/var/lib/openvswitch
131 rm -rf $RPM_BUILD_ROOT
134 if grep -F net.ipv4.conf.all.arp_filter /etc/sysctl.conf >/dev/null 2>&1; then :; else
135 cat >>/etc/sysctl.conf <<EOF
136 # This works around an issue in xhad, which binds to a particular
137 # Ethernet device, which in turn causes ICMP port unreachable messages
138 # if packets are received are on the wrong interface, which in turn
139 # can happen if we send out ARP replies on every interface (as Linux
140 # does by default) instead of just on the interface that has the IP
141 # address being ARPed for, which this sysctl setting in turn works
145 net.ipv4.conf.all.arp_filter = 1
149 if test ! -e /etc/openvswitch/conf.db; then
150 install -d -m 755 -o root -g root /etc/openvswitch
152 # Create ovs-vswitchd config database
153 ovsdb-tool -vANY:console:emer create /etc/openvswitch/conf.db \
154 /usr/share/openvswitch/vswitch.ovsschema
156 # Create initial table in config database
157 ovsdb-tool -vANY:console:emer transact /etc/openvswitch/conf.db \
158 '[{"op": "insert", "table": "Open_vSwitch", "row": {}}]' \
162 # Create default or update existing /etc/sysconfig/openvswitch.
163 SYSCONFIG=/etc/sysconfig/openvswitch
164 TEMPLATE=/usr/share/openvswitch/scripts/sysconfig.template
165 if [ ! -e $SYSCONFIG ]; then
166 cp $TEMPLATE $SYSCONFIG
168 for var in $(awk -F'[ :]' '/^# [_A-Z0-9]+:/{print $2}' $TEMPLATE)
170 if ! grep $var $SYSCONFIG >/dev/null 2>&1; then
172 sed -n "/$var:/,/$var=/p" $TEMPLATE >> $SYSCONFIG
177 # Deliberately break %postun in broken OVS builds that revert original
178 # XenServer scripts during rpm -U by moving the directory where it thinks
180 if [ -d /usr/lib/openvswitch/xs-original ]; then
181 mkdir -p /usr/lib/openvswitch/xs-saved
182 mv /usr/lib/openvswitch/xs-original/* /usr/lib/openvswitch/xs-saved/ &&
183 rmdir /usr/lib/openvswitch/xs-original
186 # Replace XenServer files by our versions.
187 mkdir -p /usr/lib/openvswitch/xs-saved \
188 || printf "Could not create script backup directory.\n"
190 /opt/xensource/libexec/interface-reconfigure \
191 /opt/xensource/libexec/InterfaceReconfigure.py \
192 /opt/xensource/libexec/InterfaceReconfigureBridge.py \
193 /opt/xensource/libexec/InterfaceReconfigureVswitch.py \
194 /etc/xensource/scripts/vif
198 if [ -f "$f" ] && [ "$t" != "/usr/share/openvswitch/scripts/$s" ]; then
199 mv "$f" /usr/lib/openvswitch/xs-saved/ \
200 || printf "Could not save original XenServer $s script\n"
201 ln -s "/usr/share/openvswitch/scripts/$s" "$f" \
202 || printf "Could not link to Open vSwitch $s script\n"
206 # Clean up dangling symlinks to removed OVS replacement scripts no longer
207 # provided by OVS. Any time a replacement script is removed from OVS,
208 # it should be added here to ensure correct reversion from old versions of
209 # OVS that don't clean up dangling symlinks during the uninstall phase.
212 /usr/sbin/xen-bugtool
214 saved=/usr/lib/openvswitch/xs-saved/$(basename "$orig")
215 [ -e "$saved" ] && mv -f "$saved" "$orig"
218 # Ensure all required services are set to run
219 for s in openvswitch openvswitch-xapi-update; do
220 if chkconfig --list $s >/dev/null 2>&1; then
221 chkconfig --del $s || printf "Could not remove $s init script."
223 chkconfig --add $s || printf "Could not add $s init script."
224 chkconfig $s on || printf "Could not enable $s init script."
227 if [ "$1" = "1" ]; then # $1 = 2 for upgrade
228 # Configure system to use Open vSwitch
229 echo vswitch > /etc/xensource/network.conf
231 printf "\nYou MUST reboot the server NOW to complete the change to\n"
232 printf "Open vSwitch. Attempts to modify networking on the server\n"
233 printf "or any hosted VM will fail until after the reboot and could\n"
234 printf "leave the server in a state requiring manual recovery.\n\n"
237 mode=$(cat /etc/xensource/network.conf)
238 if [ "$mode" != "vswitch" ] && [ "$mode" != "openvswitch" ]; then
239 printf "\nThe server is not configured to run Open vSwitch. To run in\n"
240 printf "vswitch mode, you must run the following command:\n\n"
241 printf "\txe-switch-network-backend vswitch"
243 printf "\nTo use the new Open vSwitch install, you should reboot the\n"
244 printf "server now. Failure to do so may result in incorrect operation."
250 %post %{module_package}
251 # Ensure that modprobe will find our modules.
252 depmod %{xen_version}
255 if [ "$1" = "0" ]; then # $1 = 1 for upgrade
256 for s in openvswitch openvswitch-xapi-update; do
257 chkconfig --del $s || printf "Could not remove $s init script."
262 # Restore original XenServer scripts if the OVS equivalent no longer exists.
263 # This works both in the upgrade and erase cases.
264 # This lists every file that every version of OVS has ever replaced. Never
265 # remove old files that OVS no longer replaces, or upgrades from old versions
266 # will fail to restore the XS originals, leaving the system in a broken state.
267 # Also be sure to add removed script paths to the %post scriptlet above to
268 # prevent the same problem when upgrading from old versions of OVS that lack
269 # this restore-on-upgrade logic.
271 /etc/xensource/scripts/vif \
273 /usr/sbin/xen-bugtool \
274 /opt/xensource/libexec/interface-reconfigure \
275 /opt/xensource/libexec/InterfaceReconfigure.py \
276 /opt/xensource/libexec/InterfaceReconfigureBridge.py \
277 /opt/xensource/libexec/InterfaceReconfigureVswitch.py
279 # Only revert dangling symlinks.
280 if [ -h "$f" ] && [ ! -e "$f" ]; then
282 if [ ! -f "/usr/lib/openvswitch/xs-saved/$s" ]; then
283 printf "Original XenServer $s script not present in /usr/lib/openvswitch/xs-saved\n" >&2
284 printf "Could not restore original XenServer script.\n" >&2
287 && mv "/usr/lib/openvswitch/xs-saved/$s" "$f") \
288 || printf "Could not restore original XenServer $s script.\n" >&2
293 if [ "$1" = "0" ]; then # $1 = 1 for upgrade
294 rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
295 /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo
297 rm -f /usr/share/openvswitch/scripts/InterfaceReconfigure.pyc \
298 /usr/share/openvswitch/scripts/InterfaceReconfigure.pyo \
299 /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyc \
300 /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyo \
301 /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyc \
302 /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyo
304 # Remove all configuration files
305 rm -f /etc/openvswitch/conf.db
306 rm -f /etc/sysconfig/openvswitch
307 rm -f /etc/openvswitch/vswitchd.cacert
309 # Remove saved XenServer scripts directory, but only if it's empty
310 rmdir -p /usr/lib/openvswitch/xs-saved 2>/dev/null
312 # Configure system to use bridge
313 echo bridge > /etc/xensource/network.conf
315 printf "\nYou MUST reboot the server now to complete the change to\n"
316 printf "standard Xen networking. Attempts to modify networking on the\n"
317 printf "server or any hosted VM will fail until after the reboot and\n"
318 printf "could leave the server in a state requiring manual recovery.\n\n"
322 %defattr(-,root,root)
323 /etc/init.d/openvswitch
324 /etc/init.d/openvswitch-xapi-update
325 /etc/xapi.d/plugins/openvswitch-cfg-update
326 /etc/xensource/bugtool/network-status/openvswitch.xml
327 /etc/xensource/bugtool/kernel-info/openvswitch.xml
328 /etc/logrotate.d/openvswitch
329 /etc/profile.d/openvswitch.sh
330 /usr/share/openvswitch/python/ovs/__init__.py
331 /usr/share/openvswitch/python/ovs/daemon.py
332 /usr/share/openvswitch/python/ovs/db/__init__.py
333 /usr/share/openvswitch/python/ovs/db/data.py
334 /usr/share/openvswitch/python/ovs/db/error.py
335 /usr/share/openvswitch/python/ovs/db/idl.py
336 /usr/share/openvswitch/python/ovs/db/parser.py
337 /usr/share/openvswitch/python/ovs/db/schema.py
338 /usr/share/openvswitch/python/ovs/db/types.py
339 /usr/share/openvswitch/python/ovs/dirs.py
340 /usr/share/openvswitch/python/ovs/fatal_signal.py
341 /usr/share/openvswitch/python/ovs/json.py
342 /usr/share/openvswitch/python/ovs/jsonrpc.py
343 /usr/share/openvswitch/python/ovs/ovsuuid.py
344 /usr/share/openvswitch/python/ovs/poller.py
345 /usr/share/openvswitch/python/ovs/process.py
346 /usr/share/openvswitch/python/ovs/reconnect.py
347 /usr/share/openvswitch/python/ovs/socket_util.py
348 /usr/share/openvswitch/python/ovs/stream.py
349 /usr/share/openvswitch/python/ovs/timeval.py
350 /usr/share/openvswitch/python/ovs/util.py
351 /usr/share/openvswitch/python/uuid.py
352 /usr/share/openvswitch/scripts/ovs-xapi-sync
353 /usr/share/openvswitch/scripts/interface-reconfigure
354 /usr/share/openvswitch/scripts/InterfaceReconfigure.py
355 /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
356 /usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
357 /usr/share/openvswitch/scripts/vif
358 /usr/share/openvswitch/scripts/sysconfig.template
359 /usr/share/openvswitch/scripts/xen-bugtool-tc-class-show
360 /usr/share/openvswitch/scripts/ovs-save
361 /usr/share/openvswitch/vswitch.ovsschema
362 /usr/sbin/ovs-vlan-bug-workaround
363 /usr/sbin/ovs-vswitchd
364 /usr/sbin/ovsdb-server
369 /usr/bin/ovs-tcpundump
370 /usr/bin/ovs-vlan-test
372 /usr/bin/ovsdb-client
374 /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
375 /usr/share/man/man1/ovsdb-client.1.gz
376 /usr/share/man/man1/ovsdb-server.1.gz
377 /usr/share/man/man1/ovsdb-tool.1.gz
378 /usr/share/man/man5/ovs-vswitchd.conf.db.5.gz
379 /usr/share/man/man8/ovs-appctl.8.gz
380 /usr/share/man/man8/ovs-dpctl.8.gz
381 /usr/share/man/man8/ovs-ofctl.8.gz
382 /usr/share/man/man8/ovs-parse-leaks.8.gz
383 /usr/share/man/man1/ovs-pcap.1.gz
384 /usr/share/man/man1/ovs-tcpundump.1.gz
385 /usr/share/man/man8/ovs-vlan-bug-workaround.8.gz
386 /usr/share/man/man8/ovs-vlan-test.8.gz
387 /usr/share/man/man8/ovs-vsctl.8.gz
388 /usr/share/man/man8/ovs-vswitchd.8.gz
390 %exclude /usr/lib/xsconsole/plugins-base/*.py[co]
391 %exclude /usr/sbin/ovs-brcompatd
392 %exclude /usr/share/man/man8/ovs-brcompatd.8.gz
393 %exclude /usr/share/openvswitch/scripts/*.py[co]
394 %exclude /usr/share/openvswitch/python/*.py[co]
395 %exclude /usr/share/openvswitch/python/ovs/*.py[co]
396 %exclude /usr/share/openvswitch/python/ovs/db/*.py[co]
398 %files %{module_package}
399 /lib/modules/%{xen_version}/extra/openvswitch/openvswitch_mod.ko
400 %exclude /lib/modules/%{xen_version}/extra/openvswitch/brcompat_mod.ko