xenserver: Replace customized xen-bugtool with plugin to collect qdisc info.
[sliver-openvswitch.git] / xenserver / openvswitch-xen.spec
1 # Spec file for Open vSwitch.
2
3 # Copyright (C) 2009, 2010, 2011 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/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
88 install -m 644 \
89         xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py \
90                $RPM_BUILD_ROOT/usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
91
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
95
96 # Get rid of stuff we don't want to make RPM happy.
97 rm \
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
108
109 install -d -m 755 $RPM_BUILD_ROOT/var/lib/openvswitch
110
111 %clean
112 rm -rf $RPM_BUILD_ROOT
113
114 %post
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...  "
120         else
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...  "
124         fi
125
126         if /usr/share/openvswitch/scripts/interface-reconfigure rewrite; then
127             printf "done.\n"
128         else
129             printf "FAILED\n"
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"
133             exit 1
134         fi
135     fi
136 fi
137
138 # Ensure that modprobe will find our modules.
139 depmod %{xen_version}
140
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
149 # around.
150 #
151 # Bug #1378.
152 net.ipv4.conf.all.arp_filter = 1
153 EOF
154 fi
155
156 if test ! -e /etc/openvswitch/conf.db; then
157     install -d -m 755 -o root -g root /etc/openvswitch
158
159     # Create ovs-vswitchd config database
160     ovsdb-tool -vANY:console:emer create /etc/openvswitch/conf.db \
161             /usr/share/openvswitch/vswitch.ovsschema
162
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": {}}]' \
166             > /dev/null
167 fi
168
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
174 else
175     for var in $(awk -F'[ :]' '/^# [_A-Z0-9]+:/{print $2}' $TEMPLATE)
176     do
177         if ! grep $var $SYSCONFIG >/dev/null 2>&1; then
178             echo >> $SYSCONFIG
179             sed -n "/$var:/,/$var=/p" $TEMPLATE >> $SYSCONFIG
180         fi
181     done
182 fi
183
184 # Replace XenServer files by our versions.
185 mkdir -p /usr/lib/openvswitch/xs-original \
186     || printf "Could not create script backup directory.\n"
187 for f in \
188     /opt/xensource/libexec/interface-reconfigure \
189     /opt/xensource/libexec/InterfaceReconfigure.py \
190     /opt/xensource/libexec/InterfaceReconfigureBridge.py \
191     /opt/xensource/libexec/InterfaceReconfigureVswitch.py \
192     /etc/xensource/scripts/vif
193 do
194     s=$(basename "$f")
195     t=$(readlink "$f")
196     if [ -f "$f" ] && [ "$t" != "/usr/share/openvswitch/scripts/$s" ]; then
197         mv "$f" /usr/lib/openvswitch/xs-original/ \
198             || printf "Could not save original XenServer $s script\n"
199         ln -s "/usr/share/openvswitch/scripts/$s" "$f" \
200             || printf "Could not link to Open vSwitch $s script\n"
201     fi
202 done
203
204 # Bug #4667: one-time cleanup of brctl removal in commit 54f16a10
205 # (xenserver: Remove brctl wrapper script).
206 if [ -h /usr/sbin/brctl ] &&
207     [ "$(readlink /usr/sbin/brctl)" = /usr/share/openvswitch/scripts/brctl ]; then
208     mv -f /usr/lib/openvswitch/xs-original/brctl /usr/sbin/
209 fi
210
211 # Ensure all required services are set to run
212 for s in openvswitch openvswitch-xapi-update; do
213     if chkconfig --list $s >/dev/null 2>&1; then
214         chkconfig --del $s || printf "Could not remove $s init script."
215     fi
216     chkconfig --add $s || printf "Could not add $s init script."
217     chkconfig $s on || printf "Could not enable $s init script."
218 done
219
220 # Configure system to use Open vSwitch
221 echo vswitch > /etc/xensource/network.conf
222
223 if [ "$1" = "1" ]; then    # $1 = 2 for upgrade
224     printf "\nYou MUST reboot the server NOW to complete the change to\n"
225     printf "Open vSwitch.  Attempts to modify networking on the server\n"
226     printf "or any hosted VM will fail until after the reboot and could\n"
227     printf "leave the server in an state requiring manual recovery.\n\n"
228 else
229     printf "\nTo use the new Open vSwitch install, you should reboot the\n" 
230     printf "server now.  Failure to do so may result in incorrect operation."
231     printf "\n\n"
232 fi
233
234 %preun
235 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
236     for s in openvswitch openvswitch-xapi-update; do
237         chkconfig --del $s || printf "Could not remove $s init script."
238     done
239 fi
240
241
242 %postun
243 rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
244     /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo
245
246 rm -f /usr/share/openvswitch/scripts/InterfaceReconfigure.pyc \
247     /usr/share/openvswitch/scripts/InterfaceReconfigure.pyo \
248     /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyc \
249     /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyo \
250     /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyc \
251     /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyo 
252
253 # Restore original XenServer scripts
254 for f in \
255     /opt/xensource/libexec/interface-reconfigure \
256     /opt/xensource/libexec/InterfaceReconfigure.py \
257     /opt/xensource/libexec/InterfaceReconfigureBridge.py \
258     /opt/xensource/libexec/InterfaceReconfigureVswitch.py \
259     /etc/xensource/scripts/vif
260 do
261     s=$(basename "$f")
262     if [ ! -f "/usr/lib/openvswitch/xs-original/$s" ]; then
263         printf "Original XenServer $s script not present in /usr/lib/openvswitch/xs-original\n"
264         printf "Could not restore original XenServer script.\n"
265     else
266         (rm -f "$f" \
267             && mv "/usr/lib/openvswitch/xs-original/$s" "$f") \
268             || printf "Could not restore original XenServer $s script.\n"
269     fi
270 done
271
272 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
273     # Remove all configuration files
274     rm -f /etc/openvswitch/conf.db
275     rm -f /etc/sysconfig/openvswitch
276     rm -f /etc/openvswitch/vswitchd.cacert
277     rm -f /var/xapi/network.dbcache
278
279     # Configure system to use bridge
280     echo bridge > /etc/xensource/network.conf
281
282     printf "\nYou MUST reboot the server now to complete the change to\n"
283     printf "standard Xen networking.  Attempts to modify networking on the\n"
284     printf "server or any hosted VM will fail until after the reboot and\n"
285     printf "could leave the server in a state requiring manual recovery.\n\n"
286 fi
287
288 %files
289 %defattr(-,root,root)
290 /etc/init.d/openvswitch
291 /etc/init.d/openvswitch-xapi-update
292 /etc/xapi.d/plugins/openvswitch-cfg-update
293 /etc/xensource/bugtool/network-status/openvswitch.xml
294 /etc/logrotate.d/openvswitch
295 /etc/profile.d/openvswitch.sh
296 /lib/modules/%{xen_version}/kernel/extra/openvswitch/openvswitch_mod.ko
297 /usr/share/openvswitch/python/ovs/__init__.py
298 /usr/share/openvswitch/python/ovs/daemon.py
299 /usr/share/openvswitch/python/ovs/db/__init__.py
300 /usr/share/openvswitch/python/ovs/db/data.py
301 /usr/share/openvswitch/python/ovs/db/error.py
302 /usr/share/openvswitch/python/ovs/db/idl.py
303 /usr/share/openvswitch/python/ovs/db/parser.py
304 /usr/share/openvswitch/python/ovs/db/schema.py
305 /usr/share/openvswitch/python/ovs/db/types.py
306 /usr/share/openvswitch/python/ovs/dirs.py
307 /usr/share/openvswitch/python/ovs/fatal_signal.py
308 /usr/share/openvswitch/python/ovs/json.py
309 /usr/share/openvswitch/python/ovs/jsonrpc.py
310 /usr/share/openvswitch/python/ovs/ovsuuid.py
311 /usr/share/openvswitch/python/ovs/poller.py
312 /usr/share/openvswitch/python/ovs/process.py
313 /usr/share/openvswitch/python/ovs/reconnect.py
314 /usr/share/openvswitch/python/ovs/socket_util.py
315 /usr/share/openvswitch/python/ovs/stream.py
316 /usr/share/openvswitch/python/ovs/timeval.py
317 /usr/share/openvswitch/python/ovs/util.py
318 /usr/share/openvswitch/python/uuid.py
319 /usr/share/openvswitch/scripts/ovs-xapi-sync
320 /usr/share/openvswitch/scripts/interface-reconfigure
321 /usr/share/openvswitch/scripts/InterfaceReconfigure.py
322 /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
323 /usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
324 /usr/share/openvswitch/scripts/vif
325 /usr/share/openvswitch/scripts/sysconfig.template
326 /usr/share/openvswitch/scripts/xen-bugtool-tc-class-show
327 /usr/share/openvswitch/scripts/ovs-save
328 /usr/share/openvswitch/vswitch.ovsschema
329 /usr/sbin/ovs-vswitchd
330 /usr/sbin/ovsdb-server
331 /usr/bin/ovs-appctl
332 /usr/bin/ovs-dpctl
333 /usr/bin/ovs-ofctl
334 /usr/bin/ovs-pcap
335 /usr/bin/ovs-tcpundump
336 /usr/bin/ovs-vlan-test
337 /usr/bin/ovs-vsctl
338 /usr/bin/ovsdb-client
339 /usr/bin/ovsdb-tool
340 /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
341 /usr/share/man/man1/ovsdb-client.1.gz
342 /usr/share/man/man1/ovsdb-server.1.gz
343 /usr/share/man/man1/ovsdb-tool.1.gz
344 /usr/share/man/man5/ovs-vswitchd.conf.db.5.gz
345 /usr/share/man/man8/ovs-appctl.8.gz
346 /usr/share/man/man8/ovs-dpctl.8.gz
347 /usr/share/man/man8/ovs-ofctl.8.gz
348 /usr/share/man/man8/ovs-parse-leaks.8.gz
349 /usr/share/man/man1/ovs-pcap.1.gz
350 /usr/share/man/man1/ovs-tcpundump.1.gz
351 /usr/share/man/man8/ovs-vlan-test.8.gz
352 /usr/share/man/man8/ovs-vsctl.8.gz
353 /usr/share/man/man8/ovs-vswitchd.8.gz
354 /var/lib/openvswitch
355 %exclude /lib/modules/%{xen_version}/kernel/extra/openvswitch/brcompat_mod.ko
356 %exclude /usr/lib/xsconsole/plugins-base/*.py[co]
357 %exclude /usr/sbin/ovs-brcompatd
358 %exclude /usr/share/man/man8/ovs-brcompatd.8.gz
359 %exclude /usr/share/openvswitch/scripts/*.py[co]
360 %exclude /usr/share/openvswitch/python/*.py[co]
361 %exclude /usr/share/openvswitch/python/ovs/*.py[co]
362 %exclude /usr/share/openvswitch/python/ovs/db/*.py[co]