1 # Spec file for vswitch and related programs.
3 # Copyright (C) 2009, 2010 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 # vswitch_version, xen_version, and build_number using -D arguments.
14 # rpmbuild -D "vswitch_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/vswitch-xen.spec
16 %define version %{vswitch_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: %{vswitch_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-%{vswitch_version}.tar.gz
29 Buildroot: /tmp/vswitch-xen-rpm
30 Requires: kernel-xen = %(echo '%{xen_version}' | sed 's/xen$//')
31 # The following Conflicts prevents the "vswitch" package generated by
32 # this spec file from installing at the same time as the "openvswitch"
33 # package shipped with XenServer 5.5.900. In fact, the packages
34 # contain some files with identical names anyhow, so they will not
35 # coexist, but adding an explicit Conflicts makes this conflict more
37 Conflicts: openvswitch
40 The vswitch provides standard network bridging functions augmented with
41 support for the OpenFlow protocol for remote per-flow control of
45 %setup -q -n openvswitch-%{vswitch_version}
48 ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=%{_localstatedir} --with-l26=/lib/modules/%{xen_version}/build --enable-ssl %{build_number}
52 rm -rf $RPM_BUILD_ROOT
53 make install DESTDIR=$RPM_BUILD_ROOT
54 install -d -m 755 $RPM_BUILD_ROOT/etc
55 install -d -m 755 $RPM_BUILD_ROOT/etc/init.d
56 install -m 755 xenserver/etc_init.d_vswitch \
57 $RPM_BUILD_ROOT/etc/init.d/vswitch
58 install -m 755 xenserver/etc_init.d_vswitch-xapi-update \
59 $RPM_BUILD_ROOT/etc/init.d/vswitch-xapi-update
60 install -d -m 755 $RPM_BUILD_ROOT/etc/sysconfig
61 install -d -m 755 $RPM_BUILD_ROOT/etc/logrotate.d
62 install -m 755 xenserver/etc_logrotate.d_vswitch \
63 $RPM_BUILD_ROOT/etc/logrotate.d/vswitch
64 install -d -m 755 $RPM_BUILD_ROOT/etc/profile.d
65 install -m 755 xenserver/etc_profile.d_vswitch.sh \
66 $RPM_BUILD_ROOT/etc/profile.d/vswitch.sh
67 install -d -m 755 $RPM_BUILD_ROOT/etc/xapi.d/plugins
68 install -m 755 xenserver/etc_xapi.d_plugins_vswitch-cfg-update \
69 $RPM_BUILD_ROOT/etc/xapi.d/plugins/vswitch-cfg-update
70 install -d -m 755 $RPM_BUILD_ROOT/usr/share/vswitch/scripts
71 install -m 644 vswitchd/vswitch.ovsschema \
72 $RPM_BUILD_ROOT/usr/share/vswitch/vswitch.ovsschema
73 install -m 755 xenserver/opt_xensource_libexec_interface-reconfigure \
74 $RPM_BUILD_ROOT/usr/share/vswitch/scripts/interface-reconfigure
75 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigure.py \
76 $RPM_BUILD_ROOT/usr/share/vswitch/scripts/InterfaceReconfigure.py
77 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureBridge.py \
78 $RPM_BUILD_ROOT/usr/share/vswitch/scripts/InterfaceReconfigureBridge.py
79 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py \
80 $RPM_BUILD_ROOT/usr/share/vswitch/scripts/InterfaceReconfigureVswitch.py
81 install -m 755 xenserver/etc_xensource_scripts_vif \
82 $RPM_BUILD_ROOT/usr/share/vswitch/scripts/vif
83 install -m 755 xenserver/usr_share_vswitch_scripts_refresh-xs-network-uuids \
84 $RPM_BUILD_ROOT/usr/share/vswitch/scripts/refresh-xs-network-uuids
85 install -m 755 xenserver/usr_sbin_xen-bugtool \
86 $RPM_BUILD_ROOT/usr/share/vswitch/scripts/xen-bugtool
87 install -m 755 xenserver/usr_sbin_brctl \
88 $RPM_BUILD_ROOT/usr/share/vswitch/scripts/brctl
89 install -m 755 xenserver/usr_share_vswitch_scripts_sysconfig.template \
90 $RPM_BUILD_ROOT/usr/share/vswitch/scripts/sysconfig.template
92 xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py \
93 $RPM_BUILD_ROOT/usr/share/vswitch/scripts/XSFeatureVSwitch.py
95 install -d -m 755 $RPM_BUILD_ROOT/lib/modules/%{xen_version}/kernel/net/vswitch
96 find datapath/linux-2.6 -name *.ko -exec install -m 755 \{\} $RPM_BUILD_ROOT/lib/modules/%{xen_version}/kernel/net/vswitch \;
98 # Get rid of stuff we don't want to make RPM happy.
100 $RPM_BUILD_ROOT/usr/bin/ovs-controller \
101 $RPM_BUILD_ROOT/usr/bin/ovs-discover \
102 $RPM_BUILD_ROOT/usr/bin/ovs-kill \
103 $RPM_BUILD_ROOT/usr/bin/ovs-openflowd \
104 $RPM_BUILD_ROOT/usr/bin/ovs-pki \
105 $RPM_BUILD_ROOT/usr/bin/ovs-wdt \
106 $RPM_BUILD_ROOT/usr/sbin/ovs-monitor \
107 $RPM_BUILD_ROOT/usr/share/man/man8/ovs-controller.8 \
108 $RPM_BUILD_ROOT/usr/share/man/man8/ovs-discover.8 \
109 $RPM_BUILD_ROOT/usr/share/man/man8/ovs-kill.8 \
110 $RPM_BUILD_ROOT/usr/share/man/man8/ovs-openflowd.8 \
111 $RPM_BUILD_ROOT/usr/share/man/man8/ovs-pki.8
112 rm -f $RPM_BUILD_ROOT/lib/modules/%{xen_version}/kernel/net/vswitch/veth_mod.ko
114 install -d -m 755 $RPM_BUILD_ROOT/var/lib/openvswitch
117 rm -rf $RPM_BUILD_ROOT
120 if [ ! -f /etc/xensource-inventory ]; then
121 printf "XenSource inventory not present in /etc/xensource-inventory"
125 if [ "$1" = "1" ]; then
126 if md5sum -c --status <<EOF
127 ca141d60061dcfdade73e75abc6529b5 /usr/sbin/brctl
128 b8e9835862ef1a9cec2a3f477d26c989 /etc/xensource/scripts/vif
129 51970ad613a3996d5997e18e44db47da /opt/xensource/libexec/interface-reconfigure
130 5654c8c36699fcc8744ca9cd5b855414 /usr/sbin/xen-bugtool
133 printf "\nVerified host scripts from XenServer 5.5.0.\n\n"
134 elif md5sum -c --status <<EOF
135 ca141d60061dcfdade73e75abc6529b5 /usr/sbin/brctl
136 b8e9835862ef1a9cec2a3f477d26c989 /etc/xensource/scripts/vif
137 51970ad613a3996d5997e18e44db47da /opt/xensource/libexec/interface-reconfigure
138 f6519085c2fc5f7bc4eccc294ed62000 /usr/sbin/xen-bugtool
141 printf "\nVerified host scripts from XenServer 5.5.0-24648p (Update 1)\n"
142 printf "or 5.5.0-25727p (Update 2).\n\n"
143 elif md5sum -c --status <<EOF
144 ca141d60061dcfdade73e75abc6529b5 /usr/sbin/brctl
145 b8e9835862ef1a9cec2a3f477d26c989 /etc/xensource/scripts/vif
146 ce451d3c985fd1db6497a363f0d9dedb /opt/xensource/libexec/interface-reconfigure
147 2b53f500431fcba5276c896e9e4281b9 /usr/sbin/xen-bugtool
150 printf "\nVerified host scripts from XenServer 5.5.900.\n\n"
154 The original XenServer scripts replaced by this package are not those
155 of any supported version of XenServer. This could lead to unexpected
156 behavior of your server. Unless you are sure you know what you are
157 doing, it is highly recommended that you remove this package
158 immediately after the install completes, which will restore the
159 XenServer scripts that you were previously using.
165 if test ! -e /var/xapi/network.dbcache; then
166 if test "$1" = 1; then
167 printf "Creating xapi database cache... "
169 printf "warning: Open vSwitch is being re-installed or upgraded,\n"
170 printf " but the xapi database cache is missing.\n"
171 printf "Re-creating xapi database cache... "
174 if /usr/share/vswitch/scripts/interface-reconfigure rewrite; then
178 printf "Open vSwitch can only be installed on a XenServer that\n"
179 printf "has connectivity to xapi on the pool master. Please\n"
180 printf "fix connectivity to the pool master, then try again.\n"
185 # Ensure that modprobe will find our modules.
186 depmod %{xen_version}
188 if grep -F net.ipv4.conf.all.arp_filter /etc/sysctl.conf >/dev/null 2>&1; then :; else
189 cat >>/etc/sysctl.conf <<EOF
190 # This works around an issue in xhad, which binds to a particular
191 # Ethernet device, which in turn causes ICMP port unreachable messages
192 # if packets are received are on the wrong interface, which in turn
193 # can happen if we send out ARP replies on every interface (as Linux
194 # does by default) instead of just on the interface that has the IP
195 # address being ARPed for, which this sysctl setting in turn works
199 net.ipv4.conf.all.arp_filter = 1
203 if test ! -e /etc/ovs-vswitchd.conf.db; then
204 # Create ovs-vswitchd config database
205 ovsdb-tool -vANY:console:emer create /etc/ovs-vswitchd.conf.db \
206 /usr/share/vswitch/vswitch.ovsschema \
208 # Create initial table in config database
209 ovsdb-tool -vANY:console:emer transact /etc/ovs-vswitchd.conf.db \
210 '[{"op": "insert", "table": "Open_vSwitch", "row": {}}]' \
214 # Create default or update existing /etc/sysconfig/vswitch.
215 SYSCONFIG=/etc/sysconfig/vswitch
216 TEMPLATE=/usr/share/vswitch/scripts/sysconfig.template
217 if [ ! -e $SYSCONFIG ]; then
218 cp $TEMPLATE $SYSCONFIG
220 for var in $(awk -F'[ :]' '/^# [_A-Z0-9]+:/{print $2}' $TEMPLATE)
222 if ! grep $var $SYSCONFIG >/dev/null 2>&1; then
224 sed -n "/$var:/,/$var=/p" $TEMPLATE >> $SYSCONFIG
229 # Replace XenServer files by our versions.
230 mkdir -p /usr/lib/vswitch/xs-original \
231 || printf "Could not create script backup directory.\n"
233 /opt/xensource/libexec/interface-reconfigure \
234 /opt/xensource/libexec/InterfaceReconfigure.py \
235 /opt/xensource/libexec/InterfaceReconfigureBridge.py \
236 /opt/xensource/libexec/InterfaceReconfigureVswitch.py \
237 /etc/xensource/scripts/vif \
238 /usr/sbin/xen-bugtool \
243 if [ -f "$f" ] && [ "$t" != "/usr/share/vswitch/scripts/$s" ]; then
244 mv "$f" /usr/lib/vswitch/xs-original/ \
245 || printf "Could not save original XenServer $s script\n"
246 ln -s "/usr/share/vswitch/scripts/$s" "$f" \
247 || printf "Could not link to vSwitch $s script\n"
251 # Install xsconsole plugin
252 plugin=$(readlink /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py)
253 if [ "$plugin" != "/usr/share/vswitch/scripts/XSFeatureVSwitch.py" ]; then
254 rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
255 ln -s /usr/share/vswitch/scripts/XSFeatureVSwitch.py /usr/lib/xsconsole/plugins-base/ || printf "Could not link to vSswitch xsconsole plugin.\n"
258 # Ensure all required services are set to run
259 for s in vswitch vswitch-xapi-update; do
260 if chkconfig --list $s >/dev/null 2>&1; then
261 chkconfig --del $s || printf "Could not remove $s init script."
263 chkconfig --add $s || printf "Could not add $s init script."
264 chkconfig $s on || printf "Could not enable $s init script."
267 # Configure system to use vswitch
268 echo vswitch > /etc/xensource/network.conf
270 if [ "$1" = "1" ]; then # $1 = 2 for upgrade
271 printf "\nYou MUST reboot the server NOW to complete the change to the\n"
272 printf "the vSwitch. Attempts to modify networking on the server\n"
273 printf "or any hosted VM will fail until after the reboot and could\n"
274 printf "leave the server in an state requiring manual recovery.\n\n"
276 printf "\nTo use the new vSwitch, you should reboot the server\n"
277 printf "now. Failure to do so may result in incorrect operation.\n\n"
281 if [ "$1" = "0" ]; then # $1 = 1 for upgrade
282 for s in vswitch vswitch-xapi-update; do
283 chkconfig --del $s || printf "Could not remove $s init script."
289 if [ "$1" = "0" ]; then # $1 = 1 for upgrade
291 rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py \
292 /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
293 /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo \
294 || printf "Could not remove vSwitch xsconsole plugin.\n"
296 # Restore original XenServer scripts
298 /opt/xensource/libexec/interface-reconfigure \
299 /etc/xensource/scripts/vif \
300 /usr/sbin/xen-bugtool \
304 if [ ! -f "/usr/lib/vswitch/xs-original/$s" ]; then
305 printf "Original XenServer $s script not present in /usr/lib/vswitch/xs-original\n"
306 printf "Could not restore original XenServer script.\n"
309 && mv "/usr/lib/vswitch/xs-original/$s" "$f") \
310 || printf "Could not restore original XenServer $s script.\n"
314 # Remove all configuration files
315 rm -f /etc/ovs-vswitchd.conf.db
316 rm -f /etc/sysconfig/vswitch
317 rm -f /etc/ovs-vswitchd.cacert
318 rm -f /var/xapi/network.dbcache
320 # Configure system to use bridge
321 echo bridge > /etc/xensource/network.conf
323 printf "\nYou MUST reboot the server now to complete the change to\n"
324 printf "standard Xen networking. Attempts to modify networking on the\n"
325 printf "server or any hosted VM will fail until after the reboot and\n"
326 printf "could leave the server in a state requiring manual recovery.\n\n"
331 %defattr(-,root,root)
333 /etc/init.d/vswitch-xapi-update
334 /etc/xapi.d/plugins/vswitch-cfg-update
335 /etc/logrotate.d/vswitch
336 /etc/profile.d/vswitch.sh
337 /lib/modules/%{xen_version}/kernel/net/vswitch/openvswitch_mod.ko
338 /lib/modules/%{xen_version}/kernel/net/vswitch/brcompat_mod.ko
339 %if %(echo '%{xen_version}'|awk -F"." '{if ($3>=18) print 1; else print 0;}')
340 /lib/modules/%{xen_version}/kernel/net/vswitch/ip_gre_mod.ko
342 /usr/share/vswitch/scripts/refresh-xs-network-uuids
343 /usr/share/vswitch/scripts/interface-reconfigure
344 /usr/share/vswitch/scripts/InterfaceReconfigure.py
345 /usr/share/vswitch/scripts/InterfaceReconfigureBridge.py
346 /usr/share/vswitch/scripts/InterfaceReconfigureVswitch.py
347 /usr/share/vswitch/scripts/vif
348 /usr/share/vswitch/scripts/xen-bugtool
349 /usr/share/vswitch/scripts/XSFeatureVSwitch.py
350 /usr/share/vswitch/scripts/brctl
351 /usr/share/vswitch/scripts/sysconfig.template
352 /usr/share/vswitch/vswitch.ovsschema
353 /usr/sbin/ovs-brcompatd
354 /usr/sbin/ovs-vswitchd
355 /usr/sbin/ovsdb-server
360 /usr/bin/ovsdb-client
362 /usr/share/man/man1/ovsdb-client.1.gz
363 /usr/share/man/man1/ovsdb-server.1.gz
364 /usr/share/man/man1/ovsdb-tool.1.gz
365 /usr/share/man/man8/ovs-appctl.8.gz
366 /usr/share/man/man8/ovs-brcompatd.8.gz
367 /usr/share/man/man8/ovs-dpctl.8.gz
368 /usr/share/man/man8/ovs-ofctl.8.gz
369 /usr/share/man/man8/ovs-vsctl.8.gz
370 /usr/share/man/man8/ovs-vswitchd.8.gz
372 %exclude /usr/share/vswitch/scripts/*.pyc
373 %exclude /usr/share/vswitch/scripts/*.pyo