1 # Spec file for vswitch and related programs.
3 # Copyright (C) 2009 Nicira Networks, Inc.
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.
10 # When building, the rpmbuild command line should define
11 # vswitch_version, xen_version, and build_number using -D arguments.
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
16 %define version %{vswitch_version}-%{xen_version}
17 %define _prefix /root/vswitch
20 Summary: Virtual switch
21 Group: System Environment/Daemons
22 URL: http://www.openvswitch.org/
23 Version: %{vswitch_version}
25 # The entire source code is ASL 2.0 except datapath/ which is GPLv2
26 License: ASL 2.0 and GPLv2
28 Source: openvswitch-%{vswitch_version}.tar.gz
29 Buildroot: /tmp/vswitch-xen-rpm
30 Requires: kernel-xen = %(echo '%{xen_version}' | sed 's/xen$//')
31 # The following Conflicts prevents the "vswitch" package generated by
32 # this spec file from installing at the same time as the "openvswitch"
33 # package shipped with XenServer 5.5.900. In fact, the packages
34 # contain some files with identical names anyhow, so they will not
35 # coexist, but adding an explicit Conflicts makes this conflict more
37 Conflicts: openvswitch
40 The vswitch provides standard network bridging functions augmented with
41 support for the OpenFlow protocol for remote per-flow control of
45 %setup -q -n openvswitch-%{vswitch_version}
48 ./configure --prefix=%{_prefix} --localstatedir=%{_localstatedir} --with-l26=/lib/modules/%{xen_version}/build --enable-ssl %{build_number}
52 rm -rf $RPM_BUILD_ROOT
53 make install DESTDIR=$RPM_BUILD_ROOT prefix=%{_prefix}
54 install -d -m 755 $RPM_BUILD_ROOT/etc
55 install -d -m 755 $RPM_BUILD_ROOT/etc/init.d
56 install -m 755 xenserver/etc_init.d_vswitch \
57 $RPM_BUILD_ROOT/etc/init.d/vswitch
58 install -m 755 xenserver/etc_init.d_vswitch-xapi-update \
59 $RPM_BUILD_ROOT/etc/init.d/vswitch-xapi-update
60 install -d -m 755 $RPM_BUILD_ROOT/etc/sysconfig
61 install -d -m 755 $RPM_BUILD_ROOT/etc/logrotate.d
62 install -m 755 xenserver/etc_logrotate.d_vswitch \
63 $RPM_BUILD_ROOT/etc/logrotate.d/vswitch
64 install -d -m 755 $RPM_BUILD_ROOT/etc/profile.d
65 install -m 755 xenserver/etc_profile.d_vswitch.sh \
66 $RPM_BUILD_ROOT/etc/profile.d/vswitch.sh
67 install -d -m 755 $RPM_BUILD_ROOT/etc/xapi.d/plugins
68 install -m 755 xenserver/etc_xapi.d_plugins_vswitch-cfg-update \
69 $RPM_BUILD_ROOT/etc/xapi.d/plugins/vswitch-cfg-update
70 install -d -m 755 $RPM_BUILD_ROOT%{_prefix}/scripts
71 install -m 755 xenserver/opt_xensource_libexec_interface-reconfigure \
72 $RPM_BUILD_ROOT%{_prefix}/scripts/interface-reconfigure
73 install -m 755 xenserver/etc_xensource_scripts_vif \
74 $RPM_BUILD_ROOT%{_prefix}/scripts/vif
75 install -m 755 xenserver/root_vswitch_scripts_dump-vif-details \
76 $RPM_BUILD_ROOT%{_prefix}/scripts/dump-vif-details
77 install -m 755 xenserver/usr_sbin_xen-bugtool \
78 $RPM_BUILD_ROOT%{_prefix}/scripts/xen-bugtool
79 install -m 755 xenserver/usr_sbin_brctl \
80 $RPM_BUILD_ROOT%{_prefix}/scripts/brctl
81 install -m 755 xenserver/root_vswitch_scripts_sysconfig.template \
82 $RPM_BUILD_ROOT/root/vswitch/scripts/sysconfig.template
84 xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py \
85 $RPM_BUILD_ROOT%{_prefix}/scripts/XSFeatureVSwitch.py
87 install -d -m 755 $RPM_BUILD_ROOT%{_prefix}/kernel_modules
88 find datapath/linux-2.6 -name *.ko -exec install -m 755 \{\} $RPM_BUILD_ROOT%{_prefix}/kernel_modules/ \;
90 # Get rid of stuff we don't want to make RPM happy.
92 $RPM_BUILD_ROOT/root/vswitch/bin/ezio-term \
93 $RPM_BUILD_ROOT/root/vswitch/bin/ovs-controller \
94 $RPM_BUILD_ROOT/root/vswitch/bin/ovs-discover \
95 $RPM_BUILD_ROOT/root/vswitch/bin/ovs-kill \
96 $RPM_BUILD_ROOT/root/vswitch/bin/ovs-openflowd \
97 $RPM_BUILD_ROOT/root/vswitch/bin/ovs-pki \
98 $RPM_BUILD_ROOT/root/vswitch/bin/ovs-switchui \
99 $RPM_BUILD_ROOT/root/vswitch/bin/ovs-wdt \
100 $RPM_BUILD_ROOT/root/vswitch/kernel_modules/veth_mod.ko \
101 $RPM_BUILD_ROOT/root/vswitch/sbin/ovs-monitor \
102 $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-controller.8 \
103 $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-discover.8 \
104 $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-kill.8 \
105 $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-openflowd.8 \
106 $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-pki.8 \
107 $RPM_BUILD_ROOT/root/vswitch/share/openvswitch
110 rm -rf $RPM_BUILD_ROOT
113 if [ ! -f /etc/xensource-inventory ]; then
114 printf "XenSource inventory not present in /etc/xensource-inventory"
118 if [ "$1" = "1" ]; then
119 if md5sum -c --status <<EOF
120 ca141d60061dcfdade73e75abc6529b5 /usr/sbin/brctl
121 b8e9835862ef1a9cec2a3f477d26c989 /etc/xensource/scripts/vif
122 51970ad613a3996d5997e18e44db47da /opt/xensource/libexec/interface-reconfigure
123 5654c8c36699fcc8744ca9cd5b855414 /usr/sbin/xen-bugtool
126 printf "\nVerified host scripts from XenServer 5.5.0.\n\n"
127 elif md5sum -c --status <<EOF
128 ca141d60061dcfdade73e75abc6529b5 /usr/sbin/brctl
129 b8e9835862ef1a9cec2a3f477d26c989 /etc/xensource/scripts/vif
130 ce451d3c985fd1db6497a363f0d9dedb /opt/xensource/libexec/interface-reconfigure
131 2b53f500431fcba5276c896e9e4281b9 /usr/sbin/xen-bugtool
133 printf "\nVerified host scripts from XenServer 5.5.900.\n\n"
137 The original XenServer scripts replaced by this package are not those
138 of any supported version of XenServer. This could lead to unexpected
139 behavior of your server. Unless you are sure you know what you are
140 doing, it is highly recommended that you remove this package
141 immediately after the install completes, which will restore the
142 XenServer scripts that you were previously using.
148 if test ! -e /etc/ovs-vswitch.dbcache; then
149 if test "$1" = 1; then
150 printf "Creating xapi database cache... "
152 printf "warning: Open vSwitch is being re-installed or upgraded,\n"
153 printf " but the xapi database cache is missing.\n"
154 printf "Re-creating xapi database cache... "
157 source /etc/xensource-inventory
158 if python - "$INSTALLATION_UUID" <<EOF
163 session = XenAPI.xapi_local()
165 session.xenapi.login_with_password("root", "")
167 vlans = session.xenapi.VLAN.get_all_records()
168 bonds = session.xenapi.Bond.get_all_records()
169 pifs = session.xenapi.PIF.get_all_records()
170 networks = session.xenapi.network.get_all_records()
171 host = session.xenapi.host.get_by_uuid(sys.argv[1])
173 session.xenapi.session.logout()
175 dbcache_file = "/etc/ovs-vswitch.dbcache"
176 f = open(dbcache_file, 'w')
177 pickle.dump({'vlans': vlans,
180 'networks': networks}, f)
181 pickle.dump({'host': host}, f)
188 printf "Open vSwitch can only be installed on a XenServer that\n"
189 printf "has connectivity to xapi on the pool master. Please\n"
190 printf "fix connectivity to the pool master, then try again.\n"
196 if grep -F net.ipv4.conf.all.arp_filter /etc/sysctl.conf >/dev/null 2>&1; then :; else
197 cat >>/etc/sysctl.conf <<EOF
198 # This works around an issue in xhad, which binds to a particular
199 # Ethernet device, which in turn causes ICMP port unreachable messages
200 # if packets are received are on the wrong interface, which in turn
201 # can happen if we send out ARP replies on every interface (as Linux
202 # does by default) instead of just on the interface that has the IP
203 # address being ARPed for, which this sysctl setting in turn works
207 net.ipv4.conf.all.arp_filter = 1
211 # Ensure ovs-vswitchd.conf exists
212 touch /etc/ovs-vswitchd.conf
214 # Create default or update existing /etc/sysconfig/vswitch.
215 SYSCONFIG=/etc/sysconfig/vswitch
216 TEMPLATE=/root/vswitch/scripts/sysconfig.template
217 if [ ! -e $SYSCONFIG ]; then
218 cp $TEMPLATE $SYSCONFIG
220 for var in $(awk -F'[ :]' '/^# [_A-Z0-9]+:/{print $2}' $TEMPLATE)
222 if ! grep $var $SYSCONFIG >/dev/null 2>&1; then
224 sed -n "/$var:/,/$var=/p" $TEMPLATE >> $SYSCONFIG
229 # Replace XenServer files by our versions.
230 mkdir -p %{_prefix}/xs-original \
231 || printf "Could not create script backup directory.\n"
233 /opt/xensource/libexec/interface-reconfigure \
234 /etc/xensource/scripts/vif \
235 /usr/sbin/xen-bugtool \
240 if [ "$t" != "%{_prefix}/scripts/$s" ]; then
241 mv "$f" %{_prefix}/xs-original/ \
242 || printf "Could not save original XenServer $s script\n"
243 ln -s "%{_prefix}/scripts/$s" "$f" \
244 || printf "Could not link to vSwitch $s script\n"
248 # Install xsconsole plugin
249 plugin=$(readlink /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py)
250 if [ "$plugin" != "/root/vswitch/scripts/XSFeatureVSwitch.py" ]; then
251 rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
252 ln -s /root/vswitch/scripts/XSFeatureVSwitch.py /usr/lib/xsconsole/plugins-base/ || printf "Could not link to vSswitch xsconsole plugin.\n"
255 # Ensure all required services are set to run
256 for s in vswitch vswitch-xapi-update; do
257 if chkconfig --list $s >/dev/null 2>&1; then
258 chkconfig --del $s || printf "Could not remove $s init script."
260 chkconfig --add $s || printf "Could not add $s init script."
261 chkconfig $s on || printf "Could not enable $s init script."
264 if [ "$1" = "1" ]; then # $1 = 2 for upgrade
265 printf "\nYou MUST reboot the server NOW to complete the change to the\n"
266 printf "the vSwitch. Attempts to modify networking on the server\n"
267 printf "or any hosted VM will fail until after the reboot and could\n"
268 printf "leave the server in an state requiring manual recovery.\n\n"
270 printf "\nTo use the new vSwitch, you should reboot the server\n"
271 printf "now. Failure to do so may result in incorrect operation.\n\n"
275 if [ "$1" = "0" ]; then # $1 = 1 for upgrade
276 for s in vswitch vswitch-xapi-update; do
277 chkconfig --del $s || printf "Could not remove $s init script."
283 if [ "$1" = "0" ]; then # $1 = 1 for upgrade
285 rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py \
286 /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
287 /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo \
288 || printf "Could not remove vSwitch xsconsole plugin.\n"
290 # Restore original XenServer scripts
292 /opt/xensource/libexec/interface-reconfigure \
293 /etc/xensource/scripts/vif \
294 /usr/sbin/xen-bugtool \
298 if [ ! -f "%{_prefix}/xs-original/$s" ]; then
299 printf "Original XenServer $s script not present in %{_prefix}/xs-original\n"
300 printf "Could not restore original XenServer script.\n"
303 && mv "%{_prefix}/xs-original/$s" "$f") \
304 || printf "Could not restore original XenServer $s script.\n"
308 find %{_prefix} -type d -depth -exec rmdir \{\} \; \
309 || printf "Could not remove vSwitch install directory.\n"
311 # Remove all configuration files
312 rm -f /etc/ovs-vswitchd.conf
313 rm -f /etc/sysconfig/vswitch
314 rm -f /etc/ovs-vswitchd.cacert
316 printf "\nYou MUST reboot the server now to complete the change to\n"
317 printf "standard Xen networking. Attempts to modify networking on the\n"
318 printf "server or any hosted VM will fail until after the reboot and\n"
319 printf "could leave the server in a state requiring manual recovery.\n\n"
324 %defattr(-,root,root)
326 /etc/init.d/vswitch-xapi-update
327 /etc/xapi.d/plugins/vswitch-cfg-update
328 /etc/logrotate.d/vswitch
329 /etc/profile.d/vswitch.sh
330 /root/vswitch/kernel_modules/brcompat_mod.ko
331 /root/vswitch/kernel_modules/openvswitch_mod.ko
332 /root/vswitch/scripts/dump-vif-details
333 /root/vswitch/scripts/interface-reconfigure
334 /root/vswitch/scripts/vif
335 /root/vswitch/scripts/xen-bugtool
336 /root/vswitch/scripts/XSFeatureVSwitch.py
337 /root/vswitch/scripts/brctl
338 /root/vswitch/scripts/sysconfig.template
339 # Following two files are generated automatically by rpm. We don't
340 # really need them and they won't be used on the XenServer, but there
341 # isn't an obvious place to get rid of them since they are generated
342 # after the install script runs. Since they are small, we just
344 /root/vswitch/scripts/XSFeatureVSwitch.pyc
345 /root/vswitch/scripts/XSFeatureVSwitch.pyo
346 /root/vswitch/sbin/ovs-brcompatd
347 /root/vswitch/sbin/ovs-vswitchd
348 /root/vswitch/bin/ovs-appctl
349 /root/vswitch/bin/ovs-cfg-mod
350 /root/vswitch/bin/ovs-dpctl
351 /root/vswitch/bin/ovs-ofctl
352 /root/vswitch/share/man/man5/ovs-vswitchd.conf.5
353 /root/vswitch/share/man/man8/ovs-appctl.8
354 /root/vswitch/share/man/man8/ovs-brcompatd.8
355 /root/vswitch/share/man/man8/ovs-cfg-mod.8
356 /root/vswitch/share/man/man8/ovs-dpctl.8
357 /root/vswitch/share/man/man8/ovs-ofctl.8
358 /root/vswitch/share/man/man8/ovs-vswitchd.8