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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
# virtual/vserver.pp -- manage vservers
modules_dir{ "virtual/contexts": }
class vserver::host {
# make sure we have the ability to query for lsbdistcodename
include assert_lsbdistcodename
$util-vserver_version = $lsbdistcodename ? {
etch => "0.30.215-2~bpo40+1",
lenny => latest,
default => latest.
}
package {
"util-vserver":
ensure => $util-vserver_version;
debootstrap:
ensure => installed
}
file {
"/etc/vservers":
ensure => directory,
require => Package["util-vserver"];
"/etc/vservers/local-interfaces/":
ensure => directory,
mode => 0755, owner => root, group => root,
require => File["/etc/vservers"];
}
}
define vs_create($in_domain, $legacy = false, $distro = 'etch', $debootstrap_mirror = 'http://ftp.debian.org/debian') {
$vs_name = $legacy ? { true => $name, false => $in_domain ? { '' => $name, default => "${name}.${in_domain}" } }
case $vs_name { '': { fail ( "Cannot create VServer with empty name" ) } }
exec { "/usr/sbin/vserver ${vs_name} build -m debootstrap -- -d $distro -m $debootstrap_mirror":
creates => "/etc/vservers/${vs_name}",
alias => "vs_create_${vs_name}"
}
}
# ensure: present, stopped, running
define vserver($ensure, $context, $in_domain = '', $mark = '', $legacy = false, $distro = '') {
case $in_domain { '': {}
default: { err("${fqdn}: vserver ${name} uses deprecated \$in_domain" ) }
}
$vs_name = $legacy ? { true => $name, false => $in_domain ? { '' => $name, default => "${name}.${in_domain}" } }
case $vs_name { '': { fail ( "Cannot create VServer with empty name" ) } }
$if_dir = "/etc/vservers/${vs_name}/interfaces/"
$mark_file = "/etc/vservers/${vs_name}/apps/init/mark"
# TODO: wasn't there a syntax for using arrays as case selectors??
case $ensure {
present: { vs_create{$name: in_domain => $in_domain, legacy => $legacy, distro => $distro, } }
running: { vs_create{$name: in_domain => $in_domain, legacy => $legacy, distro => $distro, } }
stopped: { vs_create{$name: in_domain => $in_domain, legacy => $legacy, distro => $distro, } }
delete: { vs_create{$name: in_domain => $in_domain, legacy => $legacy, distro => $distro, } }
default: { err("${fqdn}: vserver(${vs_name}): unknown ensure '${ensure}'") }
}
file {
$if_dir:
ensure => directory, checksum => mtime,
require => Exec["vs_create_${vs_name}"];
}
config_file {
"/etc/vservers/${vs_name}/context":
content => "${context}\n",
notify => Exec["vs_restart_${vs_name}"],
require => Exec["vs_create_${vs_name}"];
# create illegal configuration, when two vservers have the same context
# number
"/var/lib/puppet/modules/virtual/contexts/${context}":
content => "\n";
"/etc/vservers/${vs_name}/uts/nodename":
content => "${vs_name}\n",
notify => Exec["vs_restart_${vs_name}"],
require => Exec["vs_create_${vs_name}"];
"/etc/vservers/${vs_name}/name":
content => "${vs_name}\n",
require => Exec["vs_create_${vs_name}"];
}
case $ensure {
present: {
# don't start or stop the vserver, just make sure it exists, we just run a dummy status test here
exec { "test -e \$(readlink -f /etc/vservers/${vs_name}/vdir)":
require => Exec["vs_create_${vs_name}"],
alias => "vs_restart_${vs_name}",
}
}
running: {
exec { "vserver ${vs_name} start":
unless => "test -e \$(readlink -f /etc/vservers/${vs_name}/run)",
require => Exec["vs_create_${vs_name}"],
}
exec { "vserver ${vs_name} restart":
refreshonly => true,
require => Exec["vs_create_${vs_name}"],
alias => "vs_restart_${vs_name}",
subscribe => File[$if_dir],
}
case $mark {
'': {
err("${fqdn}: vserver ${vs_name} set to running, but won't be started on reboot without mark!")
file { $mark_file: ensure => absent, }
}
default: {
config_file { "/etc/vservers/${vs_name}/apps/init/mark":
content => "${mark}\n",
require => Exec["vs_create_${vs_name}"],
}
}
}
}
stopped: {
exec { "vserver ${vs_name} stop":
onlyif => "test -e \$(readlink -f /etc/vservers/${vs_name}/run || echo /doesntexist )",
require => Exec["vs_create_${vs_name}"],
# fake the restart exec in the stopped case, so the dependencies are fulfilled
alias => "vs_restart_${vs_name}",
}
file { $mark_file: ensure => absent, }
}
delete: {
exec { "/usr/bin/yes | vserver ${vs_name} delete":
alias => "vs_restart_${vs_name}",
}
}
}
}
# Changing stuff with this define won't do much good, since it relies on
# restarting the vservers to do the work, which won't clean up orphaned
# interfaces
define vs_interface($prefix = 24, $dev = '') {
file {
"/etc/vservers/local-interfaces/${name}/":
ensure => directory,
mode => 0755, owner => root, group => root;
"/etc/vservers/local-interfaces/${name}/ip":
content => "${name}\n",
mode => 0644, owner => root, group => root;
"/etc/vservers/local-interfaces/${name}/prefix":
content => "${prefix}\n",
mode => 0644, owner => root, group => root;
}
case $dev {
'': {
file {
"/etc/vservers/local-interfaces/${name}/nodev":
ensure => present,
mode => 0644, owner => root, group => root;
"/etc/vservers/local-interfaces/${name}/dev":
ensure => absent;
}
}
default: {
config_file { "/etc/vservers/local-interfaces/${name}/dev": content => $dev, }
file { "/etc/vservers/local-interfaces/${name}/nodev": ensure => absent, }
}
}
}
define vs_ip($vserver, $ip, $ensure) {
err("$fqdn is using deprecated vs_ip instead of vs_ip_binding for $name")
vs_ip_binding { $name: vserver => $vserver, ip => $ip, ensure => $ensure }
}
define vs_ip_binding($vserver, $ip, $ensure) {
case $ensure {
connected: {
file { "/etc/vservers/${vserver}/interfaces/${name}":
ensure => "/etc/vservers/local-interfaces/${ip}/",
require => [ File["/etc/vservers/local-interfaces/${ip}/"], Exec["vs_create_${vserver}"] ],
notify => Exec["vs_restart_${vserver}"],
}
}
disconnected: {
file { "/etc/vservers/${vserver}/interfaces/${name}":
ensure => absent,
}
}
default: {
err( "${fqdn}: vs_ip: ${vserver} -> ${ip}: unknown ensure: '${ensure}'" )
}
}
}
|