xenserver: Remove support for XenServer versions older than 5.6 FP1.
[openvswitch] / 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/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_ovs-external-ids \
77                $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/ovs-external-ids
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_share_openvswitch_scripts_sysconfig.template \
81          $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/sysconfig.template
82 install -m 755 utilities/ovs-save \
83          $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/ovs-save
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 install xenserver/uuid.py $RPM_BUILD_ROOT/usr/share/openvswitch/python
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/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
106 install -d -m 755 $RPM_BUILD_ROOT/var/lib/openvswitch
107
108 %clean
109 rm -rf $RPM_BUILD_ROOT
110
111 %post
112 if test ! -e /var/xapi/network.dbcache; then
113     if test "$1" = 1; then
114         printf "Creating xapi database cache...  "
115     else
116         printf "warning: Open vSwitch is being re-installed or upgraded,\n"
117         printf "         but the xapi database cache is missing.\n"
118         printf "Re-creating xapi database cache...  "
119     fi
120
121     if /usr/share/openvswitch/scripts/interface-reconfigure rewrite; then
122         printf "done.\n"
123     else
124         printf "FAILED\n"
125         printf "Open vSwitch can only be installed on a XenServer that\n"
126         printf "has connectivity to xapi on the pool master.  Please\n"
127         printf "fix connectivity to the pool master, then try again.\n"
128         exit 1
129     fi
130 fi
131
132 # Ensure that modprobe will find our modules.
133 depmod %{xen_version}
134
135 if grep -F net.ipv4.conf.all.arp_filter /etc/sysctl.conf >/dev/null 2>&1; then :; else
136     cat >>/etc/sysctl.conf <<EOF
137 # This works around an issue in xhad, which binds to a particular
138 # Ethernet device, which in turn causes ICMP port unreachable messages
139 # if packets are received are on the wrong interface, which in turn
140 # can happen if we send out ARP replies on every interface (as Linux
141 # does by default) instead of just on the interface that has the IP
142 # address being ARPed for, which this sysctl setting in turn works
143 # around.
144 #
145 # Bug #1378.
146 net.ipv4.conf.all.arp_filter = 1
147 EOF
148 fi
149
150 if test ! -e /etc/openvswitch/conf.db; then
151     install -d -m 755 -o root -g root /etc/openvswitch
152
153     # Create ovs-vswitchd config database
154     ovsdb-tool -vANY:console:emer create /etc/openvswitch/conf.db \
155             /usr/share/openvswitch/vswitch.ovsschema
156
157     # Create initial table in config database
158     ovsdb-tool -vANY:console:emer transact /etc/openvswitch/conf.db \
159             '[{"op": "insert", "table": "Open_vSwitch", "row": {}}]' \
160             > /dev/null
161 fi
162
163 # Create default or update existing /etc/sysconfig/openvswitch.
164 SYSCONFIG=/etc/sysconfig/openvswitch
165 TEMPLATE=/usr/share/openvswitch/scripts/sysconfig.template
166 if [ ! -e $SYSCONFIG ]; then
167     cp $TEMPLATE $SYSCONFIG
168 else
169     for var in $(awk -F'[ :]' '/^# [_A-Z0-9]+:/{print $2}' $TEMPLATE)
170     do
171         if ! grep $var $SYSCONFIG >/dev/null 2>&1; then
172             echo >> $SYSCONFIG
173             sed -n "/$var:/,/$var=/p" $TEMPLATE >> $SYSCONFIG
174         fi
175     done
176 fi
177
178 # Replace XenServer files by our versions.
179 mkdir -p /usr/lib/openvswitch/xs-original \
180     || printf "Could not create script backup directory.\n"
181 for f in \
182     /opt/xensource/libexec/interface-reconfigure \
183     /opt/xensource/libexec/InterfaceReconfigure.py \
184     /opt/xensource/libexec/InterfaceReconfigureBridge.py \
185     /opt/xensource/libexec/InterfaceReconfigureVswitch.py \
186     /etc/xensource/scripts/vif \
187     /usr/sbin/xen-bugtool
188 do
189     s=$(basename "$f")
190     t=$(readlink "$f")
191     if [ -f "$f" ] && [ "$t" != "/usr/share/openvswitch/scripts/$s" ]; then
192         mv "$f" /usr/lib/openvswitch/xs-original/ \
193             || printf "Could not save original XenServer $s script\n"
194         ln -s "/usr/share/openvswitch/scripts/$s" "$f" \
195             || printf "Could not link to Open vSwitch $s script\n"
196     fi
197 done
198
199 # Ensure all required services are set to run
200 for s in openvswitch openvswitch-xapi-update; do
201     if chkconfig --list $s >/dev/null 2>&1; then
202         chkconfig --del $s || printf "Could not remove $s init script."
203     fi
204     chkconfig --add $s || printf "Could not add $s init script."
205     chkconfig $s on || printf "Could not enable $s init script."
206 done
207
208 # Configure system to use Open vSwitch
209 echo vswitch > /etc/xensource/network.conf
210
211 if [ "$1" = "1" ]; then    # $1 = 2 for upgrade
212     printf "\nYou MUST reboot the server NOW to complete the change to\n"
213     printf "Open vSwitch.  Attempts to modify networking on the server\n"
214     printf "or any hosted VM will fail until after the reboot and could\n"
215     printf "leave the server in an state requiring manual recovery.\n\n"
216 else
217     printf "\nTo use the new Open vSwitch install, you should reboot the\n" 
218     printf "server now.  Failure to do so may result in incorrect operation."
219     printf "\n\n"
220 fi
221
222 %preun
223 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
224     for s in openvswitch openvswitch-xapi-update; do
225         chkconfig --del $s || printf "Could not remove $s init script."
226     done
227 fi
228
229
230 %postun
231 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
232     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
233         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo
234
235     rm -f /usr/share/openvswitch/scripts/InterfaceReconfigure.pyc \
236         /usr/share/openvswitch/scripts/InterfaceReconfigure.pyo \
237         /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyc \
238         /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyo \
239         /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyc \
240         /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyo 
241
242     # Restore original XenServer scripts
243     for f in \
244         /opt/xensource/libexec/interface-reconfigure \
245         /opt/xensource/libexec/InterfaceReconfigure.py \
246         /opt/xensource/libexec/InterfaceReconfigureBridge.py \
247         /opt/xensource/libexec/InterfaceReconfigureVswitch.py \
248         /etc/xensource/scripts/vif \
249         /usr/sbin/xen-bugtool
250     do
251         s=$(basename "$f")
252         if [ ! -f "/usr/lib/openvswitch/xs-original/$s" ]; then
253             printf "Original XenServer $s script not present in /usr/lib/openvswitch/xs-original\n"
254             printf "Could not restore original XenServer script.\n"
255         else
256             (rm -f "$f" \
257                 && mv "/usr/lib/openvswitch/xs-original/$s" "$f") \
258                 || printf "Could not restore original XenServer $s script.\n"
259         fi
260     done
261
262     # Remove all configuration files
263     rm -f /etc/openvswitch/conf.db
264     rm -f /etc/sysconfig/openvswitch
265     rm -f /etc/openvswitch/vswitchd.cacert
266     rm -f /var/xapi/network.dbcache
267
268     # Configure system to use bridge
269     echo bridge > /etc/xensource/network.conf
270
271     printf "\nYou MUST reboot the server now to complete the change to\n"
272     printf "standard Xen networking.  Attempts to modify networking on the\n"
273     printf "server or any hosted VM will fail until after the reboot and\n"
274     printf "could leave the server in a state requiring manual recovery.\n\n"
275 fi
276
277
278 %files
279 %defattr(-,root,root)
280 /etc/init.d/openvswitch
281 /etc/init.d/openvswitch-xapi-update
282 /etc/xapi.d/plugins/openvswitch-cfg-update
283 /etc/logrotate.d/openvswitch
284 /etc/profile.d/openvswitch.sh
285 /lib/modules/%{xen_version}/kernel/extra/openvswitch/openvswitch_mod.ko
286 /usr/share/openvswitch/python/ovs/__init__.py
287 /usr/share/openvswitch/python/ovs/daemon.py
288 /usr/share/openvswitch/python/ovs/db/__init__.py
289 /usr/share/openvswitch/python/ovs/db/data.py
290 /usr/share/openvswitch/python/ovs/db/error.py
291 /usr/share/openvswitch/python/ovs/db/idl.py
292 /usr/share/openvswitch/python/ovs/db/parser.py
293 /usr/share/openvswitch/python/ovs/db/schema.py
294 /usr/share/openvswitch/python/ovs/db/types.py
295 /usr/share/openvswitch/python/ovs/dirs.py
296 /usr/share/openvswitch/python/ovs/fatal_signal.py
297 /usr/share/openvswitch/python/ovs/json.py
298 /usr/share/openvswitch/python/ovs/jsonrpc.py
299 /usr/share/openvswitch/python/ovs/ovsuuid.py
300 /usr/share/openvswitch/python/ovs/poller.py
301 /usr/share/openvswitch/python/ovs/process.py
302 /usr/share/openvswitch/python/ovs/reconnect.py
303 /usr/share/openvswitch/python/ovs/socket_util.py
304 /usr/share/openvswitch/python/ovs/stream.py
305 /usr/share/openvswitch/python/ovs/timeval.py
306 /usr/share/openvswitch/python/ovs/util.py
307 /usr/share/openvswitch/python/uuid.py
308 /usr/share/openvswitch/scripts/ovs-external-ids
309 /usr/share/openvswitch/scripts/interface-reconfigure
310 /usr/share/openvswitch/scripts/InterfaceReconfigure.py
311 /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
312 /usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
313 /usr/share/openvswitch/scripts/vif
314 /usr/share/openvswitch/scripts/xen-bugtool
315 /usr/share/openvswitch/scripts/sysconfig.template
316 /usr/share/openvswitch/scripts/ovs-save
317 /usr/share/openvswitch/vswitch.ovsschema
318 /usr/sbin/ovs-vswitchd
319 /usr/sbin/ovsdb-server
320 /usr/bin/ovs-appctl
321 /usr/bin/ovs-dpctl
322 /usr/bin/ovs-ofctl
323 /usr/bin/ovs-pcap
324 /usr/bin/ovs-tcpundump
325 /usr/bin/ovs-vlan-test
326 /usr/bin/ovs-vsctl
327 /usr/bin/ovsdb-client
328 /usr/bin/ovsdb-tool
329 /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
330 /usr/share/man/man1/ovsdb-client.1.gz
331 /usr/share/man/man1/ovsdb-server.1.gz
332 /usr/share/man/man1/ovsdb-tool.1.gz
333 /usr/share/man/man5/ovs-vswitchd.conf.db.5.gz
334 /usr/share/man/man8/ovs-appctl.8.gz
335 /usr/share/man/man8/ovs-dpctl.8.gz
336 /usr/share/man/man8/ovs-ofctl.8.gz
337 /usr/share/man/man8/ovs-parse-leaks.8.gz
338 /usr/share/man/man1/ovs-pcap.1.gz
339 /usr/share/man/man1/ovs-tcpundump.1.gz
340 /usr/share/man/man8/ovs-vlan-test.8.gz
341 /usr/share/man/man8/ovs-vsctl.8.gz
342 /usr/share/man/man8/ovs-vswitchd.8.gz
343 /var/lib/openvswitch
344 %exclude /lib/modules/%{xen_version}/kernel/extra/openvswitch/brcompat_mod.ko
345 %exclude /usr/lib/xsconsole/plugins-base/*.py[co]
346 %exclude /usr/sbin/ovs-brcompatd
347 %exclude /usr/share/man/man8/ovs-brcompatd.8.gz
348 %exclude /usr/share/openvswitch/scripts/*.py[co]
349 %exclude /usr/share/openvswitch/python/*.py[co]
350 %exclude /usr/share/openvswitch/python/ovs/*.py[co]
351 %exclude /usr/share/openvswitch/python/ovs/db/*.py[co]