9e1c9c29a6c55b66e31e185034c39bde0328261a
[openvswitch] / xenserver / openvswitch-xen.spec
1 # Spec file for Open vSwitch.
2
3 # Copyright (C) 2009, 2010 Nicira Networks, Inc.
4 #
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.
9
10 # When building, the rpmbuild command line should define
11 # openvswitch_version, xen_version, and build_number using -D arguments.
12 # for example:
13 #
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
15 #
16 %define version %{openvswitch_version}-%{xen_version}
17
18 Name: openvswitch
19 Summary: Virtual switch
20 Group: System Environment/Daemons
21 URL: http://www.openvswitch.org/
22 Vendor: Nicira Networks, Inc.
23 Version: %{openvswitch_version}
24
25 # The entire source code is ASL 2.0 except datapath/ which is GPLv2
26 License: ASL 2.0 and GPLv2
27 Release: 1
28 Source: openvswitch-%{openvswitch_version}.tar.gz
29 Buildroot: /tmp/openvswitch-xen-rpm
30 Requires: kernel-xen = %(echo '%{xen_version}' | sed 's/xen$//')
31
32 %description
33 Open vSwitch provides standard network bridging functions augmented with
34 support for the OpenFlow protocol for remote per-flow control of
35 traffic.
36
37 %prep
38 %setup -q -n openvswitch-%{openvswitch_version}
39
40 %build
41 ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=%{_localstatedir} --with-l26=/lib/modules/%{xen_version}/build --enable-ssl %{build_number}
42 make %{_smp_mflags}
43
44 %install
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/usr/share/openvswitch/scripts
64 install -m 644 vswitchd/vswitch.ovsschema \
65          $RPM_BUILD_ROOT/usr/share/openvswitch/vswitch.ovsschema
66 install -m 755 xenserver/opt_xensource_libexec_interface-reconfigure \
67              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/interface-reconfigure
68 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigure.py \
69              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigure.py
70 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureBridge.py \
71              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
72 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py \
73              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
74 install -m 755 xenserver/etc_xensource_scripts_vif \
75              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/vif
76 install -m 755 xenserver/usr_share_openvswitch_scripts_refresh-network-uuids \
77                $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/refresh-network-uuids
78 install -m 755 xenserver/usr_sbin_xen-bugtool \
79              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/xen-bugtool
80 install -m 755 xenserver/usr_sbin_brctl \
81              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/brctl
82 install -m 755 xenserver/usr_share_openvswitch_scripts_sysconfig.template \
83          $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/sysconfig.template
84 install -d -m 755 $RPM_BUILD_ROOT/usr/lib/xsconsole/plugins-base
85 install -m 644 \
86         xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py \
87                $RPM_BUILD_ROOT/usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
88
89 install -d -m 755 $RPM_BUILD_ROOT/lib/modules/%{xen_version}/kernel/extra/openvswitch
90 find datapath/linux-2.6 -name *.ko -exec install -m 755  \{\} $RPM_BUILD_ROOT/lib/modules/%{xen_version}/kernel/extra/openvswitch \;
91
92 # Get rid of stuff we don't want to make RPM happy.
93 rm \
94     $RPM_BUILD_ROOT/usr/bin/ovs-controller \
95     $RPM_BUILD_ROOT/usr/bin/ovs-discover \
96     $RPM_BUILD_ROOT/usr/bin/ovs-kill \
97     $RPM_BUILD_ROOT/usr/bin/ovs-openflowd \
98     $RPM_BUILD_ROOT/usr/bin/ovs-pki \
99     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-controller.8 \
100     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-discover.8 \
101     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-kill.8 \
102     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-openflowd.8 \
103     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-pki.8
104
105 install -d -m 755 $RPM_BUILD_ROOT/var/lib/openvswitch
106
107 %clean
108 rm -rf $RPM_BUILD_ROOT
109
110 %post
111 if [ ! -f /etc/xensource-inventory ]; then
112     printf "XenSource inventory not present in /etc/xensource-inventory"
113     exit 1
114 fi
115 . /etc/xensource-inventory
116
117 if [ "$1" = "1" ]; then
118     if md5sum -c --status <<EOF
119 ca141d60061dcfdade73e75abc6529b5  /usr/sbin/brctl
120 b8e9835862ef1a9cec2a3f477d26c989  /etc/xensource/scripts/vif
121 51970ad613a3996d5997e18e44db47da  /opt/xensource/libexec/interface-reconfigure
122 5654c8c36699fcc8744ca9cd5b855414  /usr/sbin/xen-bugtool
123 EOF
124     then
125         printf "\nVerified host scripts from XenServer 5.5.0.\n\n"
126     elif md5sum -c --status <<EOF
127 ca141d60061dcfdade73e75abc6529b5  /usr/sbin/brctl
128 b8e9835862ef1a9cec2a3f477d26c989  /etc/xensource/scripts/vif
129 51970ad613a3996d5997e18e44db47da  /opt/xensource/libexec/interface-reconfigure
130 f6519085c2fc5f7bc4eccc294ed62000  /usr/sbin/xen-bugtool
131 EOF
132     then
133         printf "\nVerified host scripts from XenServer 5.5.0-24648p (Update 1)\n"
134         printf "or 5.5.0-25727p (Update 2).\n\n"
135     elif md5sum -c --status <<EOF
136 ca141d60061dcfdade73e75abc6529b5  /usr/sbin/brctl
137 02cf136237ed85fcbcc1efc15ce0591c  /opt/xensource/libexec/interface-reconfigure
138 3a192ee70ebf2153c90051b3af95f331  /opt/xensource/libexec/InterfaceReconfigureBridge.py
139 f71cadf1464caefa7943de0ab47fdd8a  /opt/xensource/libexec/InterfaceReconfigure.py
140 d70f08f235fb1bfd49a0580e440f15a0  /opt/xensource/libexec/InterfaceReconfigureVswitch.py
141 f5c85ca825b1e6f5a0845530981cd836  /etc/xensource/scripts/vif
142 facb851606f82ca2bcc760a4d91bbe33  /usr/sbin/xen-bugtool
143 EOF
144     then
145         printf "\nVerified host scripts from XenServer 5.5.900-29381p.\n\n"
146     else
147 cat <<EOF
148
149 The original XenServer scripts replaced by this package are not those
150 of any supported version of XenServer.  This could lead to unexpected
151 behavior of your server.  Unless you are sure you know what you are
152 doing, it is highly recommended that you remove this package
153 immediately after the install completes, which will restore the
154 XenServer scripts that you were previously using.
155
156 EOF
157     fi
158 fi
159
160 # On XenServer 5.5.0, we need refresh-network-uuids to run whenever
161 # XAPI starts or restarts.  (On XenServer 5.6.0, XAPI calls the
162 # "update" method of the vswitch-cfg-update plugin whenever it starts
163 # or restarts, so this is no longer necessary.)
164 if test "$PRODUCT_VERSION" = "5.5.0"; then
165     RNU=/usr/share/openvswitch/scripts/refresh-network-uuids
166     XSS=/opt/xensource/libexec/xapi-startup-script
167     if test -e $XSS && (test ! -L $XSS || test "`readlink $XSS`" != $RNU); then
168         echo "$XSS is already in use, refusing to overwrite"
169         exit 1
170     fi
171     rm -f $XSS
172     ln -s $RNU $XSS
173
174     # If /etc/xensource/network.conf doesn't exist (it was added in 5.6.0),
175     # then interface-reconfigure will be unhappy when we run it below.
176     if test ! -e /etc/xensource/network.conf; then
177         echo bridge > /etc/xensource/network.conf
178     fi
179 fi
180
181
182 if test ! -e /var/xapi/network.dbcache; then
183     if test "$1" = 1; then
184         printf "Creating xapi database cache...  "
185     else
186         printf "warning: Open vSwitch is being re-installed or upgraded,\n"
187         printf "         but the xapi database cache is missing.\n"
188         printf "Re-creating xapi database cache...  "
189     fi
190
191     if /usr/share/openvswitch/scripts/interface-reconfigure rewrite; then
192         printf "done.\n"
193     else
194         printf "FAILED\n"
195         printf "Open vSwitch can only be installed on a XenServer that\n"
196         printf "has connectivity to xapi on the pool master.  Please\n"
197         printf "fix connectivity to the pool master, then try again.\n"
198         exit 1
199     fi
200 fi
201
202 # Ensure that modprobe will find our modules.
203 depmod %{xen_version}
204
205 if grep -F net.ipv4.conf.all.arp_filter /etc/sysctl.conf >/dev/null 2>&1; then :; else
206     cat >>/etc/sysctl.conf <<EOF
207 # This works around an issue in xhad, which binds to a particular
208 # Ethernet device, which in turn causes ICMP port unreachable messages
209 # if packets are received are on the wrong interface, which in turn
210 # can happen if we send out ARP replies on every interface (as Linux
211 # does by default) instead of just on the interface that has the IP
212 # address being ARPed for, which this sysctl setting in turn works
213 # around.
214 #
215 # Bug #1378.
216 net.ipv4.conf.all.arp_filter = 1
217 EOF
218 fi
219
220 if test ! -e /etc/openvswitch/conf.db; then
221     install -d -m 755 -o root -g root /etc/openvswitch
222
223     # Create ovs-vswitchd config database
224     ovsdb-tool -vANY:console:emer create /etc/openvswitch/conf.db \
225             /usr/share/openvswitch/vswitch.ovsschema
226
227     # Create initial table in config database
228     ovsdb-tool -vANY:console:emer transact /etc/openvswitch/conf.db \
229             '[{"op": "insert", "table": "Open_vSwitch", "row": {}}]' \
230             > /dev/null
231 fi
232
233 # Create default or update existing /etc/sysconfig/openvswitch.
234 SYSCONFIG=/etc/sysconfig/openvswitch
235 TEMPLATE=/usr/share/openvswitch/scripts/sysconfig.template
236 if [ ! -e $SYSCONFIG ]; then
237     cp $TEMPLATE $SYSCONFIG
238 else
239     for var in $(awk -F'[ :]' '/^# [_A-Z0-9]+:/{print $2}' $TEMPLATE)
240     do
241         if ! grep $var $SYSCONFIG >/dev/null 2>&1; then
242             echo >> $SYSCONFIG
243             sed -n "/$var:/,/$var=/p" $TEMPLATE >> $SYSCONFIG
244         fi
245     done
246 fi
247
248 # Replace XenServer files by our versions.
249 mkdir -p /usr/lib/openvswitch/xs-original \
250     || printf "Could not create script backup directory.\n"
251 for f in \
252     /opt/xensource/libexec/interface-reconfigure \
253     /opt/xensource/libexec/InterfaceReconfigure.py \
254     /opt/xensource/libexec/InterfaceReconfigureBridge.py \
255     /opt/xensource/libexec/InterfaceReconfigureVswitch.py \
256     /etc/xensource/scripts/vif \
257     /usr/sbin/xen-bugtool \
258     /usr/sbin/brctl
259 do
260     s=$(basename "$f")
261     t=$(readlink "$f")
262     if [ -f "$f" ] && [ "$t" != "/usr/share/openvswitch/scripts/$s" ]; then
263         mv "$f" /usr/lib/openvswitch/xs-original/ \
264             || printf "Could not save original XenServer $s script\n"
265         ln -s "/usr/share/openvswitch/scripts/$s" "$f" \
266             || printf "Could not link to Open vSwitch $s script\n"
267     fi
268 done
269
270 # Ensure all required services are set to run
271 for s in openvswitch openvswitch-xapi-update; do
272     if chkconfig --list $s >/dev/null 2>&1; then
273         chkconfig --del $s || printf "Could not remove $s init script."
274     fi
275     chkconfig --add $s || printf "Could not add $s init script."
276     chkconfig $s on || printf "Could not enable $s init script."
277 done
278
279 # Configure system to use Open vSwitch
280 echo vswitch > /etc/xensource/network.conf
281
282 if [ "$1" = "1" ]; then    # $1 = 2 for upgrade
283     printf "\nYou MUST reboot the server NOW to complete the change to\n"
284     printf "Open vSwitch.  Attempts to modify networking on the server\n"
285     printf "or any hosted VM will fail until after the reboot and could\n"
286     printf "leave the server in an state requiring manual recovery.\n\n"
287 else
288     printf "\nTo use the new Open vSwitch install, you should reboot the\n" 
289     printf "server now.  Failure to do so may result in incorrect operation."
290     printf "\n\n"
291 fi
292
293 %preun
294 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
295     for s in openvswitch openvswitch-xapi-update; do
296         chkconfig --del $s || printf "Could not remove $s init script."
297     done
298 fi
299
300
301 %postun
302 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
303     . /etc/xensource-inventory
304     if test "$PRODUCT_VERSION" = "5.5.0"; then
305         XSS=/opt/xensource/libexec/xapi-startup-script
306         rm -f $XSS
307     fi
308
309     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
310         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo
311
312     rm -f /usr/share/openvswitch/scripts/InterfaceReconfigure.pyc \
313         /usr/share/openvswitch/scripts/InterfaceReconfigure.pyo \
314         /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyc \
315         /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyo \
316         /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyc \
317         /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyo 
318
319     # Restore original XenServer scripts
320     for f in \
321         /opt/xensource/libexec/interface-reconfigure \
322         /opt/xensource/libexec/InterfaceReconfigure.py \
323         /opt/xensource/libexec/InterfaceReconfigureBridge.py \
324         /opt/xensource/libexec/InterfaceReconfigureVswitch.py \
325         /etc/xensource/scripts/vif \
326         /usr/sbin/xen-bugtool \
327         /usr/sbin/brctl
328     do
329         s=$(basename "$f")
330         if [ ! -f "/usr/lib/openvswitch/xs-original/$s" ]; then
331             printf "Original XenServer $s script not present in /usr/lib/openvswitch/xs-original\n"
332             printf "Could not restore original XenServer script.\n"
333         else
334             (rm -f "$f" \
335                 && mv "/usr/lib/openvswitch/xs-original/$s" "$f") \
336                 || printf "Could not restore original XenServer $s script.\n"
337         fi
338     done
339
340     # Remove all configuration files
341     rm -f /etc/openvswitch/conf.db
342     rm -f /etc/sysconfig/openvswitch
343     rm -f /etc/openvswitch/vswitchd.cacert
344     rm -f /var/xapi/network.dbcache
345
346     if test "$PRODUCT_VERSION" != "5.5.0"; then
347         # Configure system to use bridge
348         echo bridge > /etc/xensource/network.conf
349     else
350         # Get rid of network.conf entirely, to make the system pristine.
351         rm -f /etc/xensource/network.conf
352     fi
353
354     printf "\nYou MUST reboot the server now to complete the change to\n"
355     printf "standard Xen networking.  Attempts to modify networking on the\n"
356     printf "server or any hosted VM will fail until after the reboot and\n"
357     printf "could leave the server in a state requiring manual recovery.\n\n"
358 fi
359
360
361 %files
362 %defattr(-,root,root)
363 /etc/init.d/openvswitch
364 /etc/init.d/openvswitch-xapi-update
365 /etc/xapi.d/plugins/openvswitch-cfg-update
366 /etc/logrotate.d/openvswitch
367 /etc/profile.d/openvswitch.sh
368 /lib/modules/%{xen_version}/kernel/extra/openvswitch/openvswitch_mod.ko
369 /lib/modules/%{xen_version}/kernel/extra/openvswitch/brcompat_mod.ko
370 /usr/share/openvswitch/scripts/refresh-network-uuids
371 /usr/share/openvswitch/scripts/interface-reconfigure
372 /usr/share/openvswitch/scripts/InterfaceReconfigure.py
373 /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
374 /usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
375 /usr/share/openvswitch/scripts/vif
376 /usr/share/openvswitch/scripts/xen-bugtool
377 /usr/share/openvswitch/scripts/brctl
378 /usr/share/openvswitch/scripts/sysconfig.template
379 /usr/share/openvswitch/vswitch.ovsschema
380 /usr/sbin/ovs-brcompatd
381 /usr/sbin/ovs-vswitchd
382 /usr/sbin/ovsdb-server
383 /usr/bin/ovs-appctl
384 /usr/bin/ovs-dpctl
385 /usr/bin/ovs-ofctl
386 /usr/bin/ovs-vsctl
387 /usr/bin/ovsdb-client
388 /usr/bin/ovsdb-tool
389 /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
390 /usr/share/man/man1/ovsdb-client.1.gz
391 /usr/share/man/man1/ovsdb-server.1.gz
392 /usr/share/man/man1/ovsdb-tool.1.gz
393 /usr/share/man/man5/ovs-vswitchd.conf.db.5.gz
394 /usr/share/man/man8/ovs-appctl.8.gz
395 /usr/share/man/man8/ovs-brcompatd.8.gz
396 /usr/share/man/man8/ovs-dpctl.8.gz
397 /usr/share/man/man8/ovs-ofctl.8.gz
398 /usr/share/man/man8/ovs-parse-leaks.8.gz
399 /usr/share/man/man8/ovs-vsctl.8.gz
400 /usr/share/man/man8/ovs-vswitchd.8.gz
401 /var/lib/openvswitch
402 %exclude /usr/lib/xsconsole/plugins-base/*.pyc
403 %exclude /usr/lib/xsconsole/plugins-base/*.pyo
404 %exclude /usr/share/openvswitch/scripts/*.pyc
405 %exclude /usr/share/openvswitch/scripts/*.pyo