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