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