aboutsummaryrefslogtreecommitdiffstats
path: root/modules/libvirtd/manifests/init.pp
blob: fb6ffaed6b64bd426f0d3daff16fe4cbd77a2b62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
class libvirtd {
    class base {
        # make sure to use a recent enough version
        # dnsmasq-base -> for nat network
        # netcat-openbsd -> for ssh remote access
        # iptables -> for dhcp, message error was quite puzzling
        # python-* => needed for helper script
if versioncmp($::lsbdistrelease, '7') < 0 {
        package {['libvirt-utils',
                  'dnsmasq-base',
                  'netcat-openbsd',
                  'iptables',
                  'python-libvirt',
                  'python-IPy']:

        }
} else {
        package {['libvirt-utils',
                  'dnsmasq',
                  'netcat-openbsd',
                  'iptables',
                  'python2-libvirt',
                  'python-IPy']:
        }
}
        service { 'libvirtd':
            require => Package['libvirt-utils'],
        }

        #TODO remove once libvirt package is fixed to manage the directory
        file { ['/etc/libvirt/storage',
                '/etc/libvirt/storage/autostart']:
            ensure  => directory,
            require => Package['libvirt-utils'],
        }

        file { '/usr/local/bin/storage_add.py':
            mode   => '0755',
            source => 'puppet:///modules/libvirtd/storage_add.py',
        }

        file { '/usr/local/bin/network_add.py':
            mode   => '0755',
            source => 'puppet:///modules/libvirtd/network_add.py',
        }

    }

    class kvm inherits base {
        # pull cyrus-sasl, should be checked
        package { 'qemu': }
    }

    # see http://wiki.libvirt.org/page/SSHPolicyKitSetup
    define group_access() {
        # to pull polkit and create the directory
        include libvirtd::base
        file { "/etc/polkit-1/localauthority/50-local.d/50-${name}-libvirt-remote-access.pkla":
            content => template('libvirtd/50-template-libvirt-remote-access.pkla'),
            require => Package['libvirt-utils'],
        }
        # give access to /dev/kvm to people allowed to use libvirt
        file { '/dev/kvm':
            group  => $name,
            owner  => 'root',
            mode   => '0660',
        }
    }

    define storage($path, $autostart = true) {
        include libvirtd::base

        exec { "/usr/local/bin/storage_add.py ${name} ${path}":
            creates => "/etc/libvirt/storage/${name}.xml",
            require => [File['/usr/local/bin/storage_add.py'],
                        Package['python-libvirt'] ]
        }

        #TODO use API of libvirt
        file { "/etc/libvirt/storage/autostart/${name}.xml":
            ensure  => $autostart ? {
                            true  => "/etc/libvirt/storage/${name}.xml",
                            false => absent
                      },
            require => Package['libvirt-utils'],
        }
    }

    define network( $bridge_name = 'virbr0',
                    $forward = 'nat',
                    $forward_dev = 'eth0',
                    $network = '192.168.122.0/24',
                    $tftp_root = '',
                    $disable_pxe = '',
                    $autostart = true,
                    $vm_type = 'qemu') {

        exec { '/usr/local/bin/network_add.py':
            environment => ["BRIDGE_NAME=${bridge_name}",
                            "FORWARD=${forward}",
                            "FORWARD_DEV=${forward_dev}",
                            "NETWORK=${network}",
                            "TFTP_ROOT=${tftp_root}",
                            "DISABLE_PXE=\"${disable_pxe}\""],

            creates     => "/etc/libvirt/${vm_type}/networks/${name}.xml",
            require     => [File['/usr/local/bin/network_add.py'],
                        Package['python-IPy'], Package['python-libvirt'] ]
        }

        #TODO use API of libvirt
        file { "/etc/libvirt/${vm_type}/networks/autostart/${name}.xml":
            ensure  => $autostart ? {
                            true  => "/etc/libvirt/${vm_type}/networks/${name}.xml",
                            false => absent
                      },
            require => Package['libvirt-utils'],
        }
    }
}