1 |
class libvirtd { |
2 |
class base { |
3 |
# make sure to use a recent enough version |
4 |
# dnsmasq-base -> for nat network |
5 |
# netcat-openbsd -> for ssh remote access |
6 |
# iptables -> for dhcp, message error was quite puzzling |
7 |
# python-* => needed for helper script |
8 |
package {['libvirt-utils', |
9 |
'dnsmasq-base', |
10 |
'netcat-openbsd', |
11 |
'iptables', |
12 |
'python-libvirt', |
13 |
'python-IPy']: |
14 |
|
15 |
} |
16 |
|
17 |
service { 'libvirtd': |
18 |
require => Package['libvirt-utils'], |
19 |
} |
20 |
|
21 |
#TODO remove once libvirt package is fixed to manage the directory |
22 |
file { ['/etc/libvirt/storage', |
23 |
'/etc/libvirt/storage/autostart']: |
24 |
ensure => directory, |
25 |
require => Package['libvirt-utils'], |
26 |
} |
27 |
|
28 |
file { '/usr/local/bin/storage_add.py': |
29 |
mode => '0755', |
30 |
source => 'puppet:///modules/libvirtd/storage_add.py', |
31 |
} |
32 |
|
33 |
file { '/usr/local/bin/network_add.py': |
34 |
mode => '0755', |
35 |
source => 'puppet:///modules/libvirtd/network_add.py', |
36 |
} |
37 |
|
38 |
} |
39 |
|
40 |
class kvm inherits base { |
41 |
# pull cyrus-sasl, should be checked |
42 |
package { 'qemu': } |
43 |
|
44 |
} |
45 |
|
46 |
# see http://wiki.libvirt.org/page/SSHPolicyKitSetup |
47 |
define group_access() { |
48 |
# to pull polkit and create the directory |
49 |
include libvirtd::base |
50 |
file { "/etc/polkit-1/localauthority/50-local.d/50-$name-libvirt-remote-access.pkla": |
51 |
content => template('libvirtd/50-template-libvirt-remote-access.pkla'), |
52 |
require => Package['libvirt-utils'], |
53 |
} |
54 |
# give access to /dev/kvm to people allowed to use libvirt |
55 |
file { '/dev/kvm': |
56 |
group => $name, |
57 |
owner => 'root', |
58 |
mode => 660, |
59 |
} |
60 |
} |
61 |
|
62 |
define storage($path, $autostart = true) { |
63 |
include libvirtd::base |
64 |
|
65 |
exec { "/usr/local/bin/storage_add.py $name $path": |
66 |
creates => "/etc/libvirt/storage/$name.xml", |
67 |
require => [File['/usr/local/bin/storage_add.py'], |
68 |
Package['python-libvirt'] ] |
69 |
} |
70 |
|
71 |
#TODO use API of libvirt |
72 |
file { "/etc/libvirt/storage/autostart/$name.xml": |
73 |
ensure => $autostart ? { |
74 |
true => "/etc/libvirt/storage/$name.xml", |
75 |
false => absent |
76 |
}, |
77 |
require => Package['libvirt-utils'], |
78 |
} |
79 |
} |
80 |
|
81 |
define network( $bridge_name = 'virbr0', |
82 |
$forward = 'nat', |
83 |
$forward_dev = 'eth0', |
84 |
$network = '192.168.122.0/24', |
85 |
$tftp_root = '', |
86 |
$disable_pxe = '', |
87 |
$autostart = true, |
88 |
$vm_type = 'qemu') { |
89 |
|
90 |
exec { '/usr/local/bin/network_add.py': |
91 |
environment => ["BRIDGE_NAME=$bridge_name", |
92 |
"FORWARD=$forward", |
93 |
"FORWARD_DEV=$forward_dev", |
94 |
"NETWORK=$network", |
95 |
"TFTP_ROOT=$tftp_root", |
96 |
"DISABLE_PXE=\"$disable_pxe\""], |
97 |
|
98 |
creates => "/etc/libvirt/$vm_type/networks/$name.xml", |
99 |
require => [File['/usr/local/bin/network_add.py'], |
100 |
Package['python-IPy'], Package["python-libvirt"] ] |
101 |
} |
102 |
|
103 |
#TODO use API of libvirt |
104 |
file { "/etc/libvirt/$vm_type/networks/autostart/$name.xml": |
105 |
ensure => $autostart ? { |
106 |
true => "/etc/libvirt/$vm_type/networks/$name.xml", |
107 |
false => absent |
108 |
}, |
109 |
require => Package['libvirt-utils'], |
110 |
} |
111 |
} |
112 |
} |