# Install libvirt software.
#
class libvirt::client {

    case $operatingsystem {
        centos,fedora: {
            package { [ "libvirt", "virt-manager", "virt-viewer", ]:
                ensure => installed,
            }
        }
        default: {
            fail("Not supported on ${operatingsystem}.")
        }
    }

}


# Install and configure KVM and libvirtd.
#
# === Global variables
#
#   $libvirt_admingroup:
#       Group which has access to system libvirtd.
#
class libvirt::kvm inherits libvirt::client {

    package { "qemu-kvm":
        ensure => installed,
        before => Service["libvirtd"],
    }

    if !$libvirt_admingroup {
        $libvirt_admingroup = "root"
    }

    file { "/etc/libvirt/libvirtd.conf":
        ensure  => present,
        mode    => 0644,
        owner   => "root",
        group   => "root",
        content => template("libvirt/libvirtd.conf.erb"),
        require => Package["libvirt"],
        notify  => Service["libvirtd"],
    }

    service { "libvirtd":
        ensure => running,
        enable => true,
    }

}
