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