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}
19 Summary: Virtual switch
20 Group: System Environment/Daemons
21 URL: http://www.openvswitch.org/
22 Vendor: Nicira Networks, Inc.
23 Version: %{openvswitch_version}
25 # The entire source code is ASL 2.0 except datapath/ which is GPLv2
26 License: ASL 2.0 and GPLv2
28 Source: openvswitch-%{openvswitch_version}.tar.gz
29 Buildroot: /tmp/openvswitch-xen-rpm
30 Requires: kernel-xen = %(echo '%{xen_version}' | sed 's/xen$//')
33 Open vSwitch provides standard network bridging functions augmented with
34 support for the OpenFlow protocol for remote per-flow control of
38 %setup -q -n openvswitch-%{openvswitch_version}
41 ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=%{_localstatedir} --with-l26=/lib/modules/%{xen_version}/build --enable-ssl %{build_number}
45 rm -rf $RPM_BUILD_ROOT
46 make install DESTDIR=$RPM_BUILD_ROOT
47 install -d -m 755 $RPM_BUILD_ROOT/etc
48 install -d -m 755 $RPM_BUILD_ROOT/etc/init.d
49 install -m 755 xenserver/etc_init.d_openvswitch \
50 $RPM_BUILD_ROOT/etc/init.d/openvswitch
51 install -m 755 xenserver/etc_init.d_openvswitch-xapi-update \
52 $RPM_BUILD_ROOT/etc/init.d/openvswitch-xapi-update
53 install -d -m 755 $RPM_BUILD_ROOT/etc/sysconfig
54 install -d -m 755 $RPM_BUILD_ROOT/etc/logrotate.d
55 install -m 755 xenserver/etc_logrotate.d_openvswitch \
56 $RPM_BUILD_ROOT/etc/logrotate.d/openvswitch
57 install -d -m 755 $RPM_BUILD_ROOT/etc/profile.d
58 install -m 755 xenserver/etc_profile.d_openvswitch.sh \
59 $RPM_BUILD_ROOT/etc/profile.d/openvswitch.sh
60 install -d -m 755 $RPM_BUILD_ROOT/etc/xapi.d/plugins
61 install -m 755 xenserver/etc_xapi.d_plugins_openvswitch-cfg-update \
62 $RPM_BUILD_ROOT/etc/xapi.d/plugins/openvswitch-cfg-update
63 install -d -m 755 $RPM_BUILD_ROOT/etc/xensource/bugtool/network-status
64 install -m 644 xenserver/etc_xensource_bugtool_network-status_openvswitch.xml \
65 $RPM_BUILD_ROOT/etc/xensource/bugtool/network-status/openvswitch.xml
66 install -d -m 755 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts
67 install -m 644 vswitchd/vswitch.ovsschema \
68 $RPM_BUILD_ROOT/usr/share/openvswitch/vswitch.ovsschema
69 install -m 755 xenserver/opt_xensource_libexec_interface-reconfigure \
70 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/interface-reconfigure
71 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigure.py \
72 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigure.py
73 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureBridge.py \
74 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
75 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py \
76 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
77 install -m 755 xenserver/etc_xensource_scripts_vif \
78 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/vif
79 install -m 755 xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync \
80 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/ovs-xapi-sync
81 install -m 755 xenserver/usr_share_openvswitch_scripts_sysconfig.template \
82 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/sysconfig.template
83 install -m 755 xenserver/usr_share_openvswitch_scripts_xen-bugtool-tc-class-show \
84 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/xen-bugtool-tc-class-show
85 install -m 755 utilities/ovs-save \
86 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/ovs-save
87 install -d -m 755 $RPM_BUILD_ROOT/usr/lib/xsconsole/plugins-base
89 xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py \
90 $RPM_BUILD_ROOT/usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
92 install -d -m 755 $RPM_BUILD_ROOT/lib/modules/%{xen_version}/kernel/extra/openvswitch
93 find datapath/linux-2.6 -name *.ko -exec install -m 755 \{\} $RPM_BUILD_ROOT/lib/modules/%{xen_version}/kernel/extra/openvswitch \;
94 install xenserver/uuid.py $RPM_BUILD_ROOT/usr/share/openvswitch/python
96 # Get rid of stuff we don't want to make RPM happy.
98 $RPM_BUILD_ROOT/usr/bin/ovs-controller \
99 $RPM_BUILD_ROOT/usr/bin/ovs-discover \
100 $RPM_BUILD_ROOT/usr/bin/ovs-kill \
101 $RPM_BUILD_ROOT/usr/bin/ovs-openflowd \
102 $RPM_BUILD_ROOT/usr/bin/ovs-pki \
103 $RPM_BUILD_ROOT/usr/share/man/man8/ovs-controller.8 \
104 $RPM_BUILD_ROOT/usr/share/man/man8/ovs-discover.8 \
105 $RPM_BUILD_ROOT/usr/share/man/man8/ovs-kill.8 \
106 $RPM_BUILD_ROOT/usr/share/man/man8/ovs-openflowd.8 \
107 $RPM_BUILD_ROOT/usr/share/man/man8/ovs-pki.8
109 install -d -m 755 $RPM_BUILD_ROOT/var/lib/openvswitch
112 rm -rf $RPM_BUILD_ROOT
115 # Do not run the first block if we are in the XenServer installer
116 if runlevel >/dev/null 2>&1; then
117 if test ! -e /var/xapi/network.dbcache; then
118 if test "$1" = 1; then
119 printf "Creating xapi database cache... "
121 printf "warning: Open vSwitch is being re-installed or upgraded,\n"
122 printf " but the xapi database cache is missing.\n"
123 printf "Re-creating xapi database cache... "
126 if /usr/share/openvswitch/scripts/interface-reconfigure rewrite; then
130 printf "Open vSwitch can only be installed on a XenServer that\n"
131 printf "has connectivity to xapi on the pool master. Please\n"
132 printf "fix connectivity to the pool master, then try again.\n"
138 # Ensure that modprobe will find our modules.
139 depmod %{xen_version}
141 if grep -F net.ipv4.conf.all.arp_filter /etc/sysctl.conf >/dev/null 2>&1; then :; else
142 cat >>/etc/sysctl.conf <<EOF
143 # This works around an issue in xhad, which binds to a particular
144 # Ethernet device, which in turn causes ICMP port unreachable messages
145 # if packets are received are on the wrong interface, which in turn
146 # can happen if we send out ARP replies on every interface (as Linux
147 # does by default) instead of just on the interface that has the IP
148 # address being ARPed for, which this sysctl setting in turn works
152 net.ipv4.conf.all.arp_filter = 1
156 if test ! -e /etc/openvswitch/conf.db; then
157 install -d -m 755 -o root -g root /etc/openvswitch
159 # Create ovs-vswitchd config database
160 ovsdb-tool -vANY:console:emer create /etc/openvswitch/conf.db \
161 /usr/share/openvswitch/vswitch.ovsschema
163 # Create initial table in config database
164 ovsdb-tool -vANY:console:emer transact /etc/openvswitch/conf.db \
165 '[{"op": "insert", "table": "Open_vSwitch", "row": {}}]' \
169 # Create default or update existing /etc/sysconfig/openvswitch.
170 SYSCONFIG=/etc/sysconfig/openvswitch
171 TEMPLATE=/usr/share/openvswitch/scripts/sysconfig.template
172 if [ ! -e $SYSCONFIG ]; then
173 cp $TEMPLATE $SYSCONFIG
175 for var in $(awk -F'[ :]' '/^# [_A-Z0-9]+:/{print $2}' $TEMPLATE)
177 if ! grep $var $SYSCONFIG >/dev/null 2>&1; then
179 sed -n "/$var:/,/$var=/p" $TEMPLATE >> $SYSCONFIG
184 # Deliberately break %postun in broken OVS builds that revert original
185 # XenServer scripts during rpm -U by moving the directory where it thinks
187 if [ -d /usr/lib/openvswitch/xs-original ]; then
188 mkdir -p /usr/lib/openvswitch/xs-saved
189 mv /usr/lib/openvswitch/xs-original/* /usr/lib/openvswitch/xs-saved/ &&
190 rmdir /usr/lib/openvswitch/xs-original
193 # Replace XenServer files by our versions.
194 mkdir -p /usr/lib/openvswitch/xs-saved \
195 || printf "Could not create script backup directory.\n"
197 /opt/xensource/libexec/interface-reconfigure \
198 /opt/xensource/libexec/InterfaceReconfigure.py \
199 /opt/xensource/libexec/InterfaceReconfigureBridge.py \
200 /opt/xensource/libexec/InterfaceReconfigureVswitch.py \
201 /etc/xensource/scripts/vif
205 if [ -f "$f" ] && [ "$t" != "/usr/share/openvswitch/scripts/$s" ]; then
206 mv "$f" /usr/lib/openvswitch/xs-saved/ \
207 || printf "Could not save original XenServer $s script\n"
208 ln -s "/usr/share/openvswitch/scripts/$s" "$f" \
209 || printf "Could not link to Open vSwitch $s script\n"
213 # Clean up dangling symlinks to removed OVS replacement scripts no longer
214 # provided by OVS. Any time a replacement script is removed from OVS,
215 # it should be added here to ensure correct reversion from old versions of
216 # OVS that don't clean up dangling symlinks during the uninstall phase.
219 /usr/sbin/xen-bugtool
221 saved=/usr/lib/openvswitch/xs-saved/$(basename "$orig")
222 [ -e "$saved" ] && mv -f "$saved" "$orig"
225 # Ensure all required services are set to run
226 for s in openvswitch openvswitch-xapi-update; do
227 if chkconfig --list $s >/dev/null 2>&1; then
228 chkconfig --del $s || printf "Could not remove $s init script."
230 chkconfig --add $s || printf "Could not add $s init script."
231 chkconfig $s on || printf "Could not enable $s init script."
234 # Configure system to use Open vSwitch
235 echo vswitch > /etc/xensource/network.conf
237 if [ "$1" = "1" ]; then # $1 = 2 for upgrade
238 printf "\nYou MUST reboot the server NOW to complete the change to\n"
239 printf "Open vSwitch. Attempts to modify networking on the server\n"
240 printf "or any hosted VM will fail until after the reboot and could\n"
241 printf "leave the server in an state requiring manual recovery.\n\n"
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."
249 if [ "$1" = "0" ]; then # $1 = 1 for upgrade
250 for s in openvswitch openvswitch-xapi-update; do
251 chkconfig --del $s || printf "Could not remove $s init script."
257 # Restore original XenServer scripts if the OVS equivalent no longer exists.
258 # This works both in the upgrade and erase cases.
259 # This lists every file that every version of OVS has ever replaced. Never
260 # remove old files that OVS no longer replaces, or upgrades from old versions
261 # will fail to restore the XS originals, leaving the system in a broken state.
262 # Also be sure to add removed script paths to the %post scriptlet above to
263 # prevent the same problem when upgrading from old versions of OVS that lack
264 # this restore-on-upgrade logic.
266 /etc/xensource/scripts/vif \
268 /usr/sbin/xen-bugtool \
269 /opt/xensource/libexec/interface-reconfigure \
270 /opt/xensource/libexec/InterfaceReconfigure.py \
271 /opt/xensource/libexec/InterfaceReconfigureBridge.py \
272 /opt/xensource/libexec/InterfaceReconfigureVswitch.py
274 # Only revert dangling symlinks.
275 if [ -h "$f" ] && [ ! -e "$f" ]; then
277 if [ ! -f "/usr/lib/openvswitch/xs-saved/$s" ]; then
278 printf "Original XenServer $s script not present in /usr/lib/openvswitch/xs-saved\n" >&2
279 printf "Could not restore original XenServer script.\n" >&2
282 && mv "/usr/lib/openvswitch/xs-saved/$s" "$f") \
283 || printf "Could not restore original XenServer $s script.\n" >&2
288 if [ "$1" = "0" ]; then # $1 = 1 for upgrade
289 rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
290 /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo
292 rm -f /usr/share/openvswitch/scripts/InterfaceReconfigure.pyc \
293 /usr/share/openvswitch/scripts/InterfaceReconfigure.pyo \
294 /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyc \
295 /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyo \
296 /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyc \
297 /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyo
299 # Remove all configuration files
300 rm -f /etc/openvswitch/conf.db
301 rm -f /etc/sysconfig/openvswitch
302 rm -f /etc/openvswitch/vswitchd.cacert
303 rm -f /var/xapi/network.dbcache
305 # Remove saved XenServer scripts directory, but only if it's empty
306 rmdir -p /usr/lib/openvswitch/xs-saved 2>/dev/null
308 # Configure system to use bridge
309 echo bridge > /etc/xensource/network.conf
311 printf "\nYou MUST reboot the server now to complete the change to\n"
312 printf "standard Xen networking. Attempts to modify networking on the\n"
313 printf "server or any hosted VM will fail until after the reboot and\n"
314 printf "could leave the server in a state requiring manual recovery.\n\n"
318 %defattr(-,root,root)
319 /etc/init.d/openvswitch
320 /etc/init.d/openvswitch-xapi-update
321 /etc/xapi.d/plugins/openvswitch-cfg-update
322 /etc/xensource/bugtool/network-status/openvswitch.xml
323 /etc/logrotate.d/openvswitch
324 /etc/profile.d/openvswitch.sh
325 /lib/modules/%{xen_version}/kernel/extra/openvswitch/openvswitch_mod.ko
326 /usr/share/openvswitch/python/ovs/__init__.py
327 /usr/share/openvswitch/python/ovs/daemon.py
328 /usr/share/openvswitch/python/ovs/db/__init__.py
329 /usr/share/openvswitch/python/ovs/db/data.py
330 /usr/share/openvswitch/python/ovs/db/error.py
331 /usr/share/openvswitch/python/ovs/db/idl.py
332 /usr/share/openvswitch/python/ovs/db/parser.py
333 /usr/share/openvswitch/python/ovs/db/schema.py
334 /usr/share/openvswitch/python/ovs/db/types.py
335 /usr/share/openvswitch/python/ovs/dirs.py
336 /usr/share/openvswitch/python/ovs/fatal_signal.py
337 /usr/share/openvswitch/python/ovs/json.py
338 /usr/share/openvswitch/python/ovs/jsonrpc.py
339 /usr/share/openvswitch/python/ovs/ovsuuid.py
340 /usr/share/openvswitch/python/ovs/poller.py
341 /usr/share/openvswitch/python/ovs/process.py
342 /usr/share/openvswitch/python/ovs/reconnect.py
343 /usr/share/openvswitch/python/ovs/socket_util.py
344 /usr/share/openvswitch/python/ovs/stream.py
345 /usr/share/openvswitch/python/ovs/timeval.py
346 /usr/share/openvswitch/python/ovs/util.py
347 /usr/share/openvswitch/python/uuid.py
348 /usr/share/openvswitch/scripts/ovs-xapi-sync
349 /usr/share/openvswitch/scripts/interface-reconfigure
350 /usr/share/openvswitch/scripts/InterfaceReconfigure.py
351 /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
352 /usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
353 /usr/share/openvswitch/scripts/vif
354 /usr/share/openvswitch/scripts/sysconfig.template
355 /usr/share/openvswitch/scripts/xen-bugtool-tc-class-show
356 /usr/share/openvswitch/scripts/ovs-save
357 /usr/share/openvswitch/vswitch.ovsschema
358 /usr/sbin/ovs-vswitchd
359 /usr/sbin/ovsdb-server
364 /usr/bin/ovs-tcpundump
365 /usr/bin/ovs-vlan-test
367 /usr/bin/ovsdb-client
369 /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
370 /usr/share/man/man1/ovsdb-client.1.gz
371 /usr/share/man/man1/ovsdb-server.1.gz
372 /usr/share/man/man1/ovsdb-tool.1.gz
373 /usr/share/man/man5/ovs-vswitchd.conf.db.5.gz
374 /usr/share/man/man8/ovs-appctl.8.gz
375 /usr/share/man/man8/ovs-dpctl.8.gz
376 /usr/share/man/man8/ovs-ofctl.8.gz
377 /usr/share/man/man8/ovs-parse-leaks.8.gz
378 /usr/share/man/man1/ovs-pcap.1.gz
379 /usr/share/man/man1/ovs-tcpundump.1.gz
380 /usr/share/man/man8/ovs-vlan-test.8.gz
381 /usr/share/man/man8/ovs-vsctl.8.gz
382 /usr/share/man/man8/ovs-vswitchd.8.gz
384 %exclude /lib/modules/%{xen_version}/kernel/extra/openvswitch/brcompat_mod.ko
385 %exclude /usr/lib/xsconsole/plugins-base/*.py[co]
386 %exclude /usr/sbin/ovs-brcompatd
387 %exclude /usr/share/man/man8/ovs-brcompatd.8.gz
388 %exclude /usr/share/openvswitch/scripts/*.py[co]
389 %exclude /usr/share/openvswitch/python/*.py[co]
390 %exclude /usr/share/openvswitch/python/ovs/*.py[co]
391 %exclude /usr/share/openvswitch/python/ovs/db/*.py[co]