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