New utility ovs-vsctl.
[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
18 Name: vswitch
19 Summary: Virtual switch
20 Group: System Environment/Daemons
21 URL: http://www.openvswitch.org/
22 Version: %{vswitch_version}
23
24 # The entire source code is ASL 2.0 except datapath/ which is GPLv2
25 License: ASL 2.0 and GPLv2
26 Release: 1
27 Source: openvswitch-%{vswitch_version}.tar.gz
28 Buildroot: /tmp/vswitch-xen-rpm
29 Requires: kernel-xen = %(echo '%{xen_version}' | sed 's/xen$//')
30 # The following Conflicts prevents the "vswitch" package generated by
31 # this spec file from installing at the same time as the "openvswitch"
32 # package shipped with XenServer 5.5.900.  In fact, the packages
33 # contain some files with identical names anyhow, so they will not
34 # coexist, but adding an explicit Conflicts makes this conflict more
35 # obvious.
36 Conflicts: openvswitch
37
38 %description
39 The vswitch provides standard network bridging functions augmented with
40 support for the OpenFlow protocol for remote per-flow control of
41 traffic.
42
43 %prep
44 %setup -q -n openvswitch-%{vswitch_version}
45
46 %build
47 ./configure --prefix=/usr --localstatedir=%{_localstatedir} --with-l26=/lib/modules/%{xen_version}/build --enable-ssl %{build_number}
48 make %{_smp_mflags}
49
50 %install
51 rm -rf $RPM_BUILD_ROOT
52 make install DESTDIR=$RPM_BUILD_ROOT
53 install -d -m 755 $RPM_BUILD_ROOT/etc
54 install -d -m 755 $RPM_BUILD_ROOT/etc/init.d
55 install -m 755 xenserver/etc_init.d_vswitch \
56          $RPM_BUILD_ROOT/etc/init.d/vswitch
57 install -m 755 xenserver/etc_init.d_vswitch-xapi-update \
58          $RPM_BUILD_ROOT/etc/init.d/vswitch-xapi-update
59 install -d -m 755 $RPM_BUILD_ROOT/etc/sysconfig
60 install -d -m 755 $RPM_BUILD_ROOT/etc/logrotate.d
61 install -m 755 xenserver/etc_logrotate.d_vswitch \
62          $RPM_BUILD_ROOT/etc/logrotate.d/vswitch
63 install -d -m 755 $RPM_BUILD_ROOT/etc/profile.d
64 install -m 755 xenserver/etc_profile.d_vswitch.sh \
65          $RPM_BUILD_ROOT/etc/profile.d/vswitch.sh
66 install -d -m 755 $RPM_BUILD_ROOT/etc/xapi.d/plugins
67 install -m 755 xenserver/etc_xapi.d_plugins_vswitch-cfg-update \
68          $RPM_BUILD_ROOT/etc/xapi.d/plugins/vswitch-cfg-update
69 install -d -m 755 $RPM_BUILD_ROOT/usr/share/vswitch/scripts
70 install -m 755 xenserver/opt_xensource_libexec_interface-reconfigure \
71              $RPM_BUILD_ROOT/usr/share/vswitch/scripts/interface-reconfigure
72 install -m 755 xenserver/etc_xensource_scripts_vif \
73              $RPM_BUILD_ROOT/usr/share/vswitch/scripts/vif
74 install -m 755 xenserver/usr_share_vswitch_scripts_dump-vif-details \
75                $RPM_BUILD_ROOT/usr/share/vswitch/scripts/dump-vif-details
76 install -m 755 xenserver/usr_sbin_xen-bugtool \
77              $RPM_BUILD_ROOT/usr/share/vswitch/scripts/xen-bugtool
78 install -m 755 xenserver/usr_sbin_brctl \
79              $RPM_BUILD_ROOT/usr/share/vswitch/scripts/brctl
80 install -m 755 xenserver/usr_share_vswitch_scripts_sysconfig.template \
81          $RPM_BUILD_ROOT/usr/share/vswitch/scripts/sysconfig.template
82 install -m 644 \
83         xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py \
84                $RPM_BUILD_ROOT/usr/share/vswitch/scripts/XSFeatureVSwitch.py
85
86 install -d -m 755 $RPM_BUILD_ROOT/lib/modules/%{xen_version}/kernel/net/vswitch
87 find datapath/linux-2.6 -name *.ko -exec install -m 755  \{\} $RPM_BUILD_ROOT/lib/modules/%{xen_version}/kernel/net/vswitch \;
88
89 # Get rid of stuff we don't want to make RPM happy.
90 rm \
91     $RPM_BUILD_ROOT/usr/bin/ovs-controller \
92     $RPM_BUILD_ROOT/usr/bin/ovs-discover \
93     $RPM_BUILD_ROOT/usr/bin/ovs-kill \
94     $RPM_BUILD_ROOT/usr/bin/ovs-openflowd \
95     $RPM_BUILD_ROOT/usr/bin/ovs-pki \
96     $RPM_BUILD_ROOT/usr/bin/ovs-wdt \
97     $RPM_BUILD_ROOT/usr/sbin/ovs-monitor \
98     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-controller.8 \
99     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-discover.8 \
100     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-kill.8 \
101     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-openflowd.8 \
102     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-pki.8
103 rm -f $RPM_BUILD_ROOT/lib/modules/%{xen_version}/kernel/net/vswitch/veth_mod.ko
104 rm -r \
105     $RPM_BUILD_ROOT/usr/share/openvswitch/commands
106
107 install -d -m 755 $RPM_BUILD_ROOT/var/lib/openvswitch
108
109 %clean
110 rm -rf $RPM_BUILD_ROOT
111
112 %post
113 if [ ! -f /etc/xensource-inventory ]; then
114     printf "XenSource inventory not present in /etc/xensource-inventory"
115     exit 1
116 fi
117
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
124 EOF
125     then
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
132 EOF
133     then
134         printf "\nVerified host scripts from XenServer 5.5.900.\n\n"
135     else
136 cat <<EOF
137
138 The original XenServer scripts replaced by this package are not those
139 of any supported version of XenServer.  This could lead to unexpected
140 behavior of your server.  Unless you are sure you know what you are
141 doing, it is highly recommended that you remove this package
142 immediately after the install completes, which will restore the
143 XenServer scripts that you were previously using.
144
145 EOF
146     fi
147 fi
148
149 if test ! -e /var/lib/openvswitch/dbcache; then
150     if test "$1" = 1; then
151         printf "Creating xapi database cache...  "
152     else
153         printf "warning: Open vSwitch is being re-installed or upgraded,\n"
154         printf "         but the xapi database cache is missing.\n"
155         printf "Re-creating xapi database cache...  "
156     fi
157
158     if /usr/share/vswitch/scripts/interface-reconfigure init-dbcache; then
159         printf "done.\n"
160     else
161         printf "FAILED\n"
162         printf "Open vSwitch can only be installed on a XenServer that\n"
163         printf "has connectivity to xapi on the pool master.  Please\n"
164         printf "fix connectivity to the pool master, then try again.\n"
165         exit 1
166     fi
167 fi
168
169 # Ensure that modprobe will find our modules.
170 depmod %{xen_version}
171
172 if grep -F net.ipv4.conf.all.arp_filter /etc/sysctl.conf >/dev/null 2>&1; then :; else
173     cat >>/etc/sysctl.conf <<EOF
174 # This works around an issue in xhad, which binds to a particular
175 # Ethernet device, which in turn causes ICMP port unreachable messages
176 # if packets are received are on the wrong interface, which in turn
177 # can happen if we send out ARP replies on every interface (as Linux
178 # does by default) instead of just on the interface that has the IP
179 # address being ARPed for, which this sysctl setting in turn works
180 # around.
181 #
182 # Bug #1378.
183 net.ipv4.conf.all.arp_filter = 1
184 EOF
185 fi
186
187 # Ensure ovs-vswitchd.conf exists
188 touch /etc/ovs-vswitchd.conf
189
190 # Create default or update existing /etc/sysconfig/vswitch.
191 SYSCONFIG=/etc/sysconfig/vswitch
192 TEMPLATE=/usr/share/vswitch/scripts/sysconfig.template
193 if [ ! -e $SYSCONFIG ]; then
194     cp $TEMPLATE $SYSCONFIG
195 else
196     for var in $(awk -F'[ :]' '/^# [_A-Z0-9]+:/{print $2}' $TEMPLATE)
197     do
198         if ! grep $var $SYSCONFIG >/dev/null 2>&1; then
199             echo >> $SYSCONFIG
200             sed -n "/$var:/,/$var=/p" $TEMPLATE >> $SYSCONFIG
201         fi
202     done
203 fi
204
205 # Replace XenServer files by our versions.
206 mkdir -p /usr/lib/vswitch/xs-original \
207     || printf "Could not create script backup directory.\n"
208 for f in \
209     /opt/xensource/libexec/interface-reconfigure \
210     /etc/xensource/scripts/vif \
211     /usr/sbin/xen-bugtool \
212     /usr/sbin/brctl
213 do
214     s=$(basename "$f")
215     t=$(readlink "$f")
216     if [ "$t" != "/usr/share/vswitch/scripts/$s" ]; then
217         mv "$f" /usr/lib/vswitch/xs-original/ \
218             || printf "Could not save original XenServer $s script\n"
219         ln -s "/usr/share/vswitch/scripts/$s" "$f" \
220             || printf "Could not link to vSwitch $s script\n"
221     fi
222 done
223
224 # Install xsconsole plugin
225 plugin=$(readlink /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py)
226 if [ "$plugin" != "/usr/share/vswitch/scripts/XSFeatureVSwitch.py" ]; then
227     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
228     ln -s /usr/share/vswitch/scripts/XSFeatureVSwitch.py /usr/lib/xsconsole/plugins-base/ || printf "Could not link to vSswitch xsconsole plugin.\n"
229 fi
230
231 # Ensure all required services are set to run
232 for s in vswitch vswitch-xapi-update; do
233     if chkconfig --list $s >/dev/null 2>&1; then
234         chkconfig --del $s || printf "Could not remove $s init script."
235     fi
236     chkconfig --add $s || printf "Could not add $s init script."
237     chkconfig $s on || printf "Could not enable $s init script."
238 done
239
240 if [ "$1" = "1" ]; then    # $1 = 2 for upgrade
241     printf "\nYou MUST reboot the server NOW to complete the change to the\n"
242     printf "the vSwitch.  Attempts to modify networking on the server\n"
243     printf "or any hosted VM will fail until after the reboot and could\n"
244     printf "leave the server in an state requiring manual recovery.\n\n"
245 else
246     printf "\nTo use the new vSwitch, you should reboot the server\n"
247     printf "now.  Failure to do so may result in incorrect operation.\n\n"
248 fi
249
250 %preun
251 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
252     for s in vswitch vswitch-xapi-update; do
253         chkconfig --del $s || printf "Could not remove $s init script."
254     done
255 fi
256
257
258 %postun
259 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
260
261     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py \
262         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
263         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo \
264         || printf "Could not remove vSwitch xsconsole plugin.\n"
265
266     # Restore original XenServer scripts
267     for f in \
268         /opt/xensource/libexec/interface-reconfigure \
269         /etc/xensource/scripts/vif \
270         /usr/sbin/xen-bugtool \
271         /usr/sbin/brctl
272     do
273         s=$(basename "$f")
274         if [ ! -f "/usr/lib/vswitch/xs-original/$s" ]; then
275             printf "Original XenServer $s script not present in /usr/lib/vswitch/xs-original\n"
276             printf "Could not restore original XenServer script.\n"
277         else
278             (rm -f "$f" \
279                 && mv "/usr/lib/vswitch/xs-original/$s" "$f") \
280                 || printf "Could not restore original XenServer $s script.\n"
281         fi
282     done
283
284     # Remove all configuration files
285     rm -f /etc/ovs-vswitchd.conf
286     rm -f /etc/sysconfig/vswitch
287     rm -f /etc/ovs-vswitchd.cacert
288
289     printf "\nYou MUST reboot the server now to complete the change to\n"
290     printf "standard Xen networking.  Attempts to modify networking on the\n"
291     printf "server or any hosted VM will fail until after the reboot and\n"
292     printf "could leave the server in a state requiring manual recovery.\n\n"
293 fi
294
295
296 %files
297 %defattr(-,root,root)
298 /etc/init.d/vswitch
299 /etc/init.d/vswitch-xapi-update
300 /etc/xapi.d/plugins/vswitch-cfg-update
301 /etc/logrotate.d/vswitch
302 /etc/profile.d/vswitch.sh
303 /lib/modules/%{xen_version}/kernel/net/vswitch/openvswitch_mod.ko
304 /lib/modules/%{xen_version}/kernel/net/vswitch/brcompat_mod.ko
305 /usr/share/vswitch/scripts/dump-vif-details
306 /usr/share/vswitch/scripts/interface-reconfigure
307 /usr/share/vswitch/scripts/vif
308 /usr/share/vswitch/scripts/xen-bugtool
309 /usr/share/vswitch/scripts/XSFeatureVSwitch.py
310 /usr/share/vswitch/scripts/brctl
311 /usr/share/vswitch/scripts/sysconfig.template
312 # Following two files are generated automatically by rpm.  We don't
313 # really need them and they won't be used on the XenServer, but there
314 # isn't an obvious place to get rid of them since they are generated
315 # after the install script runs.  Since they are small, we just
316 # include them.
317 /usr/share/vswitch/scripts/XSFeatureVSwitch.pyc
318 /usr/share/vswitch/scripts/XSFeatureVSwitch.pyo
319 /usr/sbin/ovs-brcompatd
320 /usr/sbin/ovs-vswitchd
321 /usr/bin/ovs-appctl
322 /usr/bin/ovs-cfg-mod
323 /usr/bin/ovs-dpctl
324 /usr/bin/ovs-ofctl
325 /usr/bin/ovs-vsctl
326 /usr/share/man/man5/ovs-vswitchd.conf.5.gz
327 /usr/share/man/man8/ovs-appctl.8.gz
328 /usr/share/man/man8/ovs-brcompatd.8.gz
329 /usr/share/man/man8/ovs-cfg-mod.8.gz
330 /usr/share/man/man8/ovs-dpctl.8.gz
331 /usr/share/man/man8/ovs-ofctl.8.gz
332 /usr/share/man/man8/ovs-vsctl.8.gz
333 /usr/share/man/man8/ovs-vswitchd.8.gz
334 /var/lib/openvswitch