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