diff options
author | Pietro Ferrari <pietro@riseup.net> | 2008-11-11 00:16:41 +0000 |
---|---|---|
committer | Pietro Ferrari <pietro@riseup.net> | 2008-11-11 00:16:41 +0000 |
commit | b43b2a2d5b0c424f3fce801f9158af60df20978a (patch) | |
tree | b1e48d613ee0d76a686a83c2ccdec4f769060c89 /manifests/vserver.pp | |
parent | 0a4679409748b22f464526ec2c4aad1771c80b80 (diff) | |
download | puppet-virtual-b43b2a2d5b0c424f3fce801f9158af60df20978a.tar.gz puppet-virtual-b43b2a2d5b0c424f3fce801f9158af60df20978a.tar.bz2 |
merge some changes from immerda repository. specially xen related.
Diffstat (limited to 'manifests/vserver.pp')
-rw-r--r-- | manifests/vserver.pp | 108 |
1 files changed, 67 insertions, 41 deletions
diff --git a/manifests/vserver.pp b/manifests/vserver.pp index b4d864a..e05c381 100644 --- a/manifests/vserver.pp +++ b/manifests/vserver.pp @@ -1,4 +1,6 @@ -# virtual/vserver.pp -- manage vservers +# virtual/vserver.pp -- manage vserver specifics +# Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at> +# See LICENSE for the full license granted to you. modules_dir{ "virtual/contexts": } @@ -31,40 +33,68 @@ class vserver::host { mode => 0755, owner => root, group => root, require => File["/etc/vservers"]; } + + file { + "/usr/local/bin/build_vserver": + source => "puppet://$server/virtual/build_vserver", + mode => 0755, owner => root, group => root, + require => [ Package['util-vserver'], Package[debootstrap], + # this comes from dbp module and is the most current puppet deb + File["/var/lib/puppet/modules/dbp/puppet_current.deb"] ]; + "/etc/vservers/local-interfaces": + ensure => directory, + mode => 0755, owner => root, group => root; + "/etc/cron.daily/vserver-hashify": + source => "puppet://$server/virtual/hashify.cron.daily", + mode => 0755, owner => root, group => root; + } } -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}" } } +define vs_create($in_domain, $context, $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}" + + case $legacy { + true: { + exec { "/bin/false # cannot create legacy vserver ${vs_name}": + creates => "/etc/vservers/${vs_name}", + alias => "vs_create_${vs_name}" + } + } + false: { + exec { "/usr/local/bin/build_vserver \"${vs_name}\" ${context} ${distro} ${debootstrap_mirror}": + creates => "/etc/vservers/${vs_name}", + require => File["/usr/local/bin/build_vserver"], + 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" ) } - } +define vserver($ensure, $context, $in_domain = '', $mark = '', $legacy = false) { + 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" ) } } - $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/" + $if_dir = "/etc/vservers/${vs_name}/interfaces" $mark_file = "/etc/vservers/${vs_name}/apps/init/mark" + $vs_name_underscores = gsub($vs_name, '\.', '_') + $cron_job = "/etc/cron.daily/puppet-vserver-${vs_name_underscores}" + # 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, } } + present: { vs_create{$name: in_domain => $in_domain, context => $context, legacy => $legacy, distro => $distro, } } + running: { vs_create{$name: in_domain => $in_domain, context => $context, legacy => $legacy, distro => $distro, } } + stopped: { vs_create{$name: in_domain => $in_domain, context => $context, legacy => $legacy, distro => $distro, } } + delete: { vs_create{$name: in_domain => $in_domain, context => $context, legacy => $legacy, distro => $distro, } } default: { err("${fqdn}: vserver(${vs_name}): unknown ensure '${ensure}'") } } @@ -93,8 +123,6 @@ define vserver($ensure, $context, $in_domain = '', $mark = '', $legacy = false, } 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)": @@ -102,11 +130,25 @@ define vserver($ensure, $context, $in_domain = '', $mark = '', $legacy = false, alias => "vs_restart_${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}", + } + } running: { exec { "vserver ${vs_name} start": unless => "test -e \$(readlink -f /etc/vservers/${vs_name}/run)", - require => Exec["vs_create_${vs_name}"], + require => [ Exec["vs_create_${vs_name}"], File["/etc/vservers/${vs_name}/context"] ] } exec { "vserver ${vs_name} restart": @@ -129,22 +171,6 @@ define vserver($ensure, $context, $in_domain = '', $mark = '', $legacy = false, } } } - - 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}", - } - } } } @@ -155,7 +181,7 @@ define vserver($ensure, $context, $in_domain = '', $mark = '', $legacy = false, define vs_interface($prefix = 24, $dev = '') { file { - "/etc/vservers/local-interfaces/${name}/": + "/etc/vservers/local-interfaces/${name}": ensure => directory, mode => 0755, owner => root, group => root; "/etc/vservers/local-interfaces/${name}/ip": @@ -193,7 +219,7 @@ define vs_ip_binding($vserver, $ip, $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}"] ], + require => [ File["/etc/vservers/local-interfaces/${ip}"], Exec["vs_create_${vserver}"] ], notify => Exec["vs_restart_${vserver}"], } } |