File libvirt.spec of Package libvirt.6159

#
# spec file for package libvirt
#
# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


# The configuration of libvirt is modified slightly for SLE
%define with_sle_build     %{?is_opensuse:0}%{!?is_opensuse:1}

# openSUSE13.1 and 13.2 do not understand %is_opensuse. Check for those
# explicitly and disable SLE build
%if 0%{?suse_version} == 1310 || 0%{?suse_version} == 1320
    %define with_sle_build 0
%endif

# The hypervisor drivers that run in libvirtd
%define with_xen           0%{!?_without_xen:1}
%define with_qemu          0%{!?_without_qemu:1}
%define with_lxc           0%{!?_without_lxc:1}
%define with_uml           0%{!?_without_uml:1}
%define with_libxl         0%{!?_without_libxl:1}
%define with_vbox          0%{!?_without_vbox:1}

# Then the hypervisor drivers that run outside libvirtd, in libvirt.so
%define with_openvz        0%{!?_without_openvz:1}
%define with_vmware        0%{!?_without_vmware:1}
%define with_phyp          0%{!?_without_phyp:0}
%define with_esx           0%{!?_without_esx:1}
%define with_hyperv        0%{!?_without_hyperv:0}

# Then the secondary host drivers, which run inside libvirtd
%define with_storage_rbd   0%{!?_without_storage_rbd:0}
%define with_storage_sheepdog 0
%define with_storage_gluster  0
%define with_apparmor      0%{!?_without_apparmor:1}

# Optional bits on by default
%define with_sanlock       0%{!?_without_sanlock:1}
%define with_polkit_rules  1

# A few optional bits off by default, we enable later
%define with_cgconfig      0%{!?_without_cgconfig:0}
%define with_systemd       0%{!?_without_systemd:0}
%define with_numactl       0%{!?_without_numactl:0}
%define with_numad         0%{!?_without_numad:0}
%define with_firewalld     0%{!?_without_firewalld:0}
%define with_wireshark     0%{!?_without_wireshark:0}

# Xen no longer contains xm/xend so disable building the legacy Xen driver
%define with_xen           0

# Set the OS / architecture specific special cases

# Xen is available only on x86_64 and arm
%ifnarch x86_64 %arm aarch64
    %define with_xen       0
    %define with_libxl     0
%endif

# For SLE, further restrice Xen support to x86_64 only
%if %{with_sle_build}
    %ifarch %arm aarch64
        %define with_xen   0
        %define with_libxl 0
    %endif
%endif

# Enable numactl for most architectures. Handle aarch64 separately
%ifnarch s390 s390x %arm %ix86 aarch64
    %define with_numactl   0%{!?_without_numactl:1}
%endif

# For aarch64, numactl is only available on newer than 1320, or SLE12
# family newer than 120100
%ifarch aarch64
    %if 0%{?suse_version} > 1320 || ( 0%{?suse_version} == 1315 && ( 0%{?sle_version} > 120100 ) )
        %define with_numactl 0%{!?_without_numactl:1}
    %endif
%endif

# vbox is available only on i386 x86_64
%ifnarch %{ix86} x86_64
    %define with_vbox      0
%endif

# Disable hypervisor drivers not supported in SLE
%if %{with_sle_build}
    %define with_openvz    0
    %define with_vbox      0
    %define with_uml       0
    %define with_vmware    0
    %define with_hyperv    0
%endif

# Enable phyp driver for IBM Power systems
%ifarch ppc64
    %define with_phyp      1
%endif

# rbd enablement is a bit tricky. For x86_64
%ifarch x86_64
# enable on anything newer than 1320, or SLE12 family newer than 120100
# use librbd-devel as build dependency
    %if 0%{?suse_version} > 1320 || ( 0%{?suse_version} == 1315 && ( 0%{?sle_version} > 120100 ) )
        %define with_storage_rbd 0%{!?_without_storage_rbd:1}
        %define with_rbd_lib     librbd-devel
    %endif
# enable for SLE12 family <= 120100 (SLE12GA/SP1, Leap 42.1)
# use ceph-devel as build dependency
    %if 0%{?suse_version} == 1315 && 0%{?sle_version} <= 120100
        %define with_storage_rbd 0%{!?_without_storage_rbd:1}
        %define with_rbd_lib     ceph-devel
    %endif
%endif

# For arm
%ifarch aarch64
# enable on anything newer than 1320, or SLE12 family newer than 120100
# use librbd-devel as build dependency
    %if 0%{?suse_version} > 1320 || ( 0%{?is_opensuse} == 0 && 0%{?sle_version} > 120100 )
        %define with_storage_rbd 0%{!?_without_storage_rbd:1}
        %define with_rbd_lib     librbd-devel
    %endif
%endif

# Support systemd on 12.1 and later
%if 0%{?suse_version} >= 1210
    %define with_systemd        0%{!?_without_systemd:1}
%endif

# libvirt commit 37397320 changed the configure check for wireshark to
# use pkgconfig, but our wireshark packages do not provide wireshark.pc.
# Disable the dissector for now
%define with_wireshark     0

# numad is used to manage the CPU and memory placement dynamically for
# qemu, lxc, and uml drivers
%if %{with_qemu} || %{with_lxc} || %{with_uml}
# Enable numad for most architectures. Handle aarch64 separately
    %ifnarch s390 s390x %arm %ix86 aarch64
        %define with_numad 0%{!?_without_numad:1}
    %endif
# For aarch64, enable on anything newer than 1320, or SLE12 family newer
# than 120100
    %ifarch aarch64
        %if 0%{?suse_version} > 1320 || ( 0%{?suse_version} == 1315 && 0%{?sle_version} > 120100 )
            %define with_numad 0%{!?_without_numad:1}
        %endif
    %endif
%endif

# Force QEMU to run as qemu:qemu
%define qemu_user          qemu
%define qemu_group         qemu

# Pull in cgroups config system
%if %{with_qemu} || %{with_lxc}
    %define with_cgconfig  0%{!?_without_cgconfig:1}
%endif

%define _fwdefdir /etc/sysconfig/SuSEfirewall2.d/services

Name:           libvirt
Url:            http://libvirt.org/
Version:        2.0.0
Release:        0
Summary:        Library providing a simple virtualization API
License:        LGPL-2.1+
Group:          Development/Libraries/C and C++

Requires:       libvirt-daemon = %{version}-%{release}
Requires:       libvirt-daemon-config-network = %{version}-%{release}
Requires:       libvirt-daemon-config-nwfilter = %{version}-%{release}
%if %{with_libxl}
Requires:       libvirt-daemon-driver-libxl = %{version}-%{release}
%endif
%if %{with_lxc}
Requires:       libvirt-daemon-driver-lxc = %{version}-%{release}
%endif
%if %{with_qemu}
Requires:       libvirt-daemon-driver-qemu = %{version}-%{release}
%endif
%if %{with_uml}
Requires:       libvirt-daemon-driver-uml = %{version}-%{release}
%endif
%if %{with_xen}
Requires:       libvirt-daemon-driver-xen = %{version}-%{release}
%endif
%if %{with_vbox}
Requires:       libvirt-daemon-driver-vbox = %{version}-%{release}
%endif
Requires:       libvirt-client = %{version}-%{release}
Requires:       libvirt-daemon-driver-interface = %{version}-%{release}
Requires:       libvirt-daemon-driver-network = %{version}-%{release}
Requires:       libvirt-daemon-driver-nodedev = %{version}-%{release}
Requires:       libvirt-daemon-driver-nwfilter = %{version}-%{release}
Requires:       libvirt-daemon-driver-secret = %{version}-%{release}
Requires:       libvirt-daemon-driver-storage = %{version}-%{release}

# All build-time requirements. Run-time requirements are
# listed against each sub-RPM
BuildRequires:  autoconf
BuildRequires:  automake
BuildRequires:  gettext-tools
BuildRequires:  libtool
# Needed for virkmodtest in 'make check'
BuildRequires:  modutils
%if %{with_systemd}
BuildRequires:  systemd
BuildRequires:  pkgconfig(systemd)
%endif
%if %{with_xen} || %{with_libxl}
BuildRequires:  xen-devel
%endif
BuildRequires:  fdupes
BuildRequires:  libattr-devel
BuildRequires:  libgcrypt-devel
BuildRequires:  libgnutls-devel
BuildRequires:  libtasn1-devel
BuildRequires:  libxml2-devel
BuildRequires:  libxslt
BuildRequires:  ncurses-devel
BuildRequires:  perl
BuildRequires:  python
BuildRequires:  python-xml
BuildRequires:  readline-devel
BuildRequires:  xhtml-dtd
# perl XPath is needed since we have a patch touching files that cause
# hvsupport.html to be regenerated
BuildRequires:  perl(XML::XPath)
# For pool-build probing for existing pools
BuildRequires:  libblkid-devel >= 2.17
BuildRequires:  libpciaccess0-devel >= 0.10.9
BuildRequires:  libudev-devel >= 145
BuildRequires:  libyajl-devel
%if %{with_sanlock}
BuildRequires:  sanlock-devel >= 2.4
%endif
BuildRequires:  libavahi-devel
BuildRequires:  libnl3-devel
BuildRequires:  libpcap-devel
BuildRequires:  libselinux-devel
%if %{with_apparmor}
BuildRequires:  libapparmor-devel
%endif
BuildRequires:  dnsmasq >= 2.41
BuildRequires:  iptables
# TODO BuildRequires:  iptables-ipv6
BuildRequires:  cyrus-sasl-devel
BuildRequires:  ebtables
BuildRequires:  polkit >= 0.93
BuildRequires:  polkit-devel >= 0.93
BuildRequires:  radvd
# For mount/umount in FS driver
BuildRequires:  util-linux
# For LVM drivers
BuildRequires:  lvm2
# For ISCSI driver
BuildRequires:  open-iscsi
# For disk driver
BuildRequires:  parted-devel
# For Multipath support
BuildRequires:  device-mapper-devel
%if %{with_storage_rbd}
BuildRequires:  %{with_rbd_lib}
%endif
%if %{with_numactl}
# For QEMU/LXC numa info
BuildRequires:  libnuma-devel
%endif
BuildRequires:  fuse-devel >= 2.8.6
BuildRequires:  libcap-ng-devel >= 0.5.0
BuildRequires:  libnetcontrol-devel >= 0.2.0
BuildRequires:  libssh2-devel
%if %{with_esx}
BuildRequires:  libcurl-devel
%endif
%if %{with_hyperv}
BuildRequires:  libwsman-devel >= 2.2.3
%endif
BuildRequires:  audit-devel
# we need /usr/sbin/dtrace
BuildRequires:  systemtap-sdt-devel
%if %{with_numad}
BuildRequires:  numad
%endif
%if %{with_wireshark}
BuildRequires:  wireshark-devel > 1.12.1
%endif

Source0:        %{name}-%{version}.tar.xz
Source1:        %{name}-%{version}.tar.xz.asc
Source2:        %{name}.keyring
Source3:        libvirtd.init
Source4:        libvirtd-relocation-server.fw
Source99:       baselibs.conf
Source100:      %{name}-rpmlintrc
# Upstream patches
Patch0:         c8f08e48-systemd-notify-fix.patch
Patch1:         a7f84cb1-qemu-virtio-disk-error-cleanup.patch
Patch2:         60c40ce3-qemuDomainSecretDiskCapable.patch
Patch3:         fceeeda2-qemu-secinfo-hotplug-disk.patch
Patch4:         541e9ae6-cpu-vendor-crash-fix.patch
Patch5:         d53d4650-qemu-rbd-auth.patch
Patch6:         ea46e00f-virHostdevFindUSBDevice-privsyms.patch
Patch7:         e01d300b-libxl-usb-vendor.patch
Patch8:         f820d5bf6-USB-port-path-as-an-array-of-integers.patch
Patch9:         82c142b3-introduce-virDomainUSBAddressSet.patch
Patch10:        6b3e4e2b-functions-usb-controllers-to-addr.patch
Patch11:        be146b34-extend-usb-controller-model.patch
Patch12:        770bf992-libxl-usb-controller-creation.patch
Patch13:        44304c6e-libxl-usb-controller-hotplug.patch
Patch14:        f5359e55-libxl-autocreate-usb-controller.patch
Patch15:        9a361bbb-xenconfig-usb-controller-conversion.patch
Patch16:        c6f0e177-qusb-qemu-check.patch
Patch17:        70f83f9d-pci-driver-override.patch
Patch18:        36f57ad-advertise-migv3.patch
Patch19:        c0960aab-libxl-shadow-mem.patch
Patch20:        dbb14bb0-cmt-fix1.patch
Patch21:        1ac897a1-cmt-fix2.patch
Patch22:        58ba240d-cmt-fix3.patch
Patch23:        300f668c-cmt-fix4.patch
Patch24:        1fc90ae9-libxl-mig-persist.patch
Patch25:        839a0608-virtlogd-lifecycle1.patch
Patch26:        f496ce1d-virtlogd-lifecycle2.patch
Patch27:        4c600de7-libxl-schedinfo.patch
Patch28:        f4332dd2-virsh-pod-sched-fix.patch
Patch29:        5f5a5a42-lxcDomainCreateXMLWithFiles-Avoid-crash.patch
Patch30:        089d7a55-lxc-monitor-now-holds-a-reference-to-the-domain.patch
Patch31:        cc38d566-exclude-Xen-dom0-from-libvirt-guests.patch
Patch32:        04597a70-postcopy-mig-flag.patch
Patch33:        01193545-postcopy-mig-fixup.patch
Patch34:        a05e2570-libxl-virDomainGetMaxVcpus.patch
Patch35:        ecb587e4-libxl-pae.patch
Patch36:        f4f285d8-xen-pvusb-hvm.patch
Patch37:        162bb0e7b-libxl-fix-usb-inputs-loop-error.patch
Patch38:        6e4759d0-libxl-timer-fix.patch
Patch39:        87df87e0-libxl-timer-tsc-emulate.patch
Patch40:        b4386fda-xenconfig-timer-fix.patch
Patch41:        d3970925-timer-tests.patch
Patch42:        321a28c6-libxl-default-disk-format.patch
Patch43:        bd116810-libxl-fix-disk-detach.patch
Patch44:        c89a6e78-libxl-physinfo-cleanup.patch
Patch45:        d2b77608-libxl-maxmem-fix.patch
Patch46:        79692c38-libxl-dom0-maxmem.patch
Patch47:        4ab0c959-libxl-mem-leak.patch
Patch48:        2dc1cf19-libxl-double-free.patch
Patch49:        67dcb797-virTimeBackOffWait-sleepcap.patch
Patch50:        85af0b80-qemu-adaptive-montimeout.patch
Patch51:        ff3112f3-qemu-hugepage-align-fix.patch
Patch52:        d68cb4f55-extract-the-request-sending-code-from-virNetlin.patch
Patch53:        754515b7d-add-virNetlinkDumpCommand.patch
Patch54:        3ee35d7d6-more-uses-of-SYSCTL_PATH.patch
Patch55:        5dd607059-add-virNetDevGetName.patch
Patch56:        00d28a78b-check-accept_ra-before-enabling-ipv6-forward.patch
Patch57:        a1f46c71-restrict-IPv6-RA-routes-check.patch
Patch58:        27cd7635-increase-daemons-file-limit.patch
Patch59:        6b3fb86b-increase-libvirtd-task-limit.patch
Patch60:        8126d870-libxl-cdrom-config-fix.patch
Patch61:        710d875f-libxl-cdrom-config-test.patch
Patch62:        6de895f6-libxl-def-usbctrl.patch
Patch63:        15209649-support-vbox-5_1.patch
Patch64:        2b4e16cf-vbox-hookup-the-5.1-C-API-to-the-unified-driver.patch
Patch65:        819593d1-Add-vbox-5.1-driver-file.patch
Patch66:        69722fd7-ignore-newline-libvirt-guests.patch
Patch67:        ff7e0a1a-fix-securityselinuxtest.patch
Patch68:        0f1993aa-dont-autogen-seclable.patch
Patch69:        e4cb8500-avoid-malicious-ssh-hostname-as-args.patch
Patch70:        6c43149c-qemu-logrotate-drop-minsize.patch
Patch71:        418a1002-hypervisor-logrotate-drop-minsize.patch
Patch72:        d1eea6c1-nodedev-increase-netlink-sockbuf.patch
# Patches pending upstream review
Patch100:       libxl-dom-reset.patch
Patch101:       apparmor-errormsg-fix.patch
Patch102:       apparmor-alt-seclabel.patch
# Need to go upstream
Patch150:       xen-pv-cdrom.patch
Patch151:       blockcopy-check-dst-identical-device.patch
Patch152:       libvirt-power8-models.patch
Patch153:       ppc64le-canonical-name.patch
Patch154:       libxl-set-migration-constraints.patch
Patch155:       libxl-set-cach-mode.patch
Patch156:       apparmor-fixes.patch
Patch157:       apparmor-qemu-bridge-helper.patch
Patch158:       libxl-release-mig-port.patch
# Our patches
Patch200:       libvirtd-defaults.patch
Patch201:       libvirtd-init-script.patch
Patch202:       libvirt-guests-init-script.patch
Patch203:       virtlockd-init-script.patch
Patch204:       virtlogd-init-script.patch
Patch205:       suse-qemu-conf.patch
Patch206:       support-managed-pci-xen-driver.patch
Patch207:       systemd-service-xen.patch
Patch208:       xen-sxpr-disk-type.patch
Patch209:       libxl-support-block-script.patch
Patch210:       apparmor-no-mount.patch
Patch211:       qemu-apparmor-screenshot.patch
Patch212:       libvirt-suse-netcontrol.patch
Patch213:       lxc-wait-after-eth-del.patch
Patch214:       libxl-qemu-emulator-caps.patch
Patch215:       suse-libvirtd-service.patch
# SLES-Only patches
Patch300:       virt-create-rootfs.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%description
Libvirt is a C toolkit to interact with the virtualization
capabilities of Linux. Virtualization of the Linux Operating System means
the ability to run multiple instances of Operating Systems concurrently
on a single hardware system where the basic resources are driven by a
Linux instance. The library aims to provide long term stable C API
to interact with Linux virtualization technologies.



Authors:
--------
    Daniel Veillard <veillard@redhat.com>
    Karel Zak <kzak@redhat.com>


%package doc
Summary:        API reference and website documentation
Group:          Development/Libraries/C and C++

%description doc
Includes the API reference for the libvirt C library, and a complete
copy of the libvirt.org website documentation.

%package daemon
Summary:        Server side daemon and supporting files for libvirt library
Group:          Development/Libraries/C and C++

# All runtime requirements for the libvirt package (runtime requirements
# for subpackages are listed later in those subpackages)

# The client side, i.e. shared libs and virsh are in a subpackage
Requires:       %{name}-client = %{version}-%{release}

# for modprobe of pci devices
Requires:       modutils
# for /sbin/ip & /sbin/tc
Requires:       bridge-utils
Requires:       iproute
Requires:       logrotate
Requires:       udev >= 145
Recommends:     polkit >= 0.93
%ifarch i386 i586 i686 x86_64 ia64
# For virConnectGetSysinfo
Requires:       dmidecode
%endif
%if %{with_systemd}
# For service management
%{?systemd_requires}
%endif
%if %{with_numad}
Requires:       numad
%endif

%description daemon
Server side daemon required to manage the virtualization capabilities
of recent versions of Linux. Requires a hypervisor specific sub-RPM
for specific drivers.

%package daemon-config-network
Summary:        Default configuration files for the libvirtd daemon
Group:          Development/Libraries/C and C++

Requires:       libvirt-daemon = %{version}-%{release}
Requires:       libvirt-daemon-driver-network = %{version}-%{release}

%description daemon-config-network
Default configuration files for setting up NAT based networking

%package daemon-config-nwfilter
Summary:        Network filter configuration files for the libvirtd
Group:          Development/Libraries/C and C++

Requires:       libvirt-daemon = %{version}-%{release}
Requires:       libvirt-daemon-driver-nwfilter = %{version}-%{release}

%description daemon-config-nwfilter
Network filter configuration files for the libvirt daemon, used for
cleaning guest network traffic.

%package daemon-driver-network
Summary:        Network driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       dnsmasq >= 2.41
Requires:       iptables
# TODO Requires:       iptables-ipv6
Requires:       libvirt-daemon = %{version}-%{release}
Requires:       radvd

%description daemon-driver-network
The network driver plugin for the libvirtd daemon, providing
an implementation of the virtual network APIs using the Linux
bridge capabilities.

%package daemon-driver-nwfilter
Summary:        A nwfilter driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       ebtables
Requires:       iptables
# TODO Requires:       iptables-ipv6
Requires:       libvirt-daemon = %{version}-%{release}

%description daemon-driver-nwfilter
The nwfilter driver plugin for the libvirtd daemon, providing
an implementation of the firewall APIs using the ebtables,
iptables and ip6tables capabilities

%package daemon-driver-nodedev
Summary:        Nodedev driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}

%description daemon-driver-nodedev
The nodedev driver plugin for the libvirtd daemon, providing
an implementation of the node device APIs using the udev
capabilities.

%package daemon-driver-interface
Summary:        Interface driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}

%description daemon-driver-interface
The interface driver plugin for the libvirtd daemon, providing
an implementation of the network interface APIs using the
netcontrol library

%package daemon-driver-secret
Summary:        Secret driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}

%description daemon-driver-secret
The secret driver plugin for the libvirtd daemon, providing
an implementation of the secret key APIs.

%package daemon-driver-storage
Summary:        Storage driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}
Requires:       nfs-utils
# For mkfs
Requires:       util-linux
%if %{with_qemu}
# From QEMU RPMs
Requires:       /usr/bin/qemu-img
%endif
# For LVM drivers
Requires:       lvm2
# For ISCSI driver
Requires:       open-iscsi
# For disk driver
Requires:       device-mapper
Requires:       parted
# For multipath support
Requires:       device-mapper

%description daemon-driver-storage
The storage driver plugin for the libvirtd daemon, providing
an implementation of the storage APIs using LVM, iSCSI,
parted and more.

%if %{with_qemu}

%package daemon-driver-qemu
Summary:        Qemu driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}
# There really is a hard cross-driver dependency here
Requires:       /usr/bin/qemu-img
Requires:       libvirt-daemon-driver-network = %{version}-%{release}
Requires:       libvirt-daemon-driver-storage = %{version}-%{release}
# For image compression
Requires:       bzip2
Requires:       gzip
Requires:       lzop
Requires:       qemu
Requires:       xz

%description daemon-driver-qemu
The qemu driver plugin for the libvirtd daemon, providing
an implementation of the hypervisor driver APIs using QEMU.
%endif

%if %{with_lxc}

%package daemon-driver-lxc
Summary:        LXC driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}
# There really is a hard cross-driver dependency here
Requires:       libvirt-daemon-driver-network = %{version}-%{release}

%description daemon-driver-lxc
The LXC driver plugin for the libvirtd daemon, providing
an implementation of the hypervisor driver APIs using
the Linux kernel
%endif

%if %{with_uml}

%package daemon-driver-uml
Summary:        Uml driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}

%description daemon-driver-uml
The UML driver plugin for the libvirtd daemon, providing
an implementation of the hypervisor driver APIs using
User Mode Linux
%endif

%if %{with_xen}

%package daemon-driver-xen
Summary:        Xen driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}

%description daemon-driver-xen
The Xen driver plugin for the libvirtd daemon, providing
an implementation of the hypervisor driver APIs using Xen.
%endif

%if %{with_vbox}

%package daemon-driver-vbox
Summary:        VirtualBox driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}

%description daemon-driver-vbox
The vbox driver plugin for the libvirtd daemon, providing
an implementation of the hypervisor driver APIs using
VirtualBox
%endif

%if %{with_libxl}

%package daemon-driver-libxl
Summary:        Libxl driver plugin for the libvirtd daemon
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}

%description daemon-driver-libxl
The Libxl driver plugin for the libvirtd daemon, providing
an implementation of the hypervisor driver APIs using libxl.
%endif

%if %{with_qemu}

%package daemon-qemu
Summary:        Server side daemon & driver required to run QEMU guests
Group:          Development/Libraries/C and C++

Requires:       libvirt-daemon = %{version}-%{release}
Requires:       libvirt-daemon-driver-interface = %{version}-%{release}
Requires:       libvirt-daemon-driver-network = %{version}-%{release}
Requires:       libvirt-daemon-driver-nodedev = %{version}-%{release}
Requires:       libvirt-daemon-driver-nwfilter = %{version}-%{release}
Requires:       libvirt-daemon-driver-qemu = %{version}-%{release}
Requires:       libvirt-daemon-driver-secret = %{version}-%{release}
Requires:       libvirt-daemon-driver-storage = %{version}-%{release}

%description daemon-qemu
Server side daemon and driver required to manage the virtualization
capabilities of the QEMU emulators
%endif

%if %{with_lxc}

%package daemon-lxc
Summary:        Server side daemon & driver required to run LXC guests
Group:          Development/Libraries/C and C++

Requires:       libvirt-daemon = %{version}-%{release}
Requires:       libvirt-daemon-driver-interface = %{version}-%{release}
Requires:       libvirt-daemon-driver-lxc = %{version}-%{release}
Requires:       libvirt-daemon-driver-network = %{version}-%{release}
Requires:       libvirt-daemon-driver-nodedev = %{version}-%{release}
Requires:       libvirt-daemon-driver-nwfilter = %{version}-%{release}
Requires:       libvirt-daemon-driver-secret = %{version}-%{release}
Requires:       libvirt-daemon-driver-storage = %{version}-%{release}

%description daemon-lxc
Server side daemon and driver required to manage the virtualization
capabilities of LXC
%endif

%if %{with_uml}

%package daemon-uml
Summary:        Server side daemon & driver required to run UML guests
Group:          Development/Libraries/C and C++

Requires:       libvirt-daemon = %{version}-%{release}
Requires:       libvirt-daemon-driver-interface = %{version}-%{release}
Requires:       libvirt-daemon-driver-network = %{version}-%{release}
Requires:       libvirt-daemon-driver-nodedev = %{version}-%{release}
Requires:       libvirt-daemon-driver-nwfilter = %{version}-%{release}
Requires:       libvirt-daemon-driver-secret = %{version}-%{release}
Requires:       libvirt-daemon-driver-storage = %{version}-%{release}
Requires:       libvirt-daemon-driver-uml = %{version}-%{release}

%description daemon-uml
Server side daemon and driver required to manage the virtualization
capabilities of UML
%endif

%if %{with_xen} || %{with_libxl}

%package daemon-xen
Summary:        Server side daemon & driver required to run XEN guests
Group:          Development/Libraries/C and C++

Requires:       libvirt-daemon = %{version}-%{release}
    %if %{with_xen}
Requires:       libvirt-daemon-driver-xen = %{version}-%{release}
    %endif
    %if %{with_libxl}
Requires:       libvirt-daemon-driver-libxl = %{version}-%{release}
    %endif
Requires:       libvirt-daemon-driver-interface = %{version}-%{release}
Requires:       libvirt-daemon-driver-network = %{version}-%{release}
Requires:       libvirt-daemon-driver-nodedev = %{version}-%{release}
Requires:       libvirt-daemon-driver-nwfilter = %{version}-%{release}
Requires:       libvirt-daemon-driver-secret = %{version}-%{release}
Requires:       libvirt-daemon-driver-storage = %{version}-%{release}
Requires:       xen

%description daemon-xen
Server side daemon and driver required to manage the virtualization
capabilities of XEN
%endif

%if %{with_vbox}

%package daemon-vbox
Summary:        Server side daemon & driver required to run VirtualBox guests
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon = %{version}-%{release}
Requires:       libvirt-daemon-driver-interface = %{version}-%{release}
Requires:       libvirt-daemon-driver-network = %{version}-%{release}
Requires:       libvirt-daemon-driver-nodedev = %{version}-%{release}
Requires:       libvirt-daemon-driver-nwfilter = %{version}-%{release}
Requires:       libvirt-daemon-driver-secret = %{version}-%{release}
Requires:       libvirt-daemon-driver-storage = %{version}-%{release}
Requires:       libvirt-daemon-driver-vbox = %{version}-%{release}
Requires:       virtualbox

%description daemon-vbox
Server side daemon and driver required to manage the virtualization
capabilities of VirtualBox
%endif

%package client
Summary:        Client side library and utilities of the libvirt library
Group:          Development/Libraries/C and C++
Requires:       ncurses
Requires:       readline
# So remote clients can access libvirt over SSH tunnel
# (client invokes 'nc' against the UNIX socket on the server)
Requires:       netcat-openbsd
# Needed by libvirt-guests init script.
Requires:       gettext-runtime
# Needed by virt-pki-validate script.
Requires:       cyrus-sasl
Requires:       gnutls
# Not technically required, but makes 'out-of-box' config
# work correctly & doesn't have onerous dependencies
Requires:       cyrus-sasl-digestmd5

%description client
Shared libraries and client binaries needed to access to the
virtualization capabilities of recent versions of Linux (and other OSes).

%package devel
Summary:        Libraries, includes, etc. to compile with the libvirt library
Group:          Development/Libraries/C and C++
Requires:       %{name}-client = %{version}-%{release}
Requires:       %{name}-doc = %{version}-%{release}
Requires:       pkg-config

%description devel
Include header files & development libraries for the libvirt C library.


%if %{with_sanlock}

%package lock-sanlock
Summary:        Sanlock lock manager plugin for QEMU driver
Group:          Development/Libraries/C and C++
Requires:       sanlock >= 2.4
# for virt-sanlock-cleanup require augeas
Requires:       %{name}-client = %{version}-%{release}
Requires:       %{name}-daemon = %{version}-%{release}
Requires:       augeas

%description lock-sanlock
Includes the Sanlock lock manager plugin for the QEMU driver
%endif

%if %{with_wireshark}

%package -n wireshark-plugin-libvirt
Summary:        Wireshark plugin for libvirt RPC protocol
Group:          Productivity/Networking/Diagnostic
Requires:       %{name}-client = %{version}-%{release}
Requires:       wireshark

%description -n wireshark-plugin-libvirt
Wireshark dissector plugin for better analysis of libvirt RPC traffic.
%endif

%package nss
Summary:        Libvirt plugin for Name Service Switch
Group:          Development/Libraries/C and C++
Requires:       libvirt-daemon-driver-network = %{version}-%{release}

%description nss
libvirt plugin for NSS for translating domain names into IP addresses.

%prep
%setup -q
%patch0 -p1
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%patch8 -p1
%patch9 -p1
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p1
%patch14 -p1
%patch15 -p1
%patch16 -p1
%patch17 -p1
%patch18 -p1
%patch19 -p1
%patch20 -p1
%patch21 -p1
%patch22 -p1
%patch23 -p1
%patch24 -p1
%patch25 -p1
%patch26 -p1
%patch27 -p1
%patch28 -p1
%patch29 -p1
%patch30 -p1
%patch31 -p1
%patch32 -p1
%patch33 -p1
%patch34 -p1
%patch35 -p1
%patch36 -p1
%patch37 -p1
%patch38 -p1
%patch39 -p1
%patch40 -p1
%patch41 -p1
%patch42 -p1
%patch43 -p1
%patch44 -p1
%patch45 -p1
%patch46 -p1
%patch47 -p1
%patch48 -p1
%patch49 -p1
%patch50 -p1
%patch51 -p1
%patch52 -p1
%patch53 -p1
%patch54 -p1
%patch55 -p1
%patch56 -p1
%patch57 -p1
%patch58 -p1
%patch59 -p1
%patch60 -p1
%patch61 -p1
%patch62 -p1
%patch63 -p1
%patch64 -p1
%patch65 -p1
%patch66 -p1
%patch67 -p1
%patch68 -p1
%patch69 -p1
%patch70 -p1
%patch71 -p1
%patch72 -p1
%patch100 -p1
%patch101 -p1
%patch102 -p1
%patch150 -p1
%patch151 -p1
%patch152 -p1
%patch153 -p1
%patch154 -p1
%patch155 -p1
%patch156 -p1
%patch157 -p1
%patch158 -p1
%patch200 -p1
%patch201 -p1
%patch202 -p1
%patch203 -p1
%patch204 -p1
%patch205 -p1
%patch206 -p1
%patch207 -p1
%patch208 -p1
%patch209 -p1
%patch210 -p1
%patch211 -p1
%patch212 -p1
%patch213 -p1
%patch214 -p1
%patch215 -p1
%patch300 -p1

%build
%if %{with_xen}
    %define arg_xen --with-xen
%else
    %define arg_xen --without-xen
%endif
%if %{with_qemu}
    %define arg_qemu --with-qemu
%else
    %define arg_qemu --without-qemu
%endif
%if %{with_openvz}
    %define arg_openvz --with-openvz
%else
    %define arg_openvz --without-openvz
%endif
%if %{with_lxc}
    %define arg_lxc --with-lxc
%else
    %define arg_lxc --without-lxc
%endif
%if %{with_vbox}
    %define arg_vbox --with-vbox
%else
    %define arg_vbox --without-vbox
%endif
%if %{with_uml}
    %define arg_uml --with-uml
%else
    %define arg_uml --without-uml
%endif
%if %{with_phyp}
    %define arg_phyp --with-phyp
%else
    %define arg_phyp --without-phyp
%endif
%if %{with_esx}
    %define arg_esx --with-esx
%else
    %define arg_esx --without-esx
%endif
%if %{with_vmware}
    %define arg_vmware --with-vmware
%else
    %define arg_vmware --without-vmware
%endif
%if %{with_hyperv}
    %define arg_hyperv --with-hyperv
%else
    %define arg_hyperv --without-hyperv
%endif
%if %{with_libxl}
    %define arg_libxl --with-libxl
%else
    %define arg_libxl --without-libxl
%endif
%if %{with_storage_rbd}
    %define arg_storage_rbd --with-storage-rbd
%else
    %define arg_storage_rbd --without-storage-rbd
%endif
%if %{with_storage_sheepdog}
    %define arg_storage_sheepdog --with-storage-sheepdog
%else
    %define arg_storage_sheepdog --without-storage-sheepdog
%endif
%if %{with_storage_gluster}
    %define arg_storage_gluster --with-storage-gluster
%else
    %define arg_storage_gluster --without-storage-gluster
%endif
%if %{with_numactl}
    %define arg_numactl --with-numactl
%else
    %define arg_numactl --without-numactl
%endif
%if %{with_numad}
    %define arg_numad --with-numad
%else
    %define arg_numad --without-numad
%endif
%if %{with_apparmor}
    %define arg_apparmor --with-apparmor
    %define arg_apparmor_profiles --with-apparmor-profiles
%else
    %define arg_apparmor --without-apparmor
%endif
%if %{with_sanlock}
    %define arg_sanlock --with-sanlock
%else
    %define arg_sanlock --without-sanlock
%endif
%if %{with_systemd}
    %define arg_init_script --with-init-script=systemd
%else
    %define arg_init_script --with-init-script=redhat
%endif
%if %{with_firewalld}
    %define arg_firewalld --with-firewalld
%else
    %define arg_firewalld --without-firewalld
%endif
%if %{with_wireshark}
    %define arg_wireshark --with-wireshark-dissector
%else
    %define arg_wireshark --without-wireshark-dissector
%endif

%define arg_selinux_mount --with-selinux-mount="/selinux"

# x86_64 UEFI firmwares
# To more closely resemble actual hardware, we use the firmwares with
# embedded Microsoft keys
LOADERS="/usr/share/qemu/ovmf-x86_64-ms-code.bin:/usr/share/qemu/ovmf-x86_64-ms-vars.bin"
# aarch64 UEFI firmwares
LOADERS="$LOADERS:/usr/share/qemu/aavmf-aarch64-code.bin:/usr/share/qemu/aavmf-aarch64-vars.bin"
%define arg_loader_nvram --with-loader-nvram="$LOADERS"

autoreconf -f -i
export CFLAGS="$RPM_OPT_FLAGS"
%configure --disable-static --with-pic \
           %{?arg_xen} \
           %{?arg_qemu} \
           %{?arg_openvz} \
           %{?arg_lxc} \
           %{?arg_vbox} \
           %{?arg_libxl} \
           --with-sasl \
           --with-avahi \
           --with-polkit \
           --with-libvirtd \
           %{?arg_uml} \
           %{?arg_phyp} \
           %{?arg_esx} \
           %{?arg_hyperv} \
           %{?arg_vmware} \
           --without-xenapi \
           --without-vz \
           --without-bhyve \
           --with-interface \
           --with-network \
           --with-storage-fs \
           --with-storage-lvm \
           --with-storage-iscsi \
           --with-storage-disk \
           --with-storage-mpath \
           %{?arg_storage_rbd} \
           %{?arg_storage_sheepdog} \
           %{?arg_storage_gluster} \
           %{?arg_numactl} \
           %{?arg_numad} \
           --with-capng \
           --with-fuse \
           --without-netcf \
           --with-netcontrol \
           --with-selinux \
           %{?arg_selinux_mount} \
           %{?arg_apparmor} \
           %{?arg_apparmor_profiles} \
           --with-udev \
           --with-yajl \
           %{?arg_sanlock} \
           --with-libpcap \
           --with-macvtap \
           --with-audit \
           --with-dtrace \
           --with-driver-modules \
           %{?arg_firewalld} \
           %{?arg_wireshark} \
           --with-nss-plugin \
           --libexecdir=%{_libdir}/%{name} \
           --with-qemu-user=%{qemu_user} \
           --with-qemu-group=%{qemu_group} \
           %{?arg_loader_nvram} \
           --without-login-shell \
           %{arg_init_script} \
           ac_cv_path_MODPROBE=/sbin/modprobe \
           ac_cv_path_UDEVADM=/sbin/udevadm \
           ac_cv_path_SHOWMOUNT=/usr/sbin/showmount \
           ac_cv_path_PARTED=/usr/sbin/parted \
           ac_cv_path_QEMU_BRIDGE_HELPER=/usr/lib/qemu-bridge-helper
make V=1 %{?jobs:-j%jobs} DOCS_DIR=%{_docdir}/%{name}-python EXAMPLE_DIR=%{_docdir}/%{name}-python/examples HTML_DIR=%{_docdir}/%{name}
gzip -9 ChangeLog

%install
%makeinstall SYSTEMD_UNIT_DIR=%{_unitdir} DOCS_DIR=%{_docdir}/%{name}-python EXAMPLE_DIR=%{_docdir}/%{name}-python/examples HTML_DIR=%{_docdir}/%{name}
make -C examples distclean
cp examples/lxcconvert/virt-lxc-convert $RPM_BUILD_ROOT%{_bindir}
rm -f $RPM_BUILD_ROOT%{_libdir}/*.la
%if %{with_wireshark}
rm -f $RPM_BUILD_ROOT%{_libdir}/wireshark/plugins/*/libvirt.la
mv $RPM_BUILD_ROOT%{_libdir}/wireshark/plugins/*/libvirt.so \
   $RPM_BUILD_ROOT%{_libdir}/wireshark/plugins/libvirt.so
%endif
rm -f $RPM_BUILD_ROOT%{_libdir}/*.a
rm -f $RPM_BUILD_ROOT%{_libdir}/%{name}/lock-driver/*.la
rm -f $RPM_BUILD_ROOT%{_libdir}/%{name}/lock-driver/*.a
rm -f $RPM_BUILD_ROOT%{_libdir}/%{name}/connection-driver/*.la
rm -f $RPM_BUILD_ROOT%{_libdir}/%{name}/connection-driver/*.a
# remove currently unsupported locale(s)
for dir in $RPM_BUILD_ROOT/usr/share/locale/*
do
  sdir=`echo $dir | sed "s|$RPM_BUILD_ROOT||"`
  if test -d $sdir ; then continue ; fi
  rm -rfv "$dir"
done

mkdir -p $RPM_BUILD_ROOT/%{_localstatedir}/lib/libvirt
mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/libvirt/hooks
%find_lang %{name}
# Add a README to the libvirt package with a note about the empty
# file list
cat > $RPM_BUILD_ROOT%{_docdir}/libvirt/libvirt.README << 'EOF'
The libvirt package no longer contains any files.  It exists now
only to fulfill its 'Provides' contract.
EOF
install -d -m 0755 $RPM_BUILD_ROOT%{_localstatedir}/lib/libvirt/dnsmasq/
install -d -m 0755 $RPM_BUILD_ROOT%{_datadir}/libvirt/networks/
cp $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/qemu/networks/default.xml \
   $RPM_BUILD_ROOT%{_datadir}/libvirt/networks/default.xml
rm -f $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/qemu/networks/default.xml
rm -f $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/qemu/networks/autostart/default.xml
# Strip auto-generated UUID - we need it generated per-install
sed -i -e "/<uuid>/d" $RPM_BUILD_ROOT%{_datadir}/libvirt/networks/default.xml
%if %{with_lxc}
cat > $RPM_BUILD_ROOT%{_docdir}/libvirt/libvirt-daemon-lxc.README << 'EOF'
Any empty package encapsulating requirements for a libvirtd capable
of managing LXC.
EOF
%else
rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/lxc.conf
rm -f $RPM_BUILD_ROOT%{_datadir}/augeas/lenses/libvirtd_lxc.aug
rm -f $RPM_BUILD_ROOT%{_datadir}/augeas/lenses/tests/test_libvirtd_lxc.aug
rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/libvirtd.lxc
%endif
%if %{with_qemu}
cat > $RPM_BUILD_ROOT%{_docdir}/libvirt/libvirt-daemon-qemu.README << 'EOF'
Any empty package encapsulating requirements for a libvirtd capable
of managing QEMU/KVM.
EOF
%else
rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/qemu.conf
rm -f $RPM_BUILD_ROOT%{_datadir}/augeas/lenses/libvirtd_qemu.aug
rm -f $RPM_BUILD_ROOT%{_datadir}/augeas/lenses/tests/test_libvirtd_qemu.aug
rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/libvirtd.qemu
%endif
%if %{with_uml}
cat > $RPM_BUILD_ROOT%{_docdir}/libvirt/libvirt-daemon-uml.README << 'EOF'
Any empty package encapsulating requirements for a libvirtd capable
of managing UML.
EOF
%else
rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/libvirtd.uml
%endif
%if %{with_vbox}
cat > $RPM_BUILD_ROOT%{_docdir}/libvirt/libvirt-daemon-vbox.README << 'EOF'
Any empty package encapsulating requirements for a libvirtd capable
of managing VirtualBox.
EOF
%endif
%if %{with_xen} || %{with_libxl}
cat > $RPM_BUILD_ROOT%{_docdir}/libvirt/libvirt-daemon-xen.README << 'EOF'
Any empty package encapsulating requirements for a libvirtd capable
of managing Xen.
EOF
%endif
%if ! %{with_libxl}
rm -f $RPM_BUILD_ROOT%{_sysconfdir}/libvirt/libxl.conf
rm -f $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/libvirtd.libxl
rm -f $RPM_BUILD_ROOT%{_datadir}/augeas/lenses/libvirtd_libxl.aug
rm -f $RPM_BUILD_ROOT%{_datadir}/augeas/lenses/tests/test_libvirtd_libxl.aug
%endif
%if ! %{with_sanlock}
rm -f $RPM_BUILD_ROOT%{_datadir}/augeas/lenses/libvirt_sanlock.aug
rm -f $RPM_BUILD_ROOT%{_datadir}/augeas/lenses/tests/test_libvirt_sanlock.aug
%endif

# init scripts
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/init.d
mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/adm/fillup-templates
# Currently using our own libvirtd init script
rm -f $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d/libvirtd
%if %{with_systemd}
ln -s %{_sbindir}/service $RPM_BUILD_ROOT%{_sbindir}/rclibvirtd
%else
install %SOURCE3 $RPM_BUILD_ROOT%{_sysconfdir}/init.d/libvirtd
ln -s /etc/init.d/libvirtd $RPM_BUILD_ROOT%{_sbindir}/rclibvirtd
%endif
mv $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/libvirtd $RPM_BUILD_ROOT%{_localstatedir}/adm/fillup-templates/sysconfig.libvirtd
rm -f $RPM_BUILD_ROOT/usr/lib/sysctl.d/60-libvirtd.conf
# For other services, use the in-tree scripts
%if %{with_systemd}
rm -f $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d/virtlogd
ln -s %{_sbindir}/service $RPM_BUILD_ROOT%{_sbindir}/rcvirtlogd
rm -f $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d/virtlockd
ln -s %{_sbindir}/service $RPM_BUILD_ROOT%{_sbindir}/rcvirtlockd
%else
mv $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d/virtlogd $RPM_BUILD_ROOT%{_sysconfdir}/init.d/virtlogd
ln -s /etc/init.d/virtlogd $RPM_BUILD_ROOT%{_sbindir}/rcvirtlogd
mv $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d/virtlockd $RPM_BUILD_ROOT%{_sysconfdir}/init.d/virtlockd
ln -s /etc/init.d/virtlockd $RPM_BUILD_ROOT%{_sbindir}/rcvirtlockd
%endif
mv $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/virtlogd $RPM_BUILD_ROOT%{_localstatedir}/adm/fillup-templates/sysconfig.virtlogd
mv $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/virtlockd $RPM_BUILD_ROOT%{_localstatedir}/adm/fillup-templates/sysconfig.virtlockd
#install firewall definitions format is described here:
#/usr/share/SuSEfirewall2/services/TEMPLATE
mkdir -p $RPM_BUILD_ROOT/%{_fwdefdir}
install -m 644 %{S:4} $RPM_BUILD_ROOT/%{_fwdefdir}/libvirtd-relocation-server
%if %{with_systemd}
rm -f $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d/libvirt-guests
ln -s %{_sbindir}/service $RPM_BUILD_ROOT%{_sbindir}/rclibvirt-guests
%else
mv $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d/libvirt-guests $RPM_BUILD_ROOT%{_sysconfdir}/init.d/libvirt-guests
mkdir -p $RPM_BUILD_ROOT%{_sbindir}
ln -s %{_sysconfdir}/init.d/libvirt-guests $RPM_BUILD_ROOT%{_sbindir}/rclibvirt-guests
%endif
mv $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/libvirt-guests $RPM_BUILD_ROOT%{_localstatedir}/adm/fillup-templates/sysconfig.libvirt-guests
%ifarch %{power64} s390x x86_64
mv $RPM_BUILD_ROOT%{_datadir}/systemtap/tapset/libvirt_probes.stp \
   $RPM_BUILD_ROOT%{_datadir}/systemtap/tapset/libvirt_probes-64.stp
mv $RPM_BUILD_ROOT%{_datadir}/systemtap/tapset/libvirt_qemu_probes.stp \
   $RPM_BUILD_ROOT%{_datadir}/systemtap/tapset/libvirt_qemu_probes-64.stp
%endif
%fdupes -s $RPM_BUILD_ROOT

%clean
rm -rf $RPM_BUILD_ROOT

%check
cd tests
SKIP_TESTS=""
# These tests don't current work in a mock build root
# virnetsockettest: needs unsupported linux-user syscalls
SKIP_TESTS="$SKIP_TESTS virnetsockettest"
# virportallocatortest fails on aarch64 due to unsupported IPV6_V6ONLY flag
%ifarch aarch64
SKIP_TESTS="$SKIP_TESTS virportallocatortest"
%endif
for i in $SKIP_TESTS
do
  rm -f $i
  printf 'int main(void) { return 0; }' > $i.c
done
make

if ! make check VIR_TEST_DEBUG=1
then
  cat test-suite.log || true
  exit 1
fi

%pre daemon
%if %{with_systemd}
%service_add_pre libvirtd.service
%service_add_pre virtlockd.service virtlockd.socket
%service_add_pre virtlogd.service virtlogd.socket
%endif
%{_bindir}/getent group libvirt >/dev/null || \
  %{_sbindir}/groupadd -r libvirt || :

%post daemon
/sbin/ldconfig
%if %{with_systemd}
%service_add_post libvirtd.service
%service_add_post virtlockd.service virtlockd.socket
%service_add_post virtlogd.service virtlogd.socket
%endif
%{fillup_only -n libvirtd}
%{fillup_only -n virtlockd}
%{fillup_only -n virtlogd}

%preun daemon
%if %{with_systemd}
%service_del_preun libvirtd.service
%service_del_preun virtlockd.service virtlockd.socket
%service_del_preun virtlogd.service virtlogd.socket
%else
%stop_on_removal libvirtd
%stop_on_removal virtlockd
%stop_on_removal virtlogd
%endif

%postun daemon
/sbin/ldconfig
%if %{with_systemd}
# On upgrade, defer restarting daemons until %posttrans
if test $1 -eq 0 ; then
    for service in libvirtd virtlockd virtlogd ; do
        rm -f "/var/lib/systemd/migrated/$service" 2> /dev/null || :
    done
    /usr/bin/systemctl daemon-reload >/dev/null 2>&1 || :
fi
%else
%restart_on_update libvirtd
%restart_on_update virtlockd
%restart_on_update virtlogd
%endif
%if %{with_systemd}
    %service_del_postun libvirtd.service
    %service_del_postun virtlockd.service virtlockd.socket
    %service_del_postun virtlogd.service virtlogd.socket
%else
    %insserv_cleanup
%endif

%posttrans daemon
# All connection drivers should be installed post transaction.
# Time to restart daemons.
%if %{with_systemd}
if test "$YAST_IS_RUNNING" != "instsys" -a "$DISABLE_RESTART_ON_UPDATE" != yes ; then
    for service in libvirtd virtlockd virtlogd ; do
        /usr/bin/systemctl try-restart ${service}.service >/dev/null 2>&1 || :
    done
fi
%endif

# In upgrade scenario we must explicitly enable virtlockd/virtlogd
# sockets, if libvirtd is already enabled and start them if
# libvirtd is running, otherwise you'll get failures to start
# guests
%triggerpostun daemon -- libvirt-daemon < 1.3.0
if [ $1 -ge 1 ] ; then
%if %{with_systemd}
        /usr/bin/systemctl is-enabled libvirtd.service 1>/dev/null 2>&1 &&
            /usr/bin/systemctl enable virtlogd.socket || :
        /usr/bin/systemctl is-active libvirtd.service 1>/dev/null 2>&1 &&
            /usr/bin/systemctl start virtlogd.socket || :
%else
        /sbin/chkconfig libvirtd 1>/dev/null 2>&1 &&
            /sbin/chkconfig virtlogd on || :
        /sbin/service libvirtd status 1>/dev/null 2>&1 &&
            /sbin/service virtlogd start || :
%endif
fi

%post daemon-config-network
# Install the default network if one doesn't exist
if test $1 -eq 1 && test ! -f %{_sysconfdir}/libvirt/qemu/networks/default.xml ; then
    UUID=`/usr/bin/uuidgen`
    sed -e "s,</name>,</name>\n  <uuid>$UUID</uuid>," \
         < %{_datadir}/libvirt/networks/default.xml \
         > %{_sysconfdir}/libvirt/qemu/networks/default.xml
fi

%pre client
%if %{with_systemd}
%service_add_pre libvirt-guests.service
%endif

%post client
/sbin/ldconfig
%if %{with_systemd}
%service_add_post libvirt-guests.service
%endif
%{fillup_only -n libvirt-guests}

%preun client
%if %{with_systemd}
%service_del_preun libvirt-guests.service
%else
%stop_on_removal libvirt-guests
%endif
if [ $1 = 0 ]; then
    rm -f /var/lib/libvirt/libvirt-guests
fi

%postun client
/sbin/ldconfig
%if %{with_systemd}
%service_del_postun libvirt-guests.service
%endif
%insserv_cleanup

%post nss
/sbin/ldconfig

%postun nss
/sbin/ldconfig

%files
%doc %{_docdir}/%{name}/libvirt.README

%files daemon
%{_sbindir}/libvirtd
%{_sbindir}/virtlogd
%{_sbindir}/virtlockd
%dir %{_libdir}/%{name}
%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/
%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/hooks
%{_localstatedir}/adm/fillup-templates/sysconfig.libvirtd
%{_localstatedir}/adm/fillup-templates/sysconfig.virtlogd
%{_localstatedir}/adm/fillup-templates/sysconfig.virtlockd
%if %{with_systemd}
%{_unitdir}/libvirtd.service
%{_unitdir}/virtlogd.service
%{_unitdir}/virtlogd.socket
%{_unitdir}/virtlockd.service
%{_unitdir}/virtlockd.socket
%else
%config /etc/init.d/libvirtd
%config /etc/init.d/virtlogd
%config /etc/init.d/virtlockd
%endif
%{_sbindir}/rclibvirtd
%{_sbindir}/rcvirtlogd
%{_sbindir}/rcvirtlockd
%config(noreplace) %{_sysconfdir}/libvirt/libvirtd.conf
%config(noreplace) %{_sysconfdir}/logrotate.d/libvirtd
%config(noreplace) %{_sysconfdir}/libvirt/virtlogd.conf
%config(noreplace) %{_sysconfdir}/libvirt/virtlockd.conf
%dir %{_datadir}/augeas/
%dir %{_datadir}/augeas/lenses
%dir %{_datadir}/augeas/lenses/tests
%{_datadir}/augeas/lenses/libvirtd.aug
%{_datadir}/augeas/lenses/tests/test_libvirtd.aug
%{_datadir}/augeas/lenses/virtlogd.aug
%{_datadir}/augeas/lenses/tests/test_virtlogd.aug
%{_datadir}/augeas/lenses/virtlockd.aug
%{_datadir}/augeas/lenses/tests/test_virtlockd.aug
%{_datadir}/augeas/lenses/libvirt_lockd.aug
%{_datadir}/augeas/lenses/tests/test_libvirt_lockd.aug
%{_datadir}/systemtap/tapset/libvirt_probes*.stp
%{_datadir}/systemtap/tapset/libvirt_qemu_probes*.stp
%{_datadir}/systemtap/tapset/libvirt_functions.stp
%dir %{_localstatedir}/lib/libvirt/
%dir %attr(0711, root, root) %{_localstatedir}/lib/libvirt/images/
%dir %attr(0711, root, root) %{_localstatedir}/lib/libvirt/filesystems/
%dir %attr(0711, root, root) %{_localstatedir}/lib/libvirt/boot/
%dir %attr(0711, root, root) %{_localstatedir}/cache/libvirt/
%dir %attr(0700, root, root) %{_localstatedir}/log/libvirt/
%dir %attr(0755, root, root) %{_libdir}/%{name}/lock-driver
%attr(0755, root, root) %{_libdir}/%{name}/lock-driver/lockd.so
%if %{with_polkit_rules}
%{_datadir}/polkit-1/rules.d/50-libvirt.rules
%endif
%{_datadir}/polkit-1/actions/org.libvirt.unix.policy
%{_datadir}/polkit-1/actions/org.libvirt.api.policy
%attr(0755, root, root) %{_libdir}/%{name}/libvirt_iohelper
%doc %{_mandir}/man8/libvirtd.8*
%doc %{_mandir}/man8/virtlogd.8*
%doc %{_mandir}/man8/virtlockd.8*
%if %{with_apparmor}
%dir %{_sysconfdir}/apparmor.d
%dir %{_sysconfdir}/apparmor.d/abstractions
%dir %{_sysconfdir}/apparmor.d/libvirt
%config(noreplace) %{_sysconfdir}/apparmor.d/usr.sbin.libvirtd
%config(noreplace) %{_sysconfdir}/apparmor.d/usr.lib.libvirt.virt-aa-helper
%config(noreplace) %{_sysconfdir}/apparmor.d/abstractions/libvirt-qemu
%config(noreplace) %{_sysconfdir}/apparmor.d/abstractions/libvirt-lxc
%config(noreplace) %{_sysconfdir}/apparmor.d/libvirt/TEMPLATE.lxc
%config(noreplace) %{_sysconfdir}/apparmor.d/libvirt/TEMPLATE.qemu
%{_libdir}/%{name}/virt-aa-helper
%endif
%config %{_fwdefdir}/libvirtd-relocation-server

%files daemon-config-network
%dir %{_datadir}/libvirt/networks/
%{_datadir}/libvirt/networks/default.xml

%files daemon-config-nwfilter
%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/nwfilter/
%config %{_sysconfdir}/libvirt/nwfilter/*.xml

%files daemon-driver-interface
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_interface.so

%files daemon-driver-network
%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/qemu/
%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/qemu/networks/
%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/qemu/networks/autostart
%dir %attr(0700, root, root) %{_localstatedir}/lib/libvirt/network/
%dir %attr(0755, root, root) %{_localstatedir}/lib/libvirt/dnsmasq/
%attr(0755, root, root) %{_libdir}/%{name}/libvirt_leaseshelper
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_network.so

%files daemon-driver-nodedev
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_nodedev.so

%files daemon-driver-nwfilter
%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/nwfilter/
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_nwfilter.so

%files daemon-driver-secret
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_secret.so

%files daemon-driver-storage
%attr(0755, root, root) %{_libdir}/%{name}/libvirt_parthelper
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_storage.so

%if %{with_qemu}

%files daemon-driver-qemu
%config(noreplace) %{_sysconfdir}/libvirt/qemu.conf
%config(noreplace) %{_sysconfdir}/libvirt/qemu-lockd.conf
%config(noreplace) %{_sysconfdir}/logrotate.d/libvirtd.qemu
%dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/
%dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/cache/libvirt/qemu/
%dir %attr(0700, root, root) %{_localstatedir}/log/libvirt/qemu/
%{_datadir}/augeas/lenses/libvirtd_qemu.aug
%{_datadir}/augeas/lenses/tests/test_libvirtd_qemu.aug
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_qemu.so
%endif

%if %{with_lxc}

%files daemon-driver-lxc
%config(noreplace) %{_sysconfdir}/libvirt/lxc.conf
%config(noreplace) %{_sysconfdir}/logrotate.d/libvirtd.lxc
%dir %attr(0700, root, root) %{_localstatedir}/lib/libvirt/lxc/
%dir %attr(0700, root, root) %{_localstatedir}/log/libvirt/lxc/
%attr(0755, root, root) %{_libdir}/%{name}/libvirt_lxc
%{_datadir}/augeas/lenses/libvirtd_lxc.aug
%{_datadir}/augeas/lenses/tests/test_libvirtd_lxc.aug
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_lxc.so
%attr(0755, root, root) %{_bindir}/virt-lxc-convert
%{_bindir}/virt-create-rootfs
%doc %{_mandir}/man1/virt-create-rootfs.1*
%endif

%if %{with_uml}

%files daemon-driver-uml
%config(noreplace) %{_sysconfdir}/logrotate.d/libvirtd.uml
%dir %attr(0700, root, root) %{_localstatedir}/lib/libvirt/uml/
%dir %attr(0700, root, root) %{_localstatedir}/log/libvirt/uml/
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_uml.so
%endif

%if %{with_xen}

%files daemon-driver-xen
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_xen.so
%endif

%if %{with_libxl}

%files daemon-driver-libxl
%config(noreplace) %{_sysconfdir}/libvirt/libxl.conf
%config(noreplace) %{_sysconfdir}/logrotate.d/libvirtd.libxl
%config(noreplace) %{_sysconfdir}/libvirt/libxl-lockd.conf
%{_datadir}/augeas/lenses/libvirtd_libxl.aug
%{_datadir}/augeas/lenses/tests/test_libvirtd_libxl.aug
%dir %attr(0700, root, root) %{_localstatedir}/lib/libvirt/libxl/
%dir %attr(0700, root, root) %{_localstatedir}/log/libvirt/libxl/
%dir %{_libdir}/%{name}/connection-driver
%{_libdir}/%{name}/connection-driver/libvirt_driver_libxl.so
%endif

%if %{with_vbox}

%files daemon-driver-vbox
%{_libdir}/%{name}/connection-driver/libvirt_driver_vbox.so
%endif

%if %{with_qemu}

%files daemon-qemu
%doc %{_docdir}/%{name}/libvirt-daemon-qemu.README
%endif

%if %{with_lxc}

%files daemon-lxc
%doc %{_docdir}/%{name}/libvirt-daemon-lxc.README
%endif

%if %{with_uml}

%files daemon-uml
%doc %{_docdir}/%{name}/libvirt-daemon-uml.README
%endif

%if %{with_xen} || %{with_libxl}

%files daemon-xen
%doc %{_docdir}/%{name}/libvirt-daemon-xen.README
%endif

%if %{with_vbox}

%files daemon-vbox
%doc %{_docdir}/%{name}/libvirt-daemon-vbox.README
%endif

%files client -f %{name}.lang
%doc AUTHORS ChangeLog.gz NEWS README COPYING COPYING.LESSER TODO
%doc %{_mandir}/man1/virsh.1*
%doc %{_mandir}/man1/virt-admin.1*
%doc %{_mandir}/man1/virt-xml-validate.1*
%doc %{_mandir}/man1/virt-pki-validate.1*
%doc %{_mandir}/man1/virt-host-validate.1*
%config(noreplace) %{_sysconfdir}/%{name}/libvirt.conf
%config(noreplace) %{_sysconfdir}/%{name}/libvirt-admin.conf
%{_bindir}/virsh
%{_bindir}/virt-admin
%{_bindir}/virt-xml-validate
%{_bindir}/virt-pki-validate
%{_bindir}/virt-host-validate
%dir %{_libdir}/%{name}
%{_libdir}/libvirt.so.*
%{_libdir}/libvirt-qemu.so.*
%{_libdir}/libvirt-lxc.so.*
%{_libdir}/libvirt-admin.so.*
%attr(0755, root, root) %{_libdir}/%{name}/libvirt-guests.sh
%{_localstatedir}/adm/fillup-templates/sysconfig.libvirt-guests
%if %{with_systemd}
%{_unitdir}/libvirt-guests.service
%else
%config /etc/init.d/libvirt-guests
%endif
%{_sbindir}/rclibvirt-guests

%dir %{_datadir}/libvirt/
%dir %{_datadir}/libvirt/schemas/

%{_datadir}/libvirt/schemas/basictypes.rng
%{_datadir}/libvirt/schemas/capability.rng
%{_datadir}/libvirt/schemas/domain.rng
%{_datadir}/libvirt/schemas/domaincaps.rng
%{_datadir}/libvirt/schemas/domaincommon.rng
%{_datadir}/libvirt/schemas/domainsnapshot.rng
%{_datadir}/libvirt/schemas/interface.rng
%{_datadir}/libvirt/schemas/network.rng
%{_datadir}/libvirt/schemas/networkcommon.rng
%{_datadir}/libvirt/schemas/nodedev.rng
%{_datadir}/libvirt/schemas/nwfilter.rng
%{_datadir}/libvirt/schemas/secret.rng
%{_datadir}/libvirt/schemas/storagecommon.rng
%{_datadir}/libvirt/schemas/storagepool.rng
%{_datadir}/libvirt/schemas/storagevol.rng
%{_datadir}/libvirt/cpu_map.xml
%dir %{_sysconfdir}/sasl2/
%config(noreplace) %{_sysconfdir}/sasl2/libvirt.conf

%files devel
%{_libdir}/libvirt.so
%{_libdir}/libvirt-admin.so
%{_libdir}/libvirt-qemu.so
%{_libdir}/libvirt-lxc.so
%{_includedir}/libvirt
%{_libdir}/pkgconfig/libvirt.pc
%{_libdir}/pkgconfig/libvirt-admin.pc
%{_libdir}/pkgconfig/libvirt-qemu.pc
%{_libdir}/pkgconfig/libvirt-lxc.pc
%dir %{_datadir}/libvirt/api/
%{_datadir}/libvirt/api/libvirt-api.xml
%{_datadir}/libvirt/api/libvirt-admin-api.xml
%{_datadir}/libvirt/api/libvirt-qemu-api.xml
%{_datadir}/libvirt/api/libvirt-lxc-api.xml

%files doc
# Website
%dir %{_docdir}/libvirt
%doc %{_docdir}/%{name}/*.png
%doc %{_docdir}/%{name}/*.html
%doc %{_docdir}/%{name}/*.gif
%doc %{_docdir}/%{name}/*.css
%doc %{_docdir}/%{name}/html
%doc %{_docdir}/%{name}/internals
%{_datadir}/libvirt/libvirtLogo.png

# API docs
%dir %{_datadir}/gtk-doc/html/libvirt/
%doc %{_datadir}/gtk-doc/html/libvirt/*

%if %{with_sanlock}

%files lock-sanlock
%doc %{_mandir}/man8/virt-sanlock-cleanup.8*
    %if %{with_qemu}
%config(noreplace) %{_sysconfdir}/%{name}/qemu-sanlock.conf
    %endif
    %if %{with_libxl}
%config(noreplace) %{_sysconfdir}/%{name}/libxl-sanlock.conf
    %endif
%dir %{_libdir}/%{name}/lock-driver/
%attr(0755, root, root) %{_libdir}/%{name}/lock-driver/sanlock.so
%dir %{_datadir}/augeas/
%dir %{_datadir}/augeas/lenses
%dir %{_datadir}/augeas/lenses/tests
%{_datadir}/augeas/lenses/libvirt_sanlock.aug
%{_datadir}/augeas/lenses/tests/test_libvirt_sanlock.aug
%dir %attr(0700, root, root) %{_localstatedir}/lib/%{name}/sanlock
%{_sbindir}/virt-sanlock-cleanup
%attr(0755, root, root) %{_libdir}/%{name}/libvirt_sanlock_helper
%endif

%if %{with_wireshark}

%files -n wireshark-plugin-libvirt
%{_libdir}/wireshark/plugins/libvirt.so
%endif

%files nss
%{_libdir}/libnss_libvirt.so.2

%changelog