summaryrefslogtreecommitdiffstats
path: root/src/os-plugins/plugins/vmgrid/OpenSLX/OSPlugin/vmgrid.pm
blob: 0965b48258581284deff27bcf992604f60de0961 (plain) (blame)
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# Copyright (c) 2010 - RZ Uni Freiburg
# Copyright (c) 2010 - 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{^(virtualbox|qemukvm|xen)$},
            #openvz|vserver
            content_descr => '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 /w relative 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 /w relative 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::vt' => {
            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
                 (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
                 (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 do not 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::maxmem' => {
            applies_to_systems => 1,
            applies_to_clients => 1,
            description => unshiftHereDoc(<<'            End-of-Here'),
                 maximum RAM used by one vm
                 (only if supported by plugin)
            End-of-Here
            content_regex => qr{^(\d\d\d\d??\d??)$},
            content_descr => 'absolute amount: \d\d\d\d??\d??',
            default => undef,
        },
        'vmgrid::minmem' => {
           applies_to_systems => 1,
           applies_to_clients => 1,
            description => unshiftHereDoc(<<'            End-of-Here'),
                 minimum RAM used by one vm
                 (only if supported by plugin)
            End-of-Here
            content_regex => qr{^(\d\d\d\d??\d??)$},
            content_descr => 'absolute amount: \d\d\d\d??\d??',
            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");
    $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;