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