Merge citrix into master.
[sliver-openvswitch.git] / xenserver / vswitch-xen.spec
1 # Spec file for vswitch and related programs.
2
3 # Copyright (C) 2009 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 %define _prefix /root/vswitch
18
19 Name: vswitch
20 Summary: Virtual switch
21 Group: System Environment/Daemons
22 URL: http://www.openvswitch.org/
23 Version: %{vswitch_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-%{vswitch_version}.tar.gz
29 Buildroot: /tmp/vswitch-xen-rpm
30 Requires: kernel-xen = %(echo '%{xen_version}' | sed 's/xen$//')
31
32 %description
33 The 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-%{vswitch_version}
39
40 %build
41 ./configure --prefix=%{_prefix} --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 prefix=%{_prefix}
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_vswitch \
50          $RPM_BUILD_ROOT/etc/init.d/vswitch
51 install -m 755 xenserver/etc_init.d_vswitch-xapi-update \
52          $RPM_BUILD_ROOT/etc/init.d/vswitch-xapi-update
53 install -d -m 755 $RPM_BUILD_ROOT/etc/sysconfig
54 install -m 755 xenserver/etc_sysconfig_vswitch.example \
55          $RPM_BUILD_ROOT/etc/sysconfig/vswitch.example
56 install -d -m 755 $RPM_BUILD_ROOT/etc/logrotate.d
57 install -m 755 xenserver/etc_logrotate.d_vswitch \
58          $RPM_BUILD_ROOT/etc/logrotate.d/vswitch
59 install -d -m 755 $RPM_BUILD_ROOT/etc/profile.d
60 install -m 755 xenserver/etc_profile.d_vswitch.sh \
61          $RPM_BUILD_ROOT/etc/profile.d/vswitch.sh
62 install -d -m 755 $RPM_BUILD_ROOT/etc/xapi.d/plugins
63 install -m 755 xenserver/etc_xapi.d_plugins_vswitch-cfg-update \
64          $RPM_BUILD_ROOT/etc/xapi.d/plugins/vswitch-cfg-update
65 install -d -m 755 $RPM_BUILD_ROOT%{_prefix}/scripts
66 install -m 755 xenserver/opt_xensource_libexec_interface-reconfigure \
67              $RPM_BUILD_ROOT%{_prefix}/scripts/interface-reconfigure
68 install -m 755 xenserver/etc_xensource_scripts_vif \
69              $RPM_BUILD_ROOT%{_prefix}/scripts/vif
70 install -m 755 xenserver/root_vswitch_scripts_dump-vif-details \
71                $RPM_BUILD_ROOT%{_prefix}/scripts/dump-vif-details
72 install -m 755 xenserver/usr_sbin_xen-bugtool \
73              $RPM_BUILD_ROOT%{_prefix}/scripts/xen-bugtool
74 install -m 755 xenserver/usr_sbin_brctl \
75              $RPM_BUILD_ROOT%{_prefix}/scripts/brctl
76 install -m 644 \
77         xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py \
78                $RPM_BUILD_ROOT%{_prefix}/scripts/XSFeatureVSwitch.py
79
80 install -d -m 755 $RPM_BUILD_ROOT%{_prefix}/kernel_modules
81 find datapath/linux-2.6 -name *.ko -exec install -m 755  \{\} $RPM_BUILD_ROOT%{_prefix}/kernel_modules/ \;
82
83 # Get rid of stuff we don't want to make RPM happy.
84 rm -rf \
85     $RPM_BUILD_ROOT/root/vswitch/bin/ezio-term \
86     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-controller \
87     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-discover \
88     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-kill \
89     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-openflowd \
90     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-pki \
91     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-switchui \
92     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-wdt \
93     $RPM_BUILD_ROOT/root/vswitch/kernel_modules/veth_mod.ko \
94     $RPM_BUILD_ROOT/root/vswitch/sbin/ovs-monitor \
95     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-controller.8 \
96     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-discover.8 \
97     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-kill.8 \
98     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-openflowd.8 \
99     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-pki.8 \
100     $RPM_BUILD_ROOT/root/vswitch/share/openvswitch
101
102 %clean
103 rm -rf $RPM_BUILD_ROOT
104
105 %pre
106 if [ ! -f /etc/xensource-inventory ]; then
107     printf "XenSource inventory not present in /etc/xensource-inventory"
108     exit 1
109 fi
110
111 if [ "$1" = "1" ]; then
112     if ! md5sum -c --status <<EOF
113 b8e9835862ef1a9cec2a3f477d26c989  /etc/xensource/scripts/vif
114 51970ad613a3996d5997e18e44db47da  /opt/xensource/libexec/interface-reconfigure
115 5654c8c36699fcc8744ca9cd5b855414  /usr/sbin/xen-bugtool
116 EOF
117     then
118         printf "\nThe original XenServer scripts replaced by this package\n"
119         printf "are different than expected.  This could lead to unexpected\n"
120         printf "behavior of your server.  Unless you are sure you know what\n"
121         printf "you are doing, it is highly recommended that you remove this\n"
122         printf "package immediately after the install completes, which\n"
123         printf "will restore the XenServer scripts that you were previously\n"
124         printf "using.\n\n"
125     fi
126     if test "`/usr/sbin/brctl --version`" != "bridge-utils, 1.1"; then
127 cat <<EOF
128
129 /usr/sbin/brctl replaced by this package reports the following version:
130
131 `/usr/sbin/brctl --version`
132
133 The expected version was:
134
135 bridge-utils, 1.1
136
137 Unless you are sure you know what you are doing, it is highly recommended that
138 you remove this package immediately after the install completes, which will
139 restore the original /usr/sbin/brctl.
140
141 EOF
142     fi
143 fi
144
145 if test ! -e /etc/ovs-vswitch.dbcache; then
146     if test "$1" = 1; then
147         printf "Creating xapi database cache...  "
148     else
149         printf "warning: Open vSwitch is being re-installed or upgraded,\n"
150         printf "         but the xapi database cache is missing.\n"
151         printf "Re-creating xapi database cache...  "
152     fi
153
154     source /etc/xensource-inventory
155     if python - "$INSTALLATION_UUID" <<EOF
156 import XenAPI
157 import pickle
158 import sys
159
160 session = XenAPI.xapi_local()
161 try:
162     session.xenapi.login_with_password("root", "")
163
164     vlans = session.xenapi.VLAN.get_all_records()
165     bonds = session.xenapi.Bond.get_all_records()
166     pifs = session.xenapi.PIF.get_all_records()
167     networks = session.xenapi.network.get_all_records()
168     host = session.xenapi.host.get_by_uuid(sys.argv[1])
169 finally:
170     session.xenapi.session.logout()
171
172 dbcache_file = "/etc/ovs-vswitch.dbcache"
173 f = open(dbcache_file, 'w')
174 pickle.dump({'vlans': vlans,
175              'bonds': bonds,
176              'pifs': pifs,
177              'networks': networks}, f)
178 pickle.dump({'host': host}, f)
179 f.close()
180 EOF
181     then
182         printf "done.\n"
183     else
184         printf "FAILED\n"
185         printf "Open vSwitch can only be installed on a XenServer that\n"
186         printf "has connectivity to xapi on the pool master.  Please\n"
187         printf "fix connectivity to the pool master, then try again.\n"
188         exit 1
189     fi
190 fi
191
192 %post
193 if grep -F net.ipv4.conf.all.arp_filter /etc/sysctl.conf >/dev/null 2>&1; then :; else
194     cat >>/etc/sysctl.conf <<EOF
195 # This works around an issue in xhad, which binds to a particular
196 # Ethernet device, which in turn causes ICMP port unreachable messages
197 # if packets are received are on the wrong interface, which in turn
198 # can happen if we send out ARP replies on every interface (as Linux
199 # does by default) instead of just on the interface that has the IP
200 # address being ARPed for, which this sysctl setting in turn works
201 # around.
202 #
203 # Bug #1378.
204 net.ipv4.conf.all.arp_filter = 1
205 EOF
206 fi
207
208 # Ensure ovs-vswitchd.conf exists
209 touch /etc/ovs-vswitchd.conf
210
211 # Replace XenServer files by our versions.
212 mkdir -p %{_prefix}/xs-original \
213     || printf "Could not create script backup directory.\n"
214 for f in \
215     /opt/xensource/libexec/interface-reconfigure \
216     /etc/xensource/scripts/vif \
217     /usr/sbin/xen-bugtool \
218     /usr/sbin/brctl
219 do
220     s=$(basename "$f")
221     t=$(readlink "$f")
222     if [ "$t" != "%{_prefix}/scripts/$s" ]; then
223         mv "$f" %{_prefix}/xs-original/ \
224             || printf "Could not save original XenServer $s script\n"
225         ln -s "%{_prefix}/scripts/$s" "$f" \
226             || printf "Could not link to vSwitch $s script\n"
227     fi
228 done
229
230 # Install xsconsole plugin
231 plugin=$(readlink /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py)
232 if [ "$plugin" != "/root/vswitch/scripts/XSFeatureVSwitch.py" ]; then
233     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
234     ln -s /root/vswitch/scripts/XSFeatureVSwitch.py /usr/lib/xsconsole/plugins-base/ || printf "Could not link to vSswitch xsconsole plugin.\n"
235 fi
236
237 # Ensure all required services are set to run
238 for s in vswitch vswitch-xapi-update; do
239     if chkconfig --list $s >/dev/null 2>&1; then
240         chkconfig --del $s || printf "Could not remove $s init script."
241     fi
242     chkconfig --add $s || printf "Could not add $s init script."
243     chkconfig $s on || printf "Could not enable $s init script."
244 done
245
246 if [ "$1" = "1" ]; then    # $1 = 2 for upgrade
247     printf "\nYou MUST reboot the server NOW to complete the change to the\n"
248     printf "the vSwitch.  Attempts to modify networking on the server\n"
249     printf "or any hosted VM will fail until after the reboot and could\n"
250     printf "leave the server in an state requiring manual recovery.\n\n"
251 else
252     printf "\nTo use the new vSwitch, you should reboot the server\n"
253     printf "now.  Failure to do so may result in incorrect operation.\n\n"
254 fi
255
256 %preun
257 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
258     for s in vswitch vswitch-xapi-update; do
259         chkconfig --del $s || printf "Could not remove $s init script."
260     done
261 fi
262
263
264 %postun
265 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
266
267     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py \
268         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
269         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo \
270         || printf "Could not remove vSwitch xsconsole plugin.\n"
271
272     # Restore original XenServer scripts
273     for f in \
274         /opt/xensource/libexec/interface-reconfigure \
275         /etc/xensource/scripts/vif \
276         /usr/sbin/xen-bugtool \
277         /usr/sbin/brctl
278     do
279         s=$(basename "$f")
280         if [ ! -f "%{_prefix}/xs-original/$s" ]; then
281             printf "Original XenServer $s script not present in %{_prefix}/xs-original\n"
282             printf "Could not restore original XenServer script.\n"
283         else
284             (rm -f "$f" \
285                 && mv "%{_prefix}/xs-original/$s" "$f") \
286                 || printf "Could not restore original XenServer $s script.\n"
287         fi
288     done
289
290     find  %{_prefix} -type d -depth -exec rmdir \{\} \; \
291         || printf "Could not remove vSwitch install directory.\n"
292
293     # Remove all configuration and log files
294     rm -f /etc/ovs-vswitchd.conf
295     rm -f /etc/sysconfig/vswitch
296     rm -f /var/log/vswitch*
297     rm -f /etc/ovs-vswitchd.cacert
298
299     printf "\nYou MUST reboot the server now to complete the change to\n"
300     printf "standard Xen networking.  Attempts to modify networking on the\n"
301     printf "server or any hosted VM will fail until after the reboot and\n"
302     printf "could leave the server in a state requiring manual recovery.\n\n"
303 fi
304
305
306 %files
307 %defattr(-,root,root)
308 /etc/init.d/vswitch
309 /etc/init.d/vswitch-xapi-update
310 /etc/xapi.d/plugins/vswitch-cfg-update
311 /etc/sysconfig/vswitch.example
312 /etc/logrotate.d/vswitch
313 /etc/profile.d/vswitch.sh
314 /root/vswitch/kernel_modules/brcompat_mod.ko
315 /root/vswitch/kernel_modules/openvswitch_mod.ko
316 /root/vswitch/scripts/dump-vif-details
317 /root/vswitch/scripts/interface-reconfigure
318 /root/vswitch/scripts/vif
319 /root/vswitch/scripts/xen-bugtool
320 /root/vswitch/scripts/XSFeatureVSwitch.py
321 /root/vswitch/scripts/brctl
322 # Following two files are generated automatically by rpm.  We don't
323 # really need them and they won't be used on the XenServer, but there
324 # isn't an obvious place to get rid of them since they are generated
325 # after the install script runs.  Since they are small, we just
326 # include them.
327 /root/vswitch/scripts/XSFeatureVSwitch.pyc
328 /root/vswitch/scripts/XSFeatureVSwitch.pyo
329 /root/vswitch/sbin/ovs-brcompatd
330 /root/vswitch/sbin/ovs-vswitchd
331 /root/vswitch/bin/ovs-appctl
332 /root/vswitch/bin/ovs-cfg-mod
333 /root/vswitch/bin/ovs-dpctl
334 /root/vswitch/bin/ovs-ofctl
335 /root/vswitch/share/man/man5/ovs-vswitchd.conf.5
336 /root/vswitch/share/man/man8/ovs-appctl.8
337 /root/vswitch/share/man/man8/ovs-brcompatd.8
338 /root/vswitch/share/man/man8/ovs-cfg-mod.8
339 /root/vswitch/share/man/man8/ovs-dpctl.8
340 /root/vswitch/share/man/man8/ovs-ofctl.8
341 /root/vswitch/share/man/man8/ovs-vswitchd.8