73e31bdfe02fa8908045e899f8d78ed9441634dc
[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.vswitch.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 \
69         xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py \
70                $RPM_BUILD_ROOT%{_prefix}/scripts/XSFeatureVSwitch.py
71
72 install -d -m 755 $RPM_BUILD_ROOT%{_prefix}/kernel_modules
73 find datapath/linux-2.6 -name *.ko -exec install -m 755  \{\} $RPM_BUILD_ROOT%{_prefix}/kernel_modules/ \;
74
75 # Get rid of stuff we don't want to make RPM happy.
76 rm -rf \
77     $RPM_BUILD_ROOT/root/vswitch/bin/ezio-term \
78     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-controller \
79     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-discover \
80     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-kill \
81     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-pki \
82     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-switchui \
83     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-wdt \
84     $RPM_BUILD_ROOT/root/vswitch/bin/secchan \
85     $RPM_BUILD_ROOT/root/vswitch/sbin/ovs-monitor \
86     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-controller.8 \
87     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-discover.8 \
88     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-kill.8 \
89     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-pki.8 \
90     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/secchan.8 \
91     $RPM_BUILD_ROOT/root/vswitch/share/openvswitch
92
93 %clean
94 rm -rf $RPM_BUILD_ROOT
95
96 %pre
97 if [ ! -f /etc/xensource-inventory ]; then
98     printf "XenSource inventory not present in /etc/xensource-inventory"
99     exit 1
100 fi
101
102 if [ "$1" = "1" ]; then
103     if ! md5sum -c --status <<EOF
104 b8e9835862ef1a9cec2a3f477d26c989  /etc/xensource/scripts/vif
105 51970ad613a3996d5997e18e44db47da  /opt/xensource/libexec/interface-reconfigure
106 EOF
107     then
108         printf "\nThe original XenServer scripts replaced by this package\n"
109         printf "are different than expected.  This could lead to unexpected\n"
110         printf "behavior of your server.  Unless you are sure you know what\n"
111         printf "you are doing, it is highly recomended that you remove this\n"
112         printf "package immediately after the install completes, which\n"
113         printf "will restore the XenServer scripts that you were previously\n"
114         printf "using.\n\n"
115     fi
116 fi
117
118 if test ! -e /etc/ovs-vswitch.dbcache; then
119     if test "$1" = 1; then
120         printf "Creating xapi database cache...  "
121     else
122         printf "warning: Open vSwitch is being re-installed or upgraded,\n"
123         printf "         but the xapi database cache is missing.\n"
124         printf "Re-creating xapi database cache...  "
125     fi
126
127     source /etc/xensource-inventory
128     if python - "$INSTALLATION_UUID" <<EOF
129 import XenAPI
130 import pickle
131 import sys
132
133 session = XenAPI.xapi_local()
134 try:
135     session.xenapi.login_with_password("root", "")
136
137     vlans = session.xenapi.VLAN.get_all_records()
138     bonds = session.xenapi.Bond.get_all_records()
139     pifs = session.xenapi.PIF.get_all_records()
140     networks = session.xenapi.network.get_all_records()
141     host = session.xenapi.host.get_by_uuid(sys.argv[1])
142 finally:
143     session.xenapi.session.logout()
144
145 dbcache_file = "/etc/ovs-vswitch.dbcache"
146 f = open(dbcache_file, 'w')
147 pickle.dump({'vlans': vlans,
148              'bonds': bonds,
149              'pifs': pifs,
150              'networks': networks}, f)
151 pickle.dump({'host': host}, f)
152 f.close()
153 EOF
154     then
155         printf "done.\n"
156     else
157         printf "FAILED\n"
158         printf "Open vSwitch can only be installed on a XenServer that\n"
159         printf "has connectivity to xapi on the pool master.  Please\n"
160         printf "fix connectivity to the pool master, then try again.\n"
161         exit 1
162     fi
163 fi
164
165 %post
166 source /etc/xensource-inventory
167
168 xe host-param-set \
169     "other-config:vSwitchVersion=%{version}" uuid="$INSTALLATION_UUID" ||
170     echo "Could not set vSwitchVersion config parameter"
171
172 # Ensure ovs-vswitchd.conf exists
173 touch /etc/ovs-vswitchd.conf
174
175 # Replace original XenServer files
176 mkdir -p %{_prefix}/xs-original \
177     || printf "Could not create script backup directory.\n"
178 for f in \
179     /opt/xensource/libexec/interface-reconfigure \
180     /etc/xensource/scripts/vif
181 do
182     s=$(basename "$f")
183     t=$(readlink "$f")
184     if [ "$t" != "%{_prefix}/scripts/$s" ]; then
185         mv "$f" %{_prefix}/xs-original/ \
186             || printf "Could not save original XenServer $s script\n"
187         ln -s "%{_prefix}/scripts/$s" "$f" \
188             || printf "Could not link to vSwitch $s script\n"
189     fi
190 done
191
192 # Install xsconsole plugin
193 plugin=$(readlink /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py)
194 if [ "$plugin" != "/root/vswitch/scripts/XSFeatureVSwitch.py" ]; then
195     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
196     ln -s /root/vswitch/scripts/XSFeatureVSwitch.py /usr/lib/xsconsole/plugins-base/ || printf "Could not link to vSswitch xsconsole plugin.\n"
197 fi
198
199 # Ensure all required services are set to run
200 for s in vswitch vswitch-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 if [ "$1" = "1" ]; then    # $1 = 2 for upgrade
209     printf "\nYou MUST reboot the server NOW to complete the change to the\n"
210     printf "the vSwitch.  Attempts to modify networking on the server\n"
211     printf "or any hosted VM will fail until after the reboot and could\n"
212     printf "leave the server in an state requiring manual recovery.\n\n"
213 else
214     printf "\nTo use the new vSwitch, you should reboot the server\n"
215     printf "now.  Failure to do so may result in incorrect operation.\n\n"
216 fi
217
218 %preun
219 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
220     for s in vswitch vswitch-xapi-update; do
221         chkconfig --del $s || printf "Could not remove $s init script."
222     done
223 fi
224
225
226 %postun
227 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
228
229     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py \
230         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
231         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo \
232         || printf "Could not remove vSwitch xsconsole plugin.\n"
233
234     # Restore original XenServer scripts
235     for f in \
236         /opt/xensource/libexec/interface-reconfigure \
237         /etc/xensource/scripts/vif
238     do
239         s=$(basename "$f")
240         if [ ! -f "%{_prefix}/xs-original/$s" ]; then
241             printf "Original XenServer $s script not present in %{_prefix}/xs-original\n"
242             printf "Could not restore original XenServer script.\n"
243         else
244             (rm -f "$f" \
245                 && mv "%{_prefix}/xs-original/$s" "$f") \
246                 || printf "Could not restore original XenServer $s script.\n"
247         fi
248     done
249
250     find  %{_prefix} -type d -depth -exec rmdir \{\} \; \
251         || printf "Could not remove vSwitch install directory.\n"
252
253     # Remove all configuration and log files
254     rm -f /etc/ovs-vswitchd.conf
255     rm -f /etc/sysconfig/vswitch
256     rm -f /var/log/vswitch*
257     rm -f /etc/ovs-vswitchd.cacert
258
259     if [ ! -f /etc/xensource-inventory ]; then
260         printf "XenSource inventory not present in /etc/xensource-inventory\n"
261         printf "Could not remove vSwitchVersion from XAPI database.\n"
262         exit 1
263     else
264         source /etc/xensource-inventory
265         xe host-param-remove \
266             param-name=other-config param-key=vSwitchVersion \
267             uuid="$INSTALLATION_UUID" ||
268             echo "Could not clear vSwitchVersion config parameter."
269     fi
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/vswitch
281 /etc/init.d/vswitch-xapi-update
282 /etc/xapi.d/plugins/vswitch-cfg-update
283 /etc/sysconfig/vswitch.example
284 /etc/logrotate.d/vswitch
285 /etc/profile.d/vswitch.sh
286 /root/vswitch/kernel_modules/brcompat_mod.ko
287 /root/vswitch/kernel_modules/openvswitch_mod.ko
288 /root/vswitch/kernel_modules/veth_mod.ko
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