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