xenserver: Minor spec file cleanups
[sliver-openvswitch.git] / 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 -m 644 \
85         xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py \
86                $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/XSFeatureVSwitch.py
87
88 install -d -m 755 $RPM_BUILD_ROOT/lib/modules/%{xen_version}/kernel/net/openvswitch
89 find datapath/linux-2.6 -name *.ko -exec install -m 755  \{\} $RPM_BUILD_ROOT/lib/modules/%{xen_version}/kernel/net/openvswitch \;
90
91 # Get rid of stuff we don't want to make RPM happy.
92 rm \
93     $RPM_BUILD_ROOT/usr/bin/ovs-controller \
94     $RPM_BUILD_ROOT/usr/bin/ovs-discover \
95     $RPM_BUILD_ROOT/usr/bin/ovs-kill \
96     $RPM_BUILD_ROOT/usr/bin/ovs-openflowd \
97     $RPM_BUILD_ROOT/usr/bin/ovs-pki \
98     $RPM_BUILD_ROOT/usr/bin/ovs-wdt \
99     $RPM_BUILD_ROOT/usr/sbin/ovs-monitor \
100     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-controller.8 \
101     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-discover.8 \
102     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-kill.8 \
103     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-openflowd.8 \
104     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-pki.8
105 rm -f $RPM_BUILD_ROOT/lib/modules/%{xen_version}/kernel/net/openvswitch/veth_mod.ko
106
107 install -d -m 755 $RPM_BUILD_ROOT/var/lib/openvswitch
108
109 %clean
110 rm -rf $RPM_BUILD_ROOT
111
112 %post
113 if [ ! -f /etc/xensource-inventory ]; then
114     printf "XenSource inventory not present in /etc/xensource-inventory"
115     exit 1
116 fi
117
118 if [ "$1" = "1" ]; then
119     if md5sum -c --status <<EOF
120 ca141d60061dcfdade73e75abc6529b5  /usr/sbin/brctl
121 b8e9835862ef1a9cec2a3f477d26c989  /etc/xensource/scripts/vif
122 51970ad613a3996d5997e18e44db47da  /opt/xensource/libexec/interface-reconfigure
123 5654c8c36699fcc8744ca9cd5b855414  /usr/sbin/xen-bugtool
124 EOF
125     then
126         printf "\nVerified host scripts from XenServer 5.5.0.\n\n"
127     elif md5sum -c --status <<EOF
128 ca141d60061dcfdade73e75abc6529b5  /usr/sbin/brctl
129 b8e9835862ef1a9cec2a3f477d26c989  /etc/xensource/scripts/vif
130 51970ad613a3996d5997e18e44db47da  /opt/xensource/libexec/interface-reconfigure
131 f6519085c2fc5f7bc4eccc294ed62000  /usr/sbin/xen-bugtool
132 EOF
133     then
134         printf "\nVerified host scripts from XenServer 5.5.0-24648p (Update 1)\n"
135         printf "or 5.5.0-25727p (Update 2).\n\n"
136     elif md5sum -c --status <<EOF
137 ca141d60061dcfdade73e75abc6529b5  /usr/sbin/brctl
138 02cf136237ed85fcbcc1efc15ce0591c  /opt/xensource/libexec/interface-reconfigure
139 3a192ee70ebf2153c90051b3af95f331  /opt/xensource/libexec/InterfaceReconfigureBridge.py
140 f71cadf1464caefa7943de0ab47fdd8a  /opt/xensource/libexec/InterfaceReconfigure.py
141 d70f08f235fb1bfd49a0580e440f15a0  /opt/xensource/libexec/InterfaceReconfigureVswitch.py
142 f5c85ca825b1e6f5a0845530981cd836  /etc/xensource/scripts/vif
143 facb851606f82ca2bcc760a4d91bbe33  /usr/sbin/xen-bugtool
144 EOF
145     then
146         printf "\nVerified host scripts from XenServer 5.5.900-29381p.\n\n"
147     else
148 cat <<EOF
149
150 The original XenServer scripts replaced by this package are not those
151 of any supported version of XenServer.  This could lead to unexpected
152 behavior of your server.  Unless you are sure you know what you are
153 doing, it is highly recommended that you remove this package
154 immediately after the install completes, which will restore the
155 XenServer scripts that you were previously using.
156
157 EOF
158     fi
159 fi
160
161 if test ! -e /var/xapi/network.dbcache; then
162     if test "$1" = 1; then
163         printf "Creating xapi database cache...  "
164     else
165         printf "warning: Open vSwitch is being re-installed or upgraded,\n"
166         printf "         but the xapi database cache is missing.\n"
167         printf "Re-creating xapi database cache...  "
168     fi
169
170     if /usr/share/openvswitch/scripts/interface-reconfigure rewrite; then
171         printf "done.\n"
172     else
173         printf "FAILED\n"
174         printf "Open vSwitch can only be installed on a XenServer that\n"
175         printf "has connectivity to xapi on the pool master.  Please\n"
176         printf "fix connectivity to the pool master, then try again.\n"
177         exit 1
178     fi
179 fi
180
181 # Ensure that modprobe will find our modules.
182 depmod %{xen_version}
183
184 if grep -F net.ipv4.conf.all.arp_filter /etc/sysctl.conf >/dev/null 2>&1; then :; else
185     cat >>/etc/sysctl.conf <<EOF
186 # This works around an issue in xhad, which binds to a particular
187 # Ethernet device, which in turn causes ICMP port unreachable messages
188 # if packets are received are on the wrong interface, which in turn
189 # can happen if we send out ARP replies on every interface (as Linux
190 # does by default) instead of just on the interface that has the IP
191 # address being ARPed for, which this sysctl setting in turn works
192 # around.
193 #
194 # Bug #1378.
195 net.ipv4.conf.all.arp_filter = 1
196 EOF
197 fi
198
199 if test ! -e /etc/openvswitch/conf.db; then
200     install -d -m 755 -o root -g root /etc/openvswitch
201
202     # Create ovs-vswitchd config database
203     ovsdb-tool -vANY:console:emer create /etc/openvswitch/conf.db \
204             /usr/share/openvswitch/vswitch.ovsschema \
205
206     # Create initial table in config database
207     ovsdb-tool -vANY:console:emer transact /etc/openvswitch/conf.db \
208             '[{"op": "insert", "table": "Open_vSwitch", "row": {}}]' \
209             > /dev/null
210 fi
211
212 # Create default or update existing /etc/sysconfig/openvswitch.
213 SYSCONFIG=/etc/sysconfig/openvswitch
214 TEMPLATE=/usr/share/openvswitch/scripts/sysconfig.template
215 if [ ! -e $SYSCONFIG ]; then
216     cp $TEMPLATE $SYSCONFIG
217 else
218     for var in $(awk -F'[ :]' '/^# [_A-Z0-9]+:/{print $2}' $TEMPLATE)
219     do
220         if ! grep $var $SYSCONFIG >/dev/null 2>&1; then
221             echo >> $SYSCONFIG
222             sed -n "/$var:/,/$var=/p" $TEMPLATE >> $SYSCONFIG
223         fi
224     done
225 fi
226
227 # Replace XenServer files by our versions.
228 mkdir -p /usr/lib/openvswitch/xs-original \
229     || printf "Could not create script backup directory.\n"
230 for f in \
231     /opt/xensource/libexec/interface-reconfigure \
232     /opt/xensource/libexec/InterfaceReconfigure.py \
233     /opt/xensource/libexec/InterfaceReconfigureBridge.py \
234     /opt/xensource/libexec/InterfaceReconfigureVswitch.py \
235     /etc/xensource/scripts/vif \
236     /usr/sbin/xen-bugtool \
237     /usr/sbin/brctl
238 do
239     s=$(basename "$f")
240     t=$(readlink "$f")
241     if [ -f "$f" ] && [ "$t" != "/usr/share/openvswitch/scripts/$s" ]; then
242         mv "$f" /usr/lib/openvswitch/xs-original/ \
243             || printf "Could not save original XenServer $s script\n"
244         ln -s "/usr/share/openvswitch/scripts/$s" "$f" \
245             || printf "Could not link to Open vSwitch $s script\n"
246     fi
247 done
248
249 # Install xsconsole plugin
250 plugin=$(readlink /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py)
251 if [ "$plugin" != "/usr/share/openvswitch/scripts/XSFeatureVSwitch.py" ]; then
252     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
253     ln -s /usr/share/openvswitch/scripts/XSFeatureVSwitch.py /usr/lib/xsconsole/plugins-base/ || printf "Could not link to Open vSwitch xsconsole plugin.\n"
254 fi
255
256 # Ensure all required services are set to run
257 for s in openvswitch openvswitch-xapi-update; do
258     if chkconfig --list $s >/dev/null 2>&1; then
259         chkconfig --del $s || printf "Could not remove $s init script."
260     fi
261     chkconfig --add $s || printf "Could not add $s init script."
262     chkconfig $s on || printf "Could not enable $s init script."
263 done
264
265 # Configure system to use Open vSwitch
266 echo vswitch > /etc/xensource/network.conf
267
268 if [ "$1" = "1" ]; then    # $1 = 2 for upgrade
269     printf "\nYou MUST reboot the server NOW to complete the change to\n"
270     printf "Open vSwitch.  Attempts to modify networking on the server\n"
271     printf "or any hosted VM will fail until after the reboot and could\n"
272     printf "leave the server in an state requiring manual recovery.\n\n"
273 else
274     printf "\nTo use the new Open vSwitch install, you should reboot the\n" 
275     printf "server now.  Failure to do so may result in incorrect operation."
276     printf "\n\n"
277 fi
278
279 %preun
280 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
281     for s in openvswitch openvswitch-xapi-update; do
282         chkconfig --del $s || printf "Could not remove $s init script."
283     done
284 fi
285
286
287 %postun
288 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
289
290     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py \
291         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
292         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo \
293         || printf "Could not remove Open vSwitch xsconsole plugin.\n"
294
295     rm -f /usr/share/openvswitch/scripts/InterfaceReconfigure.pyc \
296         /usr/share/openvswitch/scripts/InterfaceReconfigure.pyo \
297         /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyc \
298         /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyo \
299         /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyc \
300         /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyo 
301
302     # Restore original XenServer scripts
303     for f in \
304         /opt/xensource/libexec/interface-reconfigure \
305         /etc/xensource/scripts/vif \
306         /usr/sbin/xen-bugtool \
307         /usr/sbin/brctl
308     do
309         s=$(basename "$f")
310         if [ ! -f "/usr/lib/openvswitch/xs-original/$s" ]; then
311             printf "Original XenServer $s script not present in /usr/lib/openvswitch/xs-original\n"
312             printf "Could not restore original XenServer script.\n"
313         else
314             (rm -f "$f" \
315                 && mv "/usr/lib/openvswitch/xs-original/$s" "$f") \
316                 || printf "Could not restore original XenServer $s script.\n"
317         fi
318     done
319
320     # Remove all configuration files
321     rm -f /etc/openvswitch/conf.db
322     rm -f /etc/sysconfig/openvswitch
323     rm -f /etc/openvswitch/vswitchd.cacert
324     rm -f /var/xapi/network.dbcache
325
326     # Configure system to use bridge
327     echo bridge > /etc/xensource/network.conf
328
329     printf "\nYou MUST reboot the server now to complete the change to\n"
330     printf "standard Xen networking.  Attempts to modify networking on the\n"
331     printf "server or any hosted VM will fail until after the reboot and\n"
332     printf "could leave the server in a state requiring manual recovery.\n\n"
333 fi
334
335
336 %files
337 %defattr(-,root,root)
338 /etc/init.d/openvswitch
339 /etc/init.d/openvswitch-xapi-update
340 /etc/xapi.d/plugins/openvswitch-cfg-update
341 /etc/logrotate.d/openvswitch
342 /etc/profile.d/openvswitch.sh
343 /lib/modules/%{xen_version}/kernel/net/openvswitch/openvswitch_mod.ko
344 /lib/modules/%{xen_version}/kernel/net/openvswitch/brcompat_mod.ko
345 %if %(echo '%{xen_version}'|awk -F"." '{if ($3>=18) print 1; else print 0;}')
346 /lib/modules/%{xen_version}/kernel/net/openvswitch/ip_gre_mod.ko
347 %endif
348 /usr/share/openvswitch/scripts/refresh-network-uuids
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/xen-bugtool
355 /usr/share/openvswitch/scripts/XSFeatureVSwitch.py
356 /usr/share/openvswitch/scripts/brctl
357 /usr/share/openvswitch/scripts/sysconfig.template
358 /usr/share/openvswitch/vswitch.ovsschema
359 /usr/sbin/ovs-brcompatd
360 /usr/sbin/ovs-vswitchd
361 /usr/sbin/ovsdb-server
362 /usr/bin/ovs-appctl
363 /usr/bin/ovs-dpctl
364 /usr/bin/ovs-ofctl
365 /usr/bin/ovs-vsctl
366 /usr/bin/ovsdb-client
367 /usr/bin/ovsdb-tool
368 /usr/share/man/man1/ovsdb-client.1.gz
369 /usr/share/man/man1/ovsdb-server.1.gz
370 /usr/share/man/man1/ovsdb-tool.1.gz
371 /usr/share/man/man5/ovs-vswitchd.conf.db.5.gz
372 /usr/share/man/man8/ovs-appctl.8.gz
373 /usr/share/man/man8/ovs-brcompatd.8.gz
374 /usr/share/man/man8/ovs-dpctl.8.gz
375 /usr/share/man/man8/ovs-ofctl.8.gz
376 /usr/share/man/man8/ovs-vsctl.8.gz
377 /usr/share/man/man8/ovs-vswitchd.8.gz
378 /var/lib/openvswitch
379 %exclude /usr/share/openvswitch/scripts/*.pyc
380 %exclude /usr/share/openvswitch/scripts/*.pyo