diff options
author | Michael Janczyk | 2010-04-06 20:03:28 +0200 |
---|---|---|
committer | Michael Janczyk | 2010-04-06 20:03:28 +0200 |
commit | 4661a054dca2bf0844c8bd283829b68328c7fed3 (patch) | |
tree | c9fb9c71fd5033f5b666b1deee432ea5d5f36126 /os-plugins/plugins/vmgrid/OpenSLX/OSPlugin/vmgrid.pm | |
parent | cumulative commit of local branch, many changes regarding virtualization (diff) | |
download | core-4661a054dca2bf0844c8bd283829b68328c7fed3.tar.gz core-4661a054dca2bf0844c8bd283829b68328c7fed3.tar.xz core-4661a054dca2bf0844c8bd283829b68328c7fed3.zip |
cumulative commit of local branch, xen modifications and vmgrid plugin
Diffstat (limited to 'os-plugins/plugins/vmgrid/OpenSLX/OSPlugin/vmgrid.pm')
-rw-r--r-- | os-plugins/plugins/vmgrid/OpenSLX/OSPlugin/vmgrid.pm | 322 |
1 files changed, 322 insertions, 0 deletions
diff --git a/os-plugins/plugins/vmgrid/OpenSLX/OSPlugin/vmgrid.pm b/os-plugins/plugins/vmgrid/OpenSLX/OSPlugin/vmgrid.pm new file mode 100644 index 00000000..d73e0720 --- /dev/null +++ b/os-plugins/plugins/vmgrid/OpenSLX/OSPlugin/vmgrid.pm @@ -0,0 +1,322 @@ +# Copyright (c) 2008, 2009 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# vmgrid.pm +# - ... +# ----------------------------------------------------------------------------- +package OpenSLX::OSPlugin::vmgrid; + +use strict; +use warnings; + +use base qw(OpenSLX::OSPlugin::Base); + +use OpenSLX::Basics; +use OpenSLX::Utils; +use OpenSLX::DistroUtils; + +sub new +{ + my $class = shift; + + my $self = { + name => 'vmgrid', + }; + + return bless $self, $class; +} + +# TODO: desc +sub getInfo +{ + my $self = shift; + + return { + description => unshiftHereDoc(<<' End-of-Here'), + ... + End-of-Here + precedence => 80, + #required => [ qr{^(vmware|virtualbox|qemukvm|xen)$} ], + #openvz|vserver + # TODO: virtaul plugin (requires, provides?) + #required => [ qw( virtualization ) ], + #provided => [ qw( virtualization ) ], + }; +} + +sub getAttrInfo +{ + my $self = shift; + + return { + 'vmgrid::active' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + should the 'vmgrid'-plugin be executed during boot? + End-of-Here + content_regex => qr{^(0|1)$}, + content_descr => '1 means active - 0 means inactive', + default => '1', + }, + 'vmgrid::virt' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + which virtualization technique schould be used? + End-of-Here + content_regex => qr{^(vmware|virtualbox|qemukvm|xen)$}, + #openvz|vserver + content_descr => 'vmware, virtualbox, qemukvm, xen', + #openvz, vserver + default => undef, + }, + 'vmgrid::roshare' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + do you want to mount external resources? + e.g. NFS share /w virt images ... + will be mounted to /var/lib/virt/vmgrid + End-of-Here + content_regex => qr{^nfs://}, + content_descr => 'NFS share as URI (nfs://...)', + default => undef, + }, + 'vmgrid::rwshare' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + do you want a persistent storage device? + use local hard drive (ID45) or NFS share. + will be mounted to /var/opt/openslx/plugins/vmgrid/share + End-of-Here + content_regex => qr{^(id45|nfs://)}, + content_descr => 'NFS share as URI (nfs://...) or "id45"', + default => undef, + }, + 'vmgrid::imgpath' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + location of virtual images + for starts /wo full path + End-of-Here + content_descr => 'absolute path to vm image files', + default => '/var/lib/virt/vmgrid/images', + }, + 'vmgrid::xmlpath' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + location of XML configuration for virtual images + for starts /wo full path + End-of-Here + content_descr => 'absolute path to vm xml files', + default => '/var/lib/virt/vmgrid/xml', + }, + 'vmgrid::startvms' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + which virtaul machines should be started per default + comma separated list. first will be started first, + second second, and so on, max. 4 VMs + End-of-Here + content_descr => 'name of xml file e.g. scilin-5.4-wn(.xml)', + default => undef, + }, + 'vmgrid::hvm' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + use hardware virtualization, if applicable + override the settings of the corresponding virt plugin + (only if supported by plugin) + End-of-Here + content_regex => qr{^(0|1)$}, + content_descr => '"0", "1" or "-" (for unset)', + default => undef, + }, + 'vmgrid::maxvcpus' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + use this number of vcpus as maximum for one vm + will be used only if applicable + (only if supported by plugin) + End-of-Here + content_regex => qr{^(1|2|4|8|16)$}, + content_descr => '1, 2, 4, 8, 16', + default => undef, + }, + 'vmgrid::minvcpus' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + use this number of vcpus as minimum for one vm + will be used only if applicable + (only if supported by plugin) + End-of-Here + content_regex => qr{^(1|2|4|8|16)$}, + content_descr => '1, 2, 4, 8, 16', + default => undef, + }, + 'vmgrid::memratio' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + define memory ratio in nn% + order: grid client 1, 2, 3, 4, other VMs, host + if desktop virtualization defined the free memory will be + distributed between the remaining grid clients, + according to their ratio + if less than 4 VMs defined in startvms the memory is being + reserved for a later manual start + set to 0 if you don't intend to start them manually + (only if supported by plugin) + End-of-Here + content_regex => qr{^(\d\d??,\d\d??,\d\d??,\d\d??,\d\d??,\d\d??)$}, + content_descr => '\d\d??,\d\d??,\d\d??,\d\d??,\d\d??,\d\d??', + default => '40,0,0,0,40,20', + }, + 'vmgrid::maxram' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + maximum of RAM used for ALL vms + will be used only if applicable + (only if supported by plugin) + End-of-Here + content_regex => qr{^(1|2|3|4|5|6|7|8|9)}, + content_descr => 'absolute or relative e.g. 512 or 50%', + default => undef, + }, + 'vmgrid::minram' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + minimum of RAM used for ALL vms + will be used only if applicable + (only if supported by plugin) + End-of-Here + content_regex => qr{^(1|2|3|4|5|6|7|8|9)}, + content_descr => 'absolute or relative e.g. 512 or 50%', + default => undef, + }, + }; +} + +sub installationPhase +{ + my $self = shift; + my $info = shift; + + my $pluginRepoPath = $info->{'plugin-repo-path'}; + my $openslxBasePath = $info->{'openslx-base-path'}; + + $self->_writeRunlevelScript(); + + # copy all needed files now: + my $pluginName = $self->{'name'}; + my $pluginBasePath = "$openslxBasePath/lib/plugins/$pluginName/files"; + foreach my $file ( qw( vmgrid run-vmgrid.sh ) ) { + copyFile("$pluginBasePath/$file", "$pluginRepoPath/"); + chmod 0755, "$pluginRepoPath/$file"; + } + + return; +} + +sub removalPhase +{ + my $self = shift; + my $info = shift; + + return; +} + +# Write the runlevelscript +sub _writeRunlevelScript +{ + my $self = shift; + my $initfile = newInitFile(); + + $initfile->setName("vmgrid-slx"); + $initfile->setDesc("Setup environment for vmgrid. Part of OpenSLX vmgrid plugin."); + + # todo: Function need to be formated proper... not important right now + #$initfile->addFunction( + # 'running', + # 'lsmod | grep -q "$1[^_-]"' + #); + + # Is a VM running? + my $runningvms = unshiftHereDoc(<<' End-of-Here'); + if [ -e /tmp/vmgrid/vmgrid.pids ]; then + for pid in $(cat /tmp/vmgrid/vmgrid.pids); do + if ps aux | grep " ${pid} " | grep vmgrid; then + echo "Running: ${pid}" + fi + done + fi + End-of-Here + + # Kill all VMS! + my $killvms = unshiftHereDoc(<<' End-of-Here'); + if [ -e /tmp/vmgrid/vmgrid.pids ]; then + for pid in $(cat /tmp/vmgrid/vmgrid.pids); do + if ps aux | grep " ${pid} " | grep vmgrid; then + kill ${pid} + fi + done + fi + End-of-Here + + # FORCE: Kill all VMS! + my $fkillvms = unshiftHereDoc(<<' End-of-Here'); + if [ -e /tmp/vmgrid/vmgrid.pids ]; then + for pid in $(cat /tmp/vmgrid/vmgrid.pids); do + if ps aux | grep " ${pid} " | grep vmgrid; then + kill -9 ${pid} + fi + done + fi + End-of-Here + + $initfile->addFunction( + 'start', + ' vmgrid', + ); + $initfile->addToCase( + 'kill', + 'killvms' + ); + $initfile->addToCase( + 'force-kill', + 'fkillvms' + ); + $initfile->addToCase( + 'status', + 'runningvms' + ); + $initfile->addToCase( + 'restart', + 'stop && start' + ); + + # get distro version +# my $distro = (split('-',$self->{'os-plugin-engine'}->distroName()))[0]; +# my $runlevelscript = getInitFileForDistro($initfile, $distro); +# +# spitFile("$self->{'pluginRepositoryPath'}/vmgrid-slx", $runlevelscript); +} + +1; |