diff --git a/examples/virt-example.pp b/examples/virt-example.pp index 4a777b9..dbbfc1e 100644 --- a/examples/virt-example.pp +++ b/examples/virt-example.pp @@ -8,27 +8,12 @@ } class ovz-guest { - virt { "ovz1": - os_template => 'ubuntu-10.10-x86_64', - ensure => 'running', - virt_type => 'openvz', - autoboot => 'false', - configfile => 'basic', - ipaddr => ['10.0.0.1'], - features => ["nfs:on", "sit:off"], - resources_parameters => ["NUMPTY=20:20", "NUMSIGINFO=255:255"], - } - - virt { "ovz2": - ctid => 101, - os_template => 'ubuntu-11.04-x86_64', - ensure => 'stopped', - virt_type => 'openvz', - ve_root => '/home/a/root/$VEID', - ve_private => '/home/a/private/$VEID', - user => 'user:password', - capability => ["chown:off"], - devices => ["b:8:19:rw", "b:8:18:rw", "cdrom:rw"] + virt { "101": + memory => 1024, + vcpu => 4, + xml_file => "/etc/libvirt/qemu/systems/101.xml", + tmpl_cache => "debian-5.0-x86", + ensure => installed, + virt_type => "openvz" } - } diff --git a/files/libvirt/guest_starter b/files/libvirt/guest_starter new file mode 100755 index 0000000..b1f0b48 --- /dev/null +++ b/files/libvirt/guest_starter @@ -0,0 +1,68 @@ +#!/usr/bin/env ruby + +require 'facter' +class GuestStarter + def self.factory + if Facter[:virtual].value == 'xen0' + XenGuestStarter.new + else + raise "No such virtual type supported so far!" + end + end + + def guests + @guests ||= get_guests + end + + def started_guests + @started_guests ||= `virsh list | egrep -v '(^.*Id.*Name.*State$|^-*$|Domain-0|^$)' | awk '{ print $2 }'`.split("\n") + end + + def start_missing_guests + ret = 0 + guests.keys.reject{ |name| started_guests.include?(name) }.each do |guest| + if (missing_disks=guests[guest][:disks].reject{|disk| File.exists?(disk) }).empty? + start_guest(guest) + else + ret += 1 + puts "Guest #{guest} can't yet be started as the following disks are missing: #{missing_disks.join(',')}" + end + end + ret + end + + def start_guest(guest) + puts "Starting guest #{guest}" + system start_guest_cmd(guest) + end + + def get_guests + raise "Implement method!" + end + def start_guest_cmd(guest) + raise "Implement method!" + end +end + +class XenGuestStarter < GuestStarter + def get_guests + guests = {} + (Dir['/etc/xen/auto/*'] | Dir['/etc/xen/*.sxp']).each do |file| + next if File.basename(file) =~ /^xend\-.*.sxp$/ + content = File.read(file).split("\n").select{|l| l =~ /^.*(name|disk).*=.*$/ }.join("\n") + name = disk = nil + eval content + guests[name] = { + :file => file, + :disks => disk.collect{|d| d.split(':',2).last.split(',').first } + } + end + guests + end + + def start_guest_cmd(guest) + "xm create #{guests[guest][:file]}" + end +end + +exit GuestStarter.factory.start_missing_guests diff --git a/files/libvirt/random_mac_address.rb b/files/libvirt/random_mac_address.rb new file mode 100755 index 0000000..4a41db3 --- /dev/null +++ b/files/libvirt/random_mac_address.rb @@ -0,0 +1,20 @@ +#!/usr/bin/env ruby + + +prefixes = { + 'xen' => '00:16:3E', +} + +def random_hex + rand(15).to_s(16).upcase +end + +type = ARGV.shift +unless prefixes[type] + puts "Usage: #{File.basename(__FILE__)} " + puts "Where known types are: #{prefixes.keys.join(', ')}" + exit 1 +end + + +puts "#{prefixes[type]<<':'<<(0..(5-prefixes[type].split(':').length)).collect{ random_hex + random_hex }.join(':')}" diff --git a/files/xen/CentOS/sysconfig/xend b/files/xen/CentOS/sysconfig/xend new file mode 100644 index 0000000..d72f9ad --- /dev/null +++ b/files/xen/CentOS/sysconfig/xend @@ -0,0 +1,11 @@ +# NB. changing these requires a reboot. +# A simple 'xend restart' will not take effect + +# Log all hypervisor messages (cf xm dmesg) +#XENCONSOLED_LOG_HYPERVISOR=no + +# Log all guest console output (cf xm console) +#XENCONSOLED_LOG_GUESTS=no + +# Location to store guest & hypervisor logs +#XENCONSOLED_LOG_DIR=/var/log/xen/console diff --git a/files/xen/CentOS/sysconfig/xendomains b/files/xen/CentOS/sysconfig/xendomains new file mode 100755 index 0000000..cbdf5ae --- /dev/null +++ b/files/xen/CentOS/sysconfig/xendomains @@ -0,0 +1,148 @@ +## Path: System/xen +## Description: xen domain start/stop on boot +## Type: string +## Default: +# +# The xendomains script can send SysRq requests to domains on shutdown. +# If you don't want to MIGRATE, SAVE, or SHUTDOWN, this may be a possibility +# to do a quick and dirty shutdown ("s e i u o") or at least sync the disks +# of the domains ("s"). +# +XENDOMAINS_SYSRQ="" + +## Type: integer +## Default: 100000 +# +# If XENDOMAINS_SYSRQ is set, this variable determines how long to wait +# (in microseconds) after each SysRq, so the domain has a chance to react. +# If you want to a quick'n'dirty shutdown via SysRq, you may want to set +# it to a relatively high value (1200000). +# +XENDOMAINS_USLEEP=100000 + +## Type: integer +## Default: 5000000 +# +# When creating a guest domain, it is sensible to allow a little time for it +# to get started before creating another domain or proceeding through the +# boot process. Without this, the booting guests will thrash the disk as they +# start up. This timeout (in microseconds) specifies the delay after guest +# domain creation. +# +XENDOMAINS_CREATE_USLEEP=5000000 + +## Type: string +## Default: "" +# +# Set this to a non-empty string if you want to migrate virtual machines +# on shutdown. The string will be passed to the xm migrate DOMID command +# as is: It should contain the target IP address of the physical machine +# to migrate to and optionally parameters like --live. Leave empty if +# you don't want to try virtual machine relocation on shutdown. +# If migration succeeds, neither SAVE nor SHUTDOWN will be executed for +# that domain. +# +XENDOMAINS_MIGRATE="" + +## Type: string +## Default: /var/lib/xen/save +# +# Directory to save running domains to when the system (dom0) is +# shut down. Will also be used to restore domains from if # XENDOMAINS_RESTORE +# is set (see below). Leave empty to disable domain saving on shutdown +# (e.g. because you rather shut domains down). +# If domain saving does succeed, SHUTDOWN will not be executed. +# +XENDOMAINS_SAVE= + +## Type: string +## Default: "none" +# +# If you're restoring domain and the restore fails you can specify the +# type of action to be done. Possible values are: +# "none" - do nothing, standard behaviour +# "rename" - rename /savePath/invalidRestoreImage to /savePath/.invalidRestoreImage +# "delete" - delete /savePath/invalidRestoreImage +# +XENDOMAINS_RESTOREFAILTYPE="none" + +## Type: string +## Default: "--halt --wait" +# +# If neither MIGRATE nor SAVE were enabled or if they failed, you can +# try to shut down a domain by sending it a shutdown request. To do this, +# set this to "--halt --wait". Omit the "--wait" flag to avoid waiting +# for the domain to be really down. Leave empty to skip domain shutdown. +# +XENDOMAINS_SHUTDOWN="--halt --wait" + +## Type: string +## Default: "--all --halt --wait" +# +# After we have gone over all virtual machines (resp. all automatically +# started ones, see XENDOMAINS_AUTO_ONLY below) in a loop and sent SysRq, +# migrated, saved and/or shutdown according to the settings above, we +# might want to shutdown the virtual machines that are still running +# for some reason or another. To do this, set this variable to +# "--all --halt --wait", it will be passed to xm shutdown. +# Leave it empty not to do anything special here. +# (Note: This will hit all virtual machines, even if XENDOMAINS_AUTO_ONLY +# is set.) +# +XENDOMAINS_SHUTDOWN_ALL="--all --halt --wait" + +## Type: boolean +## Default: true +# +# This variable determines whether saved domains from XENDOMAINS_SAVE +# will be restored on system startup. +# +XENDOMAINS_RESTORE=false + +## Type: string +## Default: /etc/xen/auto +# +# This variable sets the directory where domains configurations +# are stored that should be started on system startup automatically. +# Leave empty if you don't want to start domains automatically +# (or just don't place any xen domain config files in that dir). +# Note that the script tries to be clever if both RESTORE and AUTO are +# set: It will first restore saved domains and then only start domains +# in AUTO which are not running yet. +# Note that the name matching is somewhat fuzzy. +# +XENDOMAINS_AUTO=/etc/xen/auto + +## Type: boolean +## Default: false +# +# If this variable is set to "true", only the domains started via config +# files in XENDOMAINS_AUTO will be treated according to XENDOMAINS_SYSRQ, +# XENDOMAINS_MIGRATE, XENDOMAINS_SAVE, XENDMAINS_SHUTDOWN; otherwise +# all running domains will be. +# Note that the name matching is somewhat fuzzy. +# +XENDOMAINS_AUTO_ONLY=false + +## Type: integer +## Default: 300 +# +# On xendomains stop, a number of xm commands (xm migrate, save, shutdown, +# shutdown --all) may be executed. In the worst case, these commands may +# stall forever, which will prevent a successful shutdown of the machine. +# If this variable is non-zero, the script will set up a watchdog timer +# for every of these xm commands and time it out after the number of seconds +# specified by this variable. +# Note that SHUTDOWN_ALL will not be called if no virtual machines or only +# zombies are still running, so you don't need to enable this timeout just +# for the zombie case. +# The setting should be large enough to make sure that migrate/save/shutdown +# can succeed. If you do live migrations, keep in mind that live migration +# of a 1GB machine over Gigabit ethernet may actually take something like +# 100s (assuming that live migration uses 10% of the network # bandwidth). +# Depending on the virtual machine, a shutdown may also require a significant +# amount of time. So better setup this variable to a huge number and hope the +# watchdog never fires. +# +XENDOMAINS_STOP_MAXWAIT=300 + diff --git a/files/xen/Debian/default/xendomains b/files/xen/Debian/default/xendomains new file mode 100644 index 0000000..4e4aba0 --- /dev/null +++ b/files/xen/Debian/default/xendomains @@ -0,0 +1,138 @@ +## Path: System/xen +## Description: xen domain start/stop on boot +## Type: string +## Default: +# +# The xendomains script can send SysRq requests to domains on shutdown. +# If you don't want to MIGRATE, SAVE, or SHUTDOWN, this may be a possibility +# to do a quick and dirty shutdown ("s e i u o") or at least sync the disks +# of the domains ("s"). +# +XENDOMAINS_SYSRQ="" + +## Type: integer +## Default: 100000 +# +# If XENDOMAINS_SYSRQ is set, this variable determines how long to wait +# (in microseconds) after each SysRq, so the domain has a chance to react. +# If you want to a quick'n'dirty shutdown via SysRq, you may want to set +# it to a relatively high value (1200000). +# +XENDOMAINS_USLEEP=100000 + +## Type: integer +## Default: 5000000 +# +# When creating a guest domain, it is sensible to allow a little time for it +# to get started before creating another domain or proceeding through the +# boot process. Without this, the booting guests will thrash the disk as they +# start up. This timeout (in microseconds) specifies the delay after guest +# domain creation. +# +XENDOMAINS_CREATE_USLEEP=5000000 + +## Type: string +## Default: "" +# +# Set this to a non-empty string if you want to migrate virtual machines +# on shutdown. The string will be passed to the xm migrate DOMID command +# as is: It should contain the target IP address of the physical machine +# to migrate to and optionally parameters like --live. Leave empty if +# you don't want to try virtual machine relocation on shutdown. +# If migration succeeds, neither SAVE nor SHUTDOWN will be executed for +# that domain. +# +XENDOMAINS_MIGRATE="" + +## Type: string +## Default: /var/lib/xen/save +# +# Directory to save running domains to when the system (dom0) is +# shut down. Will also be used to restore domains from if # XENDOMAINS_RESTORE +# is set (see below). Leave empty to disable domain saving on shutdown +# (e.g. because you rather shut domains down). +# If domain saving does succeed, SHUTDOWN will not be executed. +# +#XENDOMAINS_SAVE=/var/lib/xen/save +XENDOMAINS_SAVE= + +## Type: string +## Default: "--halt --wait" +# +# If neither MIGRATE nor SAVE were enabled or if they failed, you can +# try to shut down a domain by sending it a shutdown request. To do this, +# set this to "--halt --wait". Omit the "--wait" flag to avoid waiting +# for the domain to be really down. Leave empty to skip domain shutdown. +# +XENDOMAINS_SHUTDOWN="--halt --wait" + +## Type: string +## Default: "--all --halt --wait" +# +# After we have gone over all virtual machines (resp. all automatically +# started ones, see XENDOMAINS_AUTO_ONLY below) in a loop and sent SysRq, +# migrated, saved and/or shutdown according to the settings above, we +# might want to shutdown the virtual machines that are still running +# for some reason or another. To do this, set this variable to +# "--all --halt --wait", it will be passed to xm shutdown. +# Leave it empty not to do anything special here. +# (Note: This will hit all virtual machines, even if XENDOMAINS_AUTO_ONLY +# is set.) +# +XENDOMAINS_SHUTDOWN_ALL="--all --halt --wait" + +## Type: boolean +## Default: true +# +# This variable determines whether saved domains from XENDOMAINS_SAVE +# will be restored on system startup. +# +XENDOMAINS_RESTORE=false + +## Type: string +## Default: /etc/xen/auto +# +# This variable sets the directory where domains configurations +# are stored that should be started on system startup automatically. +# Leave empty if you don't want to start domains automatically +# (or just don't place any xen domain config files in that dir). +# Note that the script tries to be clever if both RESTORE and AUTO are +# set: It will first restore saved domains and then only start domains +# in AUTO which are not running yet. +# Note that the name matching is somewhat fuzzy. +# +XENDOMAINS_AUTO=/etc/xen/auto + +## Type: boolean +## Default: false +# +# If this variable is set to "true", only the domains started via config +# files in XENDOMAINS_AUTO will be treated according to XENDOMAINS_SYSRQ, +# XENDOMAINS_MIGRATE, XENDOMAINS_SAVE, XENDMAINS_SHUTDOWN; otherwise +# all running domains will be. +# Note that the name matching is somewhat fuzzy. +# +XENDOMAINS_AUTO_ONLY=false + +## Type: integer +## Default: 300 +# +# On xendomains stop, a number of xm commands (xm migrate, save, shutdown, +# shutdown --all) may be executed. In the worst case, these commands may +# stall forever, which will prevent a successful shutdown of the machine. +# If this variable is non-zero, the script will set up a watchdog timer +# for every of these xm commands and time it out after the number of seconds +# specified by this variable. +# Note that SHUTDOWN_ALL will not be called if no virtual machines or only +# zombies are still running, so you don't need to enable this timeout just +# for the zombie case. +# The setting should be large enough to make sure that migrate/save/shutdown +# can succeed. If you do live migrations, keep in mind that live migration +# of a 1GB machine over Gigabit ethernet may actually take something like +# 100s (assuming that live migration uses 10% of the network # bandwidth). +# Depending on the virtual machine, a shutdown may also require a significant +# amount of time. So better setup this variable to a huge number and hope the +# watchdog never fires. +# +XENDOMAINS_STOP_MAXWAIT=300 + diff --git a/lib/facter/virtual_guests.rb b/lib/facter/virtual_guests.rb new file mode 100644 index 0000000..d00b320 --- /dev/null +++ b/lib/facter/virtual_guests.rb @@ -0,0 +1,10 @@ +Facter.add('virtual_guests') do + confine :virtual => [ :xen0 ] + setcode do + # cache the list for other facts + system('((/usr/bin/find /var/cache/virsh_list.state -mmin -5 2>&1 | /bin/grep -qE \'^\/var\/cache\/virsh_list\.state$\') && [ `/bin/cat /var/cache/virsh_list.state | /usr/bin/wc -l` -gt 1 ]) || /usr/bin/virsh list | egrep -v \'(^.*Id.*Name.*State$|^-*$|Domain-0|^$)\' > /var/cache/virsh_list.state') + return '' unless File.exists?('/var/cache/virsh_list.state') + File.read('/var/cache/virsh_list.state').split("\n").collect{|line| line.split[1] }.sort.join(',') + end +end + diff --git a/lib/facter/virtual_guests_count.rb b/lib/facter/virtual_guests_count.rb new file mode 100644 index 0000000..3728992 --- /dev/null +++ b/lib/facter/virtual_guests_count.rb @@ -0,0 +1,10 @@ +Facter.add('virtual_guests_count') do + confine :virtual => [ :xen0 ] + setcode do + # cache the list for other facts + system('((/usr/bin/find /var/cache/virsh_list.state -mmin -5 2>&1 | /bin/grep -qE \'^\/var\/cache\/virsh_list\.state$\') && [ `/bin/cat /var/cache/virsh_list.state | /usr/bin/wc -l` -gt 1 ]) || /usr/bin/virsh list | egrep -v \'(^.*Id.*Name.*State$|^-*$|Domain-0|^$)\' > /var/cache/virsh_list.state') + return 0 unless File.exists?('/var/cache/virsh_list.state') + File.read('/var/cache/virsh_list.state').split("\n").length + end +end + diff --git a/lib/puppet/provider/virt/libvirt.rb b/lib/puppet/provider/virt/libvirt.rb index 90dcd1d..9b2f3d3 100644 --- a/lib/puppet/provider/virt/libvirt.rb +++ b/lib/puppet/provider/virt/libvirt.rb @@ -168,7 +168,7 @@ def interfaces=(value) # Setup the virt-install graphic configuration arguments def graphic - opt = resource[:graphics] + opt = resource[:graphic] case opt when :enable || nil then args = ["--vnc"] when :disable then args = ["--nographics"] diff --git a/lib/puppet/type/virt.rb b/lib/puppet/type/virt.rb index 567424e..a452350 100644 --- a/lib/puppet/type/virt.rb +++ b/lib/puppet/type/virt.rb @@ -50,6 +50,15 @@ module Puppet feature :storage_path, "Sets the path to storage VE files" + feature :buildable, "The provider can build a new guest from scratch", + :methods => [:build] + + feature :importable, "The provider can import and existing guest image", + :methods => [:import] + + feature :livemigratable, "The provider supports live migration", + :methods => [:migrate] + # A base class for numeric Virt parameters validation. class VirtNumericParam < Puppet::Property @@ -102,21 +111,20 @@ def munge_boolean(value) Creates config file, and makes sure the domain is not running. `absent`: Removes config file, and makes sure the domain is not running. - `purged`: - Purge all files related." - newvalue(:stopped) do + + newvalues(:stopped) do provider.stop end - - newvalue(:running) do + + newvalues(:running) do provider.start end - newvalue(:installed) do - provider.setpresent + newvalues(:installed) do + provider.setinstalled end - newvalue(:absent) do + newvalues(:absent) do provider.destroy end diff --git a/manifests/init.pp b/manifests/init.pp index 614fce0..a3ce9c3 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,37 +1,7 @@ class virt { - - include virt::params - package { $virt::params::packages: ensure => latest } - - File { - owner => 'root', - group => 'root', - mode => 0644, - subscribe => Package[$virt::params::packages], - } - - service { $virt::params::service: - ensure => running, - enable => true, - } - - service { $servicename: - ensure => 'running', - enable => 'true', + case $::virtual { + /^xen/: { include virt::xen } + #/^kvm/: { include virt::kvm } + /^openvzhn/: { include virt::openvz } } - - case $virtual { - - /^openvzhn/: { - - file { - "${virt::params::basedir}/vz.conf": - ensure => present, - source => 'puppet:///modules/virt/global/vz.conf', - notify => Service[$virt::params::servicename]; - [ $virt::params::confdir, $virt::params::vedir ]: ensure => directory; - } - - } - } } diff --git a/manifests/kvm.pp b/manifests/kvm.pp new file mode 100644 index 0000000..bfe8284 --- /dev/null +++ b/manifests/kvm.pp @@ -0,0 +1,4 @@ +class virt::kvm { + include ::virt::libvirt + include virt::kvm::base +} diff --git a/manifests/kvm/base.pp b/manifests/kvm/base.pp new file mode 100644 index 0000000..aad6c02 --- /dev/null +++ b/manifests/kvm/base.pp @@ -0,0 +1,5 @@ +class virt::kvm::base { + package{ [ 'kvm', 'qemu-kvm']: + ensure => present, + } +} diff --git a/manifests/libvirt.pp b/manifests/libvirt.pp new file mode 100644 index 0000000..8e75ac5 --- /dev/null +++ b/manifests/libvirt.pp @@ -0,0 +1,7 @@ +class virt::libvirt { + case $::operatingsystem { + debian: { include virt::libvirt::debian } + ubuntu: { include virt::libvirt::ubuntu } + default: { include virt::libvirt::base } + } +} diff --git a/manifests/libvirt/base.pp b/manifests/libvirt/base.pp new file mode 100644 index 0000000..9a37ca9 --- /dev/null +++ b/manifests/libvirt/base.pp @@ -0,0 +1,22 @@ +class virt::libvirt::base { + package{ [ 'libvirt', 'python-virtinst', 'ruby-libvirt' ]: + ensure => installed, + } + + service{'libvirtd': + ensure => running, + enable => true, + hasstatus => true, + require => Package['libvirt'], + } + + file{ + '/usr/local/sbin/guest_starter': + source => 'puppet:///modules/virt/libvirt/guest_starter', + require => Package['libvirt'], + owner => root, group => 0, mode => 0700; + '/usr/local/sbin/generate_random_macaddress': + source => 'puppet:///modules/virt/libvirt/random_mac_address.rb', + owner => root, group => 0, mode => 0755; + } +} diff --git a/manifests/libvirt/debian.pp b/manifests/libvirt/debian.pp new file mode 100644 index 0000000..7d3920a --- /dev/null +++ b/manifests/libvirt/debian.pp @@ -0,0 +1,18 @@ +class virt::libvirt::debian inherits virt::libvirt::base { + Package['python-virtinst']{ + name => 'virtinst', + } + Package['libvirt']{ + name => 'libvirt0', + } + Package['ruby-libvirt']{ + name => 'libvirt-ruby', + } + package{'libvirt-bin': + ensure => present, + } + Service['libvirtd']{ + name => 'libvirt-bin', + require +> Package['libvirt-bin'], + } +} diff --git a/manifests/libvirt/ubuntu.pp b/manifests/libvirt/ubuntu.pp new file mode 100644 index 0000000..78a6beb --- /dev/null +++ b/manifests/libvirt/ubuntu.pp @@ -0,0 +1,8 @@ +class virt::libvirt::ubuntu inherits virt::libvirt::debian { + Package['python-virtinst']{ + name => 'python-vm-builder', + } + package{'ubuntu-virt-server': + ensure => present, + } +} diff --git a/manifests/openvz.pp b/manifests/openvz.pp new file mode 100644 index 0000000..dd033cb --- /dev/null +++ b/manifests/openvz.pp @@ -0,0 +1,5 @@ +class virt::openvz { + case $::virtual { + openvzhn: { include virt::openvz::hn } + } +} diff --git a/manifests/openvz/hn.pp b/manifests/openvz/hn.pp new file mode 100644 index 0000000..71e499d --- /dev/null +++ b/manifests/openvz/hn.pp @@ -0,0 +1,8 @@ +class virt::openvz::hn { + include ::virt::libvirt + case $::operatingsystem { + ubuntu: { include virt::openvz::hn::ubuntu } + debian: { include virt::openvz::hn::debian } + fedora: { include virt::openvz::hn::fedora } + } +} diff --git a/manifests/openvz/hn/base.pp b/manifests/openvz/hn/base.pp new file mode 100644 index 0000000..4ca889f --- /dev/null +++ b/manifests/openvz/hn/base.pp @@ -0,0 +1,6 @@ +class virt::openvz::hn::base { + package{ + [ 'vzctl', 'vzquota', 'ovzkernel']: + ensure => present, + } +} diff --git a/manifests/openvz/hn/debian.pp b/manifests/openvz/hn/debian.pp new file mode 100644 index 0000000..1d90649 --- /dev/null +++ b/manifests/openvz/hn/debian.pp @@ -0,0 +1,8 @@ +class virt::openvz::hn::debian inherits virt::openvz::hn::base { + Package['openvz-kernel']{ + name => "linux-image-openvz-${::architecture}", + } + package{'vzdump': + ensure => present; + } +} diff --git a/manifests/openvz/hn/fedora.pp b/manifests/openvz/hn/fedora.pp new file mode 100644 index 0000000..eff192f --- /dev/null +++ b/manifests/openvz/hn/fedora.pp @@ -0,0 +1 @@ +class virt::openvz::hn::fedora inherits virt::openvz::hn::base { } diff --git a/manifests/openvz/hn/ubuntu.pp b/manifests/openvz/hn/ubuntu.pp new file mode 100644 index 0000000..3f9218d --- /dev/null +++ b/manifests/openvz/hn/ubuntu.pp @@ -0,0 +1,5 @@ +class virt::openvz::hn::ubuntu inherits virt::openvz::hn::base { + Package['opnvzkernel']{ + name => 'linux-openvz', + } +} diff --git a/manifests/xen.pp b/manifests/xen.pp new file mode 100644 index 0000000..ecb3b3e --- /dev/null +++ b/manifests/xen.pp @@ -0,0 +1,7 @@ +class virt::xen { + case $::virtual { + 'xen0': { include virt::xen::xen0 } + 'xenu': { include virt::xen::xenu } + default: { fail("No such xen mode known") } + } +} diff --git a/manifests/xen/xen0.pp b/manifests/xen/xen0.pp new file mode 100644 index 0000000..c1c8f05 --- /dev/null +++ b/manifests/xen/xen0.pp @@ -0,0 +1,8 @@ +class virt::xen::xen0 { + include ::virt::libvirt + case $::operatingsystem { + debian: { include virt::xen::xen0::debian } + centos: { include virt::xen::xen0::centos } + default: { include virt::xen::xen0::base } + } +} diff --git a/manifests/xen/xen0/base.pp b/manifests/xen/xen0/base.pp new file mode 100644 index 0000000..a029990 --- /dev/null +++ b/manifests/xen/xen0/base.pp @@ -0,0 +1,44 @@ +class virt::xen::xen0::base { + package{ ['xen', 'xen-libs', 'kernel-xen']: + ensure => present, + } + + service{'xend': + ensure => running, + enable => true, + hasstatus => true, + require => Package['kernel-xen'], + } + + file{'xendomains_defaults': + owner => root, group => 0, mode => 0644; + } + + service{'xendomains': + enable => true, + hasstatus => true, + require => Package['kernel-xen'], + } + # only ensure xendomains running if we have more + # than one domain running + if $::virtual_guests_count and $::virtual_guests_count > 0 { + Service['xendomains']{ + ensure => running, + } + File['xendomains_defaults']{ + notify => Service[xendomains] + } + } + + file{'/etc/xen/xend-config.sxp': + source => [ "puppet:///modules/site_virt/xen/${::fqdn}/config/xend-config.sxp", + "puppet:///modules/site_virt/xen/config/${::domain}/xend-config.sxp", + "puppet:///modules/site_virt/xen/config/${::operatingsystem}.${::lsbdistcodename}/xend-config.sxp", + "puppet:///modules/site_virt/xen/config/${::operatingsystem}/xend-config.sxp", + "puppet:///modules/site_virt/xen/config/xend-config.sxp", + "puppet:///modules/virt/xen/config/${::operatingsystem}/xend-config.sxp", + "puppet:///modules/virt/xen/config/xend-config.sxp" ], + notify => Service['xend'], + owner => root, group => 0, mode => 0644; + } +} diff --git a/manifests/xen/xen0/centos.pp b/manifests/xen/xen0/centos.pp new file mode 100644 index 0000000..24f1607 --- /dev/null +++ b/manifests/xen/xen0/centos.pp @@ -0,0 +1,13 @@ +class virt::xen::xen0::centos inherits virt::xen::xen0::base { + file{'xend_defaults': + path => '/etc/sysconfig/xend', + source => "puppet:///modules/virt/xen/${::operatingsystem}/sysconfig/xend", + notify => Service['xend'], + owner => root, group => 0, mode => 0644; + } + + File['xendomains_defaults']{ + path => '/etc/sysconfig/xendomains', + source => "puppet:///modules/virt/xen/${::operatingsystem}/sysconfig/xendomains", + } +} diff --git a/manifests/xen/xen0/debian.pp b/manifests/xen/xen0/debian.pp new file mode 100644 index 0000000..331735a --- /dev/null +++ b/manifests/xen/xen0/debian.pp @@ -0,0 +1,43 @@ +class virt::xen::xen0::debian inherits virt::xen::xen0::base { + # This package is i386 only + # See also http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=379444 + case $::architecture { + 'i386': { + package { 'libc6-xen': ensure => present } + } + } + Package['kernel-xen']{ + name => $::architecture ? { + x86_64 => "linux-image-xen-amd64", + default => "linux-image-xen-${::architecture}", + } + } + + Package['xen']{ + name => 'xen-utils-common', + } + + Package['xen-libs']{ + name => $::lsbdistcodename ? { + lenny => 'xen-utils-3.2-1', + default => 'xen-utils-4.0' + } + } + + Service['xend']{ + hasstatus => false, + } + + File['xendomains_defaults']{ + path => '/etc/default/xendomains', + source => "puppet:///modules/virt/xen/${::operatingsystem}/default/xendomains", + } + + file { + "/etc/ld.so.conf.d/nosegneg.conf": + ensure => $xen_ensure, + content => "hwcap 0 nosegneg\n", + owner => root, group => 0, mode => 0644; + } +} + diff --git a/manifests/xen/xen0/ubuntu.pp b/manifests/xen/xen0/ubuntu.pp new file mode 100644 index 0000000..e2cb35d --- /dev/null +++ b/manifests/xen/xen0/ubuntu.pp @@ -0,0 +1,5 @@ +class virt::xen::xen0::ubuntu inherits virt::xen::xen0::debian { + package{'ubuntu-xen-server': + ensure => present, + } +} diff --git a/manifests/xen/xenu.pp b/manifests/xen/xenu.pp new file mode 100644 index 0000000..1153dcf --- /dev/null +++ b/manifests/xen/xenu.pp @@ -0,0 +1,5 @@ +class virt::xen::xenu { + case $::operatingsystem { + centos: { include virt::xen::xenu::centos } + } +} diff --git a/manifests/xen/xenu/centos.pp b/manifests/xen/xenu/centos.pp new file mode 100644 index 0000000..88c125b --- /dev/null +++ b/manifests/xen/xenu/centos.pp @@ -0,0 +1,11 @@ +class virt::xen::xenu::centos { + # Connect console to xvc0 + file_line{ + 'xvc0_inittab': + path => '/etc/inittab', + line => 'co:2345:respawn:/sbin/agetty xvc0 9600 vt100-nav'; + 'securetty': + path => '/etc/securetty', + line => 'xvc0'; + } +}