Merge commit 'origin/citrix'
[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/kernel_modules/veth_mod.ko \
88     $RPM_BUILD_ROOT/root/vswitch/sbin/ovs-monitor \
89     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-controller.8 \
90     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-discover.8 \
91     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-kill.8 \
92     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-pki.8 \
93     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/secchan.8 \
94     $RPM_BUILD_ROOT/root/vswitch/share/openvswitch
95
96 %clean
97 rm -rf $RPM_BUILD_ROOT
98
99 %pre
100 if [ ! -f /etc/xensource-inventory ]; then
101     printf "XenSource inventory not present in /etc/xensource-inventory"
102     exit 1
103 fi
104
105 if [ "$1" = "1" ]; then
106     if ! md5sum -c --status <<EOF
107 b8e9835862ef1a9cec2a3f477d26c989  /etc/xensource/scripts/vif
108 51970ad613a3996d5997e18e44db47da  /opt/xensource/libexec/interface-reconfigure
109 EOF
110     then
111         printf "\nThe original XenServer scripts replaced by this package\n"
112         printf "are different than expected.  This could lead to unexpected\n"
113         printf "behavior of your server.  Unless you are sure you know what\n"
114         printf "you are doing, it is highly recomended that you remove this\n"
115         printf "package immediately after the install completes, which\n"
116         printf "will restore the XenServer scripts that you were previously\n"
117         printf "using.\n\n"
118     fi
119 fi
120
121 if test ! -e /etc/ovs-vswitch.dbcache; then
122     if test "$1" = 1; then
123         printf "Creating xapi database cache...  "
124     else
125         printf "warning: Open vSwitch is being re-installed or upgraded,\n"
126         printf "         but the xapi database cache is missing.\n"
127         printf "Re-creating xapi database cache...  "
128     fi
129
130     source /etc/xensource-inventory
131     if python - "$INSTALLATION_UUID" <<EOF
132 import XenAPI
133 import pickle
134 import sys
135
136 session = XenAPI.xapi_local()
137 try:
138     session.xenapi.login_with_password("root", "")
139
140     vlans = session.xenapi.VLAN.get_all_records()
141     bonds = session.xenapi.Bond.get_all_records()
142     pifs = session.xenapi.PIF.get_all_records()
143     networks = session.xenapi.network.get_all_records()
144     host = session.xenapi.host.get_by_uuid(sys.argv[1])
145 finally:
146     session.xenapi.session.logout()
147
148 dbcache_file = "/etc/ovs-vswitch.dbcache"
149 f = open(dbcache_file, 'w')
150 pickle.dump({'vlans': vlans,
151              'bonds': bonds,
152              'pifs': pifs,
153              'networks': networks}, f)
154 pickle.dump({'host': host}, f)
155 f.close()
156 EOF
157     then
158         printf "done.\n"
159     else
160         printf "FAILED\n"
161         printf "Open vSwitch can only be installed on a XenServer that\n"
162         printf "has connectivity to xapi on the pool master.  Please\n"
163         printf "fix connectivity to the pool master, then try again.\n"
164         exit 1
165     fi
166 fi
167
168 %post
169 source /etc/xensource-inventory
170
171 xe host-param-set \
172     "other-config:vSwitchVersion=%{version}" uuid="$INSTALLATION_UUID" ||
173     echo "Could not set vSwitchVersion config parameter"
174
175 # Ensure ovs-vswitchd.conf exists
176 touch /etc/ovs-vswitchd.conf
177
178 # Replace original XenServer files
179 mkdir -p %{_prefix}/xs-original \
180     || printf "Could not create script backup directory.\n"
181 for f in \
182     /opt/xensource/libexec/interface-reconfigure \
183     /etc/xensource/scripts/vif
184 do
185     s=$(basename "$f")
186     t=$(readlink "$f")
187     if [ "$t" != "%{_prefix}/scripts/$s" ]; then
188         mv "$f" %{_prefix}/xs-original/ \
189             || printf "Could not save original XenServer $s script\n"
190         ln -s "%{_prefix}/scripts/$s" "$f" \
191             || printf "Could not link to vSwitch $s script\n"
192     fi
193 done
194
195 # Install xsconsole plugin
196 plugin=$(readlink /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py)
197 if [ "$plugin" != "/root/vswitch/scripts/XSFeatureVSwitch.py" ]; then
198     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
199     ln -s /root/vswitch/scripts/XSFeatureVSwitch.py /usr/lib/xsconsole/plugins-base/ || printf "Could not link to vSswitch xsconsole plugin.\n"
200 fi
201
202 # Ensure all required services are set to run
203 for s in vswitch vswitch-xapi-update; do
204     if chkconfig --list $s >/dev/null 2>&1; then
205         chkconfig --del $s || printf "Could not remove $s init script."
206     fi
207     chkconfig --add $s || printf "Could not add $s init script."
208     chkconfig $s on || printf "Could not enable $s init script."
209 done
210
211 if [ "$1" = "1" ]; then    # $1 = 2 for upgrade
212     printf "\nYou MUST reboot the server NOW to complete the change to the\n"
213     printf "the 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 vSwitch, you should reboot the server\n"
218     printf "now.  Failure to do so may result in incorrect operation.\n\n"
219 fi
220
221 %preun
222 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
223     for s in vswitch vswitch-xapi-update; do
224         chkconfig --del $s || printf "Could not remove $s init script."
225     done
226 fi
227
228
229 %postun
230 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
231
232     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py \
233         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
234         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo \
235         || printf "Could not remove vSwitch xsconsole plugin.\n"
236
237     # Restore original XenServer scripts
238     for f in \
239         /opt/xensource/libexec/interface-reconfigure \
240         /etc/xensource/scripts/vif
241     do
242         s=$(basename "$f")
243         if [ ! -f "%{_prefix}/xs-original/$s" ]; then
244             printf "Original XenServer $s script not present in %{_prefix}/xs-original\n"
245             printf "Could not restore original XenServer script.\n"
246         else
247             (rm -f "$f" \
248                 && mv "%{_prefix}/xs-original/$s" "$f") \
249                 || printf "Could not restore original XenServer $s script.\n"
250         fi
251     done
252
253     find  %{_prefix} -type d -depth -exec rmdir \{\} \; \
254         || printf "Could not remove vSwitch install directory.\n"
255
256     # Remove all configuration and log files
257     rm -f /etc/ovs-vswitchd.conf
258     rm -f /etc/sysconfig/vswitch
259     rm -f /var/log/vswitch*
260     rm -f /etc/ovs-vswitchd.cacert
261
262     if [ ! -f /etc/xensource-inventory ]; then
263         printf "XenSource inventory not present in /etc/xensource-inventory\n"
264         printf "Could not remove vSwitchVersion from XAPI database.\n"
265         exit 1
266     else
267         source /etc/xensource-inventory
268         xe host-param-remove \
269             param-name=other-config param-key=vSwitchVersion \
270             uuid="$INSTALLATION_UUID" ||
271             echo "Could not clear vSwitchVersion config parameter."
272     fi
273
274     printf "\nYou MUST reboot the server now to complete the change to\n"
275     printf "standard Xen networking.  Attempts to modify networking on the\n"
276     printf "server or any hosted VM will fail until after the reboot and\n"
277     printf "could leave the server in a state requiring manual recovery.\n\n"
278 fi
279
280
281 %files
282 %defattr(-,root,root)
283 /etc/init.d/vswitch
284 /etc/init.d/vswitch-xapi-update
285 /etc/xapi.d/plugins/vswitch-cfg-update
286 /etc/sysconfig/vswitch.example
287 /etc/logrotate.d/vswitch
288 /etc/profile.d/vswitch.sh
289 /root/vswitch/kernel_modules/brcompat_mod.ko
290 /root/vswitch/kernel_modules/openvswitch_mod.ko
291 /root/vswitch/scripts/dump-vif-details
292 /root/vswitch/scripts/interface-reconfigure
293 /root/vswitch/scripts/vif
294 /root/vswitch/scripts/XSFeatureVSwitch.py
295 # Following two files are generated automatically by rpm.  We don't
296 # really need them and they won't be used on the XenServer, but there
297 # isn't an obvious place to get rid of them since they are generated
298 # after the install script runs.  Since they are small, we just
299 # include them.
300 /root/vswitch/scripts/XSFeatureVSwitch.pyc
301 /root/vswitch/scripts/XSFeatureVSwitch.pyo
302 /root/vswitch/sbin/ovs-brcompatd
303 /root/vswitch/sbin/ovs-vswitchd
304 /root/vswitch/bin/ovs-appctl
305 /root/vswitch/bin/ovs-cfg-mod
306 /root/vswitch/bin/ovs-dpctl
307 /root/vswitch/bin/ovs-ofctl
308 /root/vswitch/share/man/man5/ovs-vswitchd.conf.5
309 /root/vswitch/share/man/man8/ovs-appctl.8
310 /root/vswitch/share/man/man8/ovs-brcompatd.8
311 /root/vswitch/share/man/man8/ovs-cfg-mod.8
312 /root/vswitch/share/man/man8/ovs-dpctl.8
313 /root/vswitch/share/man/man8/ovs-ofctl.8
314 /root/vswitch/share/man/man8/ovs-vswitchd.8