Ravada.pm 182 KB
Newer Older
1
2
3
4
5
package Ravada;

use warnings;
use strict;

Francesc Guasch's avatar
Francesc Guasch committed
6
our $VERSION = '1.4.0';
Francesc Guasch's avatar
Francesc Guasch committed
7

8
use Carp qw(carp croak cluck);
9
use Data::Dumper;
10
use DBIx::Connector;
11
use File::Copy;
Francesc Guasch's avatar
Francesc Guasch committed
12
13
use Hash::Util qw(lock_hash unlock_hash);
use IPC::Run3 qw(run3);
14
use Mojo::JSON qw( encode_json decode_json );
15
use Moose;
Francesc Guasch's avatar
Francesc Guasch committed
16
use POSIX qw(WNOHANG);
17
use Proc::PID::File;
Francesc Guasch's avatar
Francesc Guasch committed
18
use Time::HiRes qw(gettimeofday tv_interval);
19
use YAML;
20
use MIME::Base64;
21
use Socket qw( inet_aton inet_ntoa );
22
use Image::Magick::Q16;
23

Francesc Guasch's avatar
Francesc Guasch committed
24
25
26
no warnings "experimental::signatures";
use feature qw(signatures);

Francesc Guasch's avatar
Francesc Guasch committed
27
use Ravada::Auth;
Francesc Guasch's avatar
Francesc Guasch committed
28
use Ravada::Booking;
29
use Ravada::Request;
Francesc Guasch's avatar
Francesc Guasch committed
30
use Ravada::Repository::ISO;
31
use Ravada::VM::Void;
32

Francesc Guasch's avatar
Francesc Guasch committed
33
our %VALID_VM;
Francesc Guasch's avatar
Francesc Guasch committed
34
our %ERROR_VM;
35
our $TIMEOUT_STALE_PROCESS;
36
our $TIMEOUT_REFRESH_REQUESTS = 0;
Francesc Guasch's avatar
Francesc Guasch committed
37
38
39
40
41
42
43

eval {
    require Ravada::VM::KVM and do {
        Ravada::VM::KVM->import;
    };
    $VALID_VM{KVM} = 1;
};
Francesc Guasch's avatar
Francesc Guasch committed
44
45
46
47
48
49
50
51
52
$ERROR_VM{KVM} = $@;

eval {
    require Ravada::VM::Void and do {
        Ravada::VM::Void->import;
    };
    $VALID_VM{Void} = 1;
};
$ERROR_VM{Void} = $@;
Francesc Guasch's avatar
Francesc Guasch committed
53

54
55
56
no warnings "experimental::signatures";
use feature qw(signatures);

Francesc Guasch's avatar
Francesc Guasch committed
57
58
59
our %VALID_CONFIG = (
    vm => undef
    ,warn_error => undef
Francesc Guasch's avatar
Francesc Guasch committed
60
    ,db => {user => undef, password => undef,  hostname => undef, host => undef, db => undef}
Francesc Guasch's avatar
Francesc Guasch committed
61
62
63
64
65
66
    ,ldap => { admin_user => { dn => undef, password => undef }
        ,filter => undef
        ,base => undef
        ,auth => undef
        ,admin_group => undef
        ,ravada_posix_group => undef
Francesc Guasch's avatar
Francesc Guasch committed
67
68
        ,groups_base => undef
        ,field => undef
69
70
        ,server => undef
        ,port => undef
Francesc Guasch's avatar
Francesc Guasch committed
71
        ,size_limit => undef
Francesc Guasch's avatar
Francesc Guasch committed
72
    }
Francesc Guasch's avatar
Francesc Guasch committed
73
    ,log => undef
Francesc Guasch's avatar
Francesc Guasch committed
74
75
);

Francesc Guasch's avatar
Francesc Guasch committed
76
77
=head1 NAME

78
Ravada - Remote Virtual Desktop Manager
Francesc Guasch's avatar
Francesc Guasch committed
79
80
81
82
83
84
85
86
87

=head1 SYNOPSIS

  use Ravada;

  my $ravada = Ravada->new()

=cut

88
89

our $FILE_CONFIG = "/etc/ravada.conf";
90
$FILE_CONFIG = undef if ! -e $FILE_CONFIG;
91
92
93
94
95

###########################################################################

our $CONNECTOR;
our $CONFIG = {};
96
our $FORCE_DEBUG = 0;
97
our $DEBUG;
Francesc Guasch's avatar
Francesc Guasch committed
98
our $VERBOSE;
99
our $CAN_FORK = 1;
100
our $CAN_LXC = 0;
101
102

# Seconds to wait for other long process
103
our $SECONDS_WAIT_CHILDREN = 5;
104

105
106
our $DIR_SQL = "sql/mysql";
$DIR_SQL = "/usr/share/doc/ravada/sql/mysql" if ! -e $DIR_SQL;
107

108
109
110
our $USER_DAEMON;
our $USER_DAEMON_NAME = 'daemon';

111
112
113
our $FIRST_TIME_RUN = 1;
$FIRST_TIME_RUN = 0 if $0 =~ /\.t$/;

114
has 'connector' => (
115
116
117
118
119
120
        is => 'rw'
);

has 'config' => (
    is => 'ro'
    ,isa => 'Str'
121
122
);

123
124
125
126
127
128
has 'warn_error' => (
    is => 'rw'
    ,isa => 'Bool'
    ,default => sub { 1 }
);

Francesc Guasch's avatar
Francesc Guasch committed
129
130
131
132
133
134
135
=head2 BUILD

Internal constructor

=cut


136
137
sub BUILD {
    my $self = shift;
138
    if ($self->config()) {
139
        _init_config($self->config);
140
    } else {
141
        _init_config($FILE_CONFIG) if $FILE_CONFIG && -e $FILE_CONFIG;
142
    }
143

Francesc Guasch's avatar
Francesc Guasch committed
144
    if ( $self->connector ) {
joansp's avatar
joansp committed
145
        $CONNECTOR = $self->connector
Francesc Guasch's avatar
Francesc Guasch committed
146
147
    } else {
        $CONNECTOR = $self->_connect_dbh();
148
        $self->connector($CONNECTOR);
Francesc Guasch's avatar
Francesc Guasch committed
149
    }
Francesc Guasch's avatar
Francesc Guasch committed
150
    Ravada::Auth::init($CONFIG);
151

152
153
}

154
155
156
157
158
159
160
sub _set_first_time_run($self) {
    my $sth = $CONNECTOR->dbh->table_info('%',undef,'domains','TABLE');
    my $info = $sth->fetchrow_hashref();
    $sth->finish;
    if  ( keys %$info ) {
        $FIRST_TIME_RUN = 0;
    } else {
161
        print "Installing " if $0 !~ /\.t$/;
162
163
164
    }
}

165
sub _install($self) {
166
    my $pid = Proc::PID::File->new(name => "ravada_install");
167
    $pid->file({dir => "/run/user/$>"}) if $>;
168
169
170
171
172
173
174
    if ( $pid->alive ) {
        print "Waiting for install process to finish" if $ENV{TERM};
        while ( $pid->alive ) {
            sleep 1;
            print "." if $ENV{TERM};
        }
        print "\n" if $ENV{TERM};
175
        return;
176
177
    }
    $pid->touch;
178
179
    $self->_set_first_time_run();

180
    $self->_create_tables();
181
    $self->_sql_create_tables();
182
    $self->_upgrade_tables();
183
    $self->_upgrade_timestamps();
184
    $self->_update_data();
185
    $self->_init_user_daemon();
186
    $self->_sql_insert_defaults();
187
188
189

    $self->_do_create_constraints();

190
    $pid->release();
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

    print "\n" if $FIRST_TIME_RUN;

}

sub _do_create_constraints($self) {
    return if !$self->{_constraints};

    if ($CAN_FORK) {

        my $pid = fork();
        die "Error: I cannot fork" if !defined $pid;
        if ($pid) {
            $self->_add_pid($pid);
            return;
        }
    }

    my $pid_file = Proc::PID::File->new(name => "ravada_constraint");
    $pid_file->file({dir => "/run/user/$>"}) if $>;
    if ( $pid_file->alive ) {
        exit if $CAN_FORK;
        return;
    }
    $pid_file->touch;
    my $dbh = $CONNECTOR->dbh;
Francesc Guasch's avatar
Francesc Guasch committed
217
218
219

    my $known_constraints;

220
    for my $constraint (@{$self->{_constraints}}) {
Francesc Guasch's avatar
Francesc Guasch committed
221
222
223
224
225
226
227
228
229
230
        my ($table,$name) = $constraint =~ /ALTER TABLE (.*?) .*?CONSTRAINT (\w+)\s/i;
        if ( !defined $table ) {
            cluck "Warning: I can't find the table in this constraint: $constraint";
            next;
        }
        if (!exists $known_constraints->{$table}) {
            my $current = $self->_get_constraints($table);
            $known_constraints->{$table} = $current;
        }
        next if exists $known_constraints->{$table}->{$name};
231
232

        warn "INFO: creating constraint $name \n"
233
        if $name && !$FIRST_TIME_RUN && $0 !~ /\.t$/;
234
235
236
237
238
239
240
241
        print "+" if $FIRST_TIME_RUN && !$CAN_FORK;

        $self->_clean_db_leftovers();

        my $sth = $dbh->do($constraint);
    }
    $pid_file->release;
    exit if $CAN_FORK;
242
243
}

244
245
246
247
248
249
sub _init_user_daemon {
    my $self = shift;
    return if $USER_DAEMON;

    $USER_DAEMON = Ravada::Auth::SQL->new(name => $USER_DAEMON_NAME);
    if (!$USER_DAEMON->id) {
Francesc Guasch's avatar
Francesc Guasch committed
250
251
252
253
254
255
256
257
        for (1 .. 120 ) {
            my @list = $self->_list_pids();
            last if !@list;
            sleep 1 if @list;
            $self->_wait_pids();
        }
        $USER_DAEMON = Ravada::Auth::SQL->new(name => $USER_DAEMON_NAME);
        return if $USER_DAEMON->id;
258
259
260
261
262
263
264
265
        $USER_DAEMON = Ravada::Auth::SQL::add_user(
            name => $USER_DAEMON_NAME,
            is_admin => 1
        );
        $USER_DAEMON = Ravada::Auth::SQL->new(name => $USER_DAEMON_NAME);
    }

}
266
267
sub _update_user_grants {
    my $self = shift;
Francesc Guasch's avatar
Francesc Guasch committed
268
    $self->_init_user_daemon();
269
    my $sth = $CONNECTOR->dbh->prepare("SELECT id FROM users WHERE is_temporary=0");
270
271
    my $id;
    $sth->execute;
Francesc Guasch's avatar
Francesc Guasch committed
272
    $sth->bind_columns(\$id);
273
    while ($sth->fetch) {
274
        my $user = Ravada::Auth::SQL->search_by_id($id) or confess "Unknown user id = $id";
Francesc Guasch's avatar
Francesc Guasch committed
275
276
        next if $user->name() eq $USER_DAEMON_NAME;

277
278
279
280
281
282
283
        my %grants = $user->grants();

        for my $key (keys %grants) {
            delete $grants{$key} if !defined $grants{$key};
        }
        next if keys %grants;

284
285
        $USER_DAEMON->grant_user_permissions($user);
        $USER_DAEMON->grant_admin_permissions($user)    if $user->is_admin;
286
287
288
289
    }
    $sth->finish;
}

290
291
292
293
294
sub _update_isos {
    my $self = shift;
    my $table = 'iso_images';
    my $field = 'name';
    my %data = (
295
296
297
	    androidx86 => {
                    name => 'Android 8.1 x86'
            ,description => 'Android-x86 64 bits. Requires an user provided ISO image.'
Francesc Guasch's avatar
Francesc Guasch committed
298
                   ,arch => 'x86_64'
299
300
301
302
                    ,xml => 'android-amd64.xml'
             ,xml_volume => 'android-volume.xml'
	     ,min_disk_size => '4'
        },
Francesc Guasch's avatar
Francesc Guasch committed
303
304
305
        arch_1909 => {
                    name => 'Arch Linux 19.09'
            ,description => 'Arch Linux 19.09.01 64 bits'
Francesc Guasch's avatar
Francesc Guasch committed
306
                   ,arch => 'x86_64'
Francesc Guasch's avatar
Francesc Guasch committed
307
308
                    ,xml => 'bionic-amd64.xml'
             ,xml_volume => 'bionic64-volume.xml'
309
310
311
312
313
314
315
316
                    ,url => 'https://archive.archlinux.org/iso/2019.09.01/'
                    ,file_re => 'archlinux-2019.09.01-x86_64.iso'
                    ,md5_url => ''
                    ,md5 => '1d6bdf5cbc6ca98c31f02d23e418dd96'
        },
	mate_focal_fossa => {
                    name => 'Ubuntu Mate Focal Fossa 64 bits'
            ,description => 'Ubuntu Mate 20.04 (Focal Fossa) 64 bits'
Francesc Guasch's avatar
Francesc Guasch committed
317
                   ,arch => 'x86_64'
318
319
                    ,xml => 'focal_fossa-amd64.xml'
             ,xml_volume => 'focal_fossa64-volume.xml'
320
321
                    ,url => 'http://cdimage.ubuntu.com/ubuntu-mate/releases/20.04.*/release/ubuntu-mate-20.04.*-desktop-amd64.iso'
                ,sha256_url => '$url/SHA256SUMS'
Francesc Guasch's avatar
Francesc Guasch committed
322
            ,options => { machine => 'pc-q35', bios => 'UEFI' }
Francesc Guasch's avatar
Francesc Guasch committed
323
                ,min_ram => 1
Francesc Guasch's avatar
Francesc Guasch committed
324
        },
Joel Alarcón's avatar
Joel Alarcón committed
325
326
327
        mate_bionic => {
                    name => 'Ubuntu Mate Bionic 64 bits'
            ,description => 'Ubuntu Mate 18.04 (Bionic Beaver) 64 bits'
Francesc Guasch's avatar
Francesc Guasch committed
328
                   ,arch => 'x86_64'
Joel Alarcón's avatar
Joel Alarcón committed
329
330
331
                    ,xml => 'bionic-amd64.xml'
             ,xml_volume => 'bionic64-volume.xml'
                    ,url => 'http://cdimage.ubuntu.com/ubuntu-mate/releases/18.04.*/release/ubuntu-mate-18.04.*-desktop-amd64.iso'
Paula Paez's avatar
Paula Paez committed
332
                ,sha256_url => '$url/SHA256SUMS'
Francesc Guasch's avatar
Francesc Guasch committed
333
                ,min_ram => 1
Joel Alarcón's avatar
Joel Alarcón committed
334
335
336
337
        },
        mate_bionic_i386 => {
                    name => 'Ubuntu Mate Bionic 32 bits'
            ,description => 'Ubuntu Mate 18.04 (Bionic Beaver) 32 bits'
Francesc Guasch's avatar
Francesc Guasch committed
338
                   ,arch => 'i686'
Joel Alarcón's avatar
Joel Alarcón committed
339
340
341
                    ,xml => 'bionic-i386.xml'
             ,xml_volume => 'bionic32-volume.xml'
                    ,url => 'http://cdimage.ubuntu.com/ubuntu-mate/releases/18.04.*/release/ubuntu-mate-18.04.*-desktop-i386.iso'
342
                ,sha256_url => '$url/SHA256SUMS'
Francesc Guasch's avatar
Francesc Guasch committed
343
                ,min_ram => 1
Joel Alarcón's avatar
Joel Alarcón committed
344
        },
frankiejol's avatar
frankiejol committed
345
346
347
        ubuntu_xenial => {
                    name => 'Ubuntu Xenial Xerus 64 bits'
            ,description => 'Ubuntu 16.04 LTS Xenial Xerus 64 bits'
Francesc Guasch's avatar
Francesc Guasch committed
348
                   ,arch => 'x86_64'
frankiejol's avatar
frankiejol committed
349
350
351
352
353
354
355
                    ,xml => 'xenial64-amd64.xml'
             ,xml_volume => 'xenial64-volume.xml'
                    ,url => 'http://releases.ubuntu.com/16.04/ubuntu-16.04.*-desktop-amd64.iso'
                ,sha256_url => '$url/SHA256SUMS'
                ,min_disk_size => '10'
        },

fv3rdugo's avatar
fv3rdugo committed
356
        mate_xenial => {
Fernando Verdugo's avatar
Fernando Verdugo committed
357
                    name => 'Ubuntu Mate Xenial'
fv3rdugo's avatar
fv3rdugo committed
358
            ,description => 'Ubuntu Mate 16.04.3 (Xenial) 64 bits'
Francesc Guasch's avatar
Francesc Guasch committed
359
                   ,arch => 'x86_64'
fv3rdugo's avatar
fv3rdugo committed
360
361
362
                    ,xml => 'yakkety64-amd64.xml'
             ,xml_volume => 'yakkety64-volume.xml'
                    ,url => 'http://cdimage.ubuntu.com/ubuntu-mate/releases/16.04.*/release/ubuntu-mate-16.04.*-desktop-amd64.iso'
363
                ,sha256_url => '$url/SHA256SUMS'
364
                ,min_disk_size => '10'
fv3rdugo's avatar
fv3rdugo committed
365
        },
366
367
368
	,focal_fossa=> {
                    name => 'Ubuntu Focal Fossa'
            ,description => 'Ubuntu 20.04 Focal Fossa 64 bits'
Francesc Guasch's avatar
Francesc Guasch committed
369
                   ,arch => 'x86_64'
370
371
                    ,xml => 'focal_fossa-amd64.xml'
             ,xml_volume => 'focal_fossa64-volume.xml'
372
                    ,url => 'http://releases.ubuntu.com/20.04/'
373
                ,file_re => '^ubuntu-20.04.*-desktop-amd64.iso'
Francesc Guasch's avatar
Francesc Guasch committed
374
                ,sha256_url => '$url/SHA256SUMS'
375
          ,min_disk_size => '9'
Francesc Guasch's avatar
Francesc Guasch committed
376
          ,min_ram => 1
Francesc Guasch's avatar
Francesc Guasch committed
377
378
            ,options => { machine => 'pc-q35', bios => 'UEFI' }
                   ,arch => 'x86_64'
379
380
        }

Joel Alarcón's avatar
Joel Alarcón committed
381
382
383
        ,bionic=> {
                    name => 'Ubuntu Bionic Beaver'
            ,description => 'Ubuntu 18.04 Bionic Beaver 64 bits'
Francesc Guasch's avatar
Francesc Guasch committed
384
                   ,arch => 'x86_64'
Joel Alarcón's avatar
Joel Alarcón committed
385
386
387
                    ,xml => 'bionic-amd64.xml'
             ,xml_volume => 'bionic64-volume.xml'
                    ,url => 'http://releases.ubuntu.com/18.04/'
388
                ,file_re => '^ubuntu-18.04.*desktop-amd64.iso'
389
                ,sha256_url => '$url/SHA256SUMS'
Joel Alarcón's avatar
Joel Alarcón committed
390
          ,min_disk_size => '9'
Francesc Guasch's avatar
Francesc Guasch committed
391
                ,min_ram => 1
Francesc Guasch's avatar
Francesc Guasch committed
392
            ,arch => 'x86_64'
Joel Alarcón's avatar
Joel Alarcón committed
393
394
        }

Francesc Guasch's avatar
Francesc Guasch committed
395
396
397
        ,serena64 => {
            name => 'Mint 18.1 Mate 64 bits'
    ,description => 'Mint Serena 18.1 with Mate Desktop based on Ubuntu Xenial 64 bits'
Francesc Guasch's avatar
Francesc Guasch committed
398
           ,arch => 'x86_64'
Francesc Guasch's avatar
Francesc Guasch committed
399
400
            ,xml => 'xenial64-amd64.xml'
     ,xml_volume => 'xenial64-volume.xml'
Francesc Guasch's avatar
Francesc Guasch committed
401
402
            ,url => 'https://mirrors.edge.kernel.org/linuxmint/stable/18.3'
        ,file_re => 'linuxmint-18.3-mate-64bit.iso'
Francesc Guasch's avatar
Francesc Guasch committed
403
404
        ,md5_url => ''
            ,md5 => 'c5cf5c5d568e2dfeaf705cfa82996d93'
405
            ,min_disk_size => '10'
Francesc Guasch's avatar
Francesc Guasch committed
406
407

        }
408
409
410
        ,mint20_64 => {
            name => 'Mint 20 Mate 64 bits'
    ,description => 'Mint Ulyana 20 with Mate Desktop 64 bits'
Francesc Guasch's avatar
Francesc Guasch committed
411
           ,arch => 'x86_64'
Joel Alarcón's avatar
Joel Alarcón committed
412
413
            ,xml => 'xenial64-amd64.xml'
     ,xml_volume => 'xenial64-volume.xml'
Francesc Guasch's avatar
Francesc Guasch committed
414
415
            ,url => 'https://mirrors.edge.kernel.org/linuxmint/stable/20.2'
        ,file_re => 'linuxmint-20.2-mate-64bit.iso'
416
        ,sha256_url => '$url/sha256sum.txt'
Joel Alarcón's avatar
Joel Alarcón committed
417
418
419
420
421
            ,min_disk_size => '15'
        }
        ,alpine381_64 => {
            name => 'Alpine 3.8 64 bits'
    ,description => 'Alpine Linux 3.8 64 bits ( Minimal Linux Distribution )'
Francesc Guasch's avatar
Francesc Guasch committed
422
           ,arch => 'x86_64'
Joel Alarcón's avatar
Joel Alarcón committed
423
424
425
426
427
            ,xml => 'alpine-amd64.xml'
     ,xml_volume => 'alpine381_64-volume.xml'
            ,url => 'http://dl-cdn.alpinelinux.org/alpine/v3.8/releases/x86_64/'
        ,file_re => 'alpine-standard-3.8.1-x86_64.iso'
        ,sha256_url => 'http://dl-cdn.alpinelinux.org/alpine/v3.8/releases/x86_64/alpine-standard-3.8.1-x86_64.iso.sha256'
Francesc Guasch's avatar
Francesc Guasch committed
428
429
            ,min_disk_size => '2'
            ,options => { machine => 'pc-q35', bios => 'UEFI' }
Joel Alarcón's avatar
Joel Alarcón committed
430
431
432
433
        }
        ,alpine381_32 => {
            name => 'Alpine 3.8 32 bits'
    ,description => 'Alpine Linux 3.8 32 bits ( Minimal Linux Distribution )'
Francesc Guasch's avatar
Francesc Guasch committed
434
           ,arch => 'i686'
Joel Alarcón's avatar
Joel Alarcón committed
435
436
437
            ,xml => 'alpine-i386.xml'
     ,xml_volume => 'alpine381_32-volume.xml'
            ,url => 'http://dl-cdn.alpinelinux.org/alpine/v3.8/releases/x86/'
Francesc Guasch's avatar
Francesc Guasch committed
438
            ,options => { machine => 'pc-i440fx' }
Joel Alarcón's avatar
Joel Alarcón committed
439
440
441
442
        ,file_re => 'alpine-standard-3.8.1-x86.iso'
        ,sha256_url => 'http://dl-cdn.alpinelinux.org/alpine/v3.8/releases/x86/alpine-standard-3.8.1-x86.iso.sha256'
            ,min_disk_size => '1'
        }
443
444
445
        ,fedora_28 => {
            name => 'Fedora 28'
            ,description => 'RedHat Fedora 28 Workstation 64 bits'
446
            ,url => 'https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/28/Workstation/x86_64/iso/Fedora-Workstation-netinst-x86_64-28-.*\.iso'
Francesc Guasch's avatar
Francesc Guasch committed
447
            ,arch => 'x86_64'
Francesc Guasch's avatar
Francesc Guasch committed
448
449
            ,xml => 'xenial64-amd64.xml'
            ,xml_volume => 'xenial64-volume.xml'
450
            ,sha256_url => '$url/Fedora-Workstation-28-.*-x86_64-CHECKSUM'
451
            ,min_disk_size => '10'
452
453
454
455
        }
	      ,kubuntu_64_focal_fossa => {
            name => 'Kubuntu Focal Fossa 64 bits'
            ,description => 'Kubuntu 20.04 Focal Fossa 64 bits'
Francesc Guasch's avatar
Francesc Guasch committed
456
            ,arch => 'x86_64'
457
458
            ,xml => 'focal_fossa-amd64.xml'
            ,xml_volume => 'focal_fossa64-volume.xml'
459
460
461
            ,sha256_url => '$url/SHA256SUMS'
            ,url => 'http://cdimage.ubuntu.com/kubuntu/releases/20.04.*/release/'
            ,file_re => 'kubuntu-20.04.*-desktop-amd64.iso'
462
            ,rename_file => 'kubuntu_focal_fossa_64.iso'
Francesc Guasch's avatar
Francesc Guasch committed
463
            ,options => { machine => 'pc-q35', bios => 'UEFI' }
Francesc Guasch's avatar
Francesc Guasch committed
464
                ,min_ram => 1
Francesc Guasch's avatar
Francesc Guasch committed
465
        }
Joel Alarcón's avatar
Joel Alarcón committed
466
467
468
        ,kubuntu_64 => {
            name => 'Kubuntu Bionic Beaver 64 bits'
            ,description => 'Kubuntu 18.04 Bionic Beaver 64 bits'
Francesc Guasch's avatar
Francesc Guasch committed
469
            ,arch => 'x86_64'
Joel Alarcón's avatar
Joel Alarcón committed
470
471
            ,xml => 'bionic-amd64.xml'
            ,xml_volume => 'bionic64-volume.xml'
Paula Paez's avatar
Paula Paez committed
472
            ,sha256_url => '$url/SHA256SUMS'
Joel Alarcón's avatar
Joel Alarcón committed
473
            ,url => 'http://cdimage.ubuntu.com/kubuntu/releases/18.04/release/'
474
            ,file_re => 'kubuntu-18.04.\d+-desktop-amd64.iso'
Joel Alarcón's avatar
Joel Alarcón committed
475
476
477
478
479
            ,rename_file => 'kubuntu_bionic_64.iso'
        }
        ,kubuntu_32 => {
            name => 'Kubuntu Bionic Beaver 32 bits'
            ,description => 'Kubuntu 18.04 Bionic Beaver 32 bits'
Francesc Guasch's avatar
Francesc Guasch committed
480
            ,arch => 'i686'
Joel Alarcón's avatar
Joel Alarcón committed
481
482
            ,xml => 'bionic-i386.xml'
            ,xml_volume => 'bionic32-volume.xml'
Paula Paez's avatar
Paula Paez committed
483
            ,sha256_url => '$url/SHA256SUMS'
Joel Alarcón's avatar
Joel Alarcón committed
484
            ,url => 'http://cdimage.ubuntu.com/kubuntu/releases/18.04/release/'
485
            ,file_re => 'kubuntu-18.04.\d+-desktop-i386.iso'
Joel Alarcón's avatar
Joel Alarcón committed
486
487
            ,rename_file => 'kubuntu_bionic_32.iso'
        }
488
489
490
        ,suse_15 => {
            name => "openSUSE Leap 15"
            ,description => "openSUSE Leap 15 64 bits"
Francesc Guasch's avatar
Francesc Guasch committed
491
            ,arch => 'x86_64'
492
493
494
            ,xml => 'bionic-amd64.xml'
            ,xml_volume => 'bionic64-volume.xml'
            ,url => 'https://download.opensuse.org/distribution/leap/15.0/iso/'
495
            ,sha256_url => '$url/openSUSE-Leap-15.\d+-NET-x86_64.iso.sha256'
496
497
498
            ,file_re => 'openSUSE-Leap-15.\d+-NET-x86_64.iso'

        }
Joel Alarcón's avatar
Joel Alarcón committed
499
500
501
        ,xubuntu_beaver_64 => {
            name => 'Xubuntu Bionic Beaver 64 bits'
            ,description => 'Xubuntu 18.04 Bionic Beaver 64 bits'
Francesc Guasch's avatar
Francesc Guasch committed
502
            ,arch => 'x86_64'
Joel Alarcón's avatar
Joel Alarcón committed
503
504
            ,xml => 'bionic-amd64.xml'
            ,xml_volume => 'bionic64-volume.xml'
505
            ,sha256_url => '$url/../SHA256SUMS'
Joel Alarcón's avatar
Joel Alarcón committed
506
507
508
509
510
511
512
            ,url => 'http://archive.ubuntu.com/ubuntu/dists/bionic/main/installer-amd64/current/images/netboot/'
            ,file_re => 'mini.iso'
            ,rename_file => 'xubuntu_bionic_64.iso'
        }
        ,xubuntu_beaver_32 => {
            name => 'Xubuntu Bionic Beaver 32 bits'
            ,description => 'Xubuntu 18.04 Bionic Beaver 32 bits'
Francesc Guasch's avatar
Francesc Guasch committed
513
            ,arch => 'i686'
Joel Alarcón's avatar
Joel Alarcón committed
514
515
516
517
518
519
520
            ,xml => 'bionic-i386.xml'
            ,xml_volume => 'bionic32-volume.xml'
            ,md5_url => '$url/../MD5SUMS'
            ,url => 'http://archive.ubuntu.com/ubuntu/dists/bionic/main/installer-i386/current/images/netboot/'
            ,file_re => 'mini.iso'
            ,rename_file => 'xubuntu_bionic_32.iso'
        }
Francesc Guasch's avatar
Francesc Guasch committed
521
522
        ,xubuntu_xenial => {
            name => 'Xubuntu Xenial Xerus'
523
            ,description => 'Xubuntu 16.04 Xenial Xerus 64 bits (LTS)'
Francesc Guasch's avatar
Francesc Guasch committed
524
525
526
527
            ,url => 'http://archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/current/images/netboot/mini.iso'
           ,xml => 'yakkety64-amd64.xml'
            ,xml_volume => 'yakkety64-volume.xml'
            ,md5 => 'fe495d34188a9568c8d166efc5898d22'
528
            ,rename_file => 'xubuntu_xenial_mini.iso'
529
            ,min_disk_size => '10'
Francesc Guasch's avatar
Francesc Guasch committed
530
        }
531
	,lubuntu_bionic_64 => {
Joel Alarcón's avatar
Joel Alarcón committed
532
533
534
             name => 'Lubuntu Bionic Beaver 64 bits'
             ,description => 'Lubuntu 18.04 Bionic Beaver 64 bits'
             ,url => 'http://cdimage.ubuntu.com/lubuntu/releases/18.04.*/release/lubuntu-18.04.*-desktop-amd64.iso'
535
             ,sha256_url => '$url/SHA256SUMS'
Joel Alarcón's avatar
Joel Alarcón committed
536
537
538
539
540
541
             ,xml => 'bionic-amd64.xml'
             ,xml_volume => 'bionic64-volume.xml'
         }
         ,lubuntu_bionic_32 => {
             name => 'Lubuntu Bionic Beaver 32 bits'
             ,description => 'Lubuntu 18.04 Bionic Beaver 32 bits'
Francesc Guasch's avatar
Francesc Guasch committed
542
             ,arch => 'i686'
Joel Alarcón's avatar
Joel Alarcón committed
543
             ,url => 'http://cdimage.ubuntu.com/lubuntu/releases/18.04.*/release/lubuntu-18.04.*-desktop-i386.iso'
544
             ,sha256_url => '$url/SHA256SUMS'
Joel Alarcón's avatar
Joel Alarcón committed
545
546
547
             ,xml => 'bionic-i386.xml'
             ,xml_volume => 'bionic32-volume.xml'
        }
548
549
550
        ,lubuntu_xenial => {
            name => 'Lubuntu Xenial Xerus'
            ,description => 'Xubuntu 16.04 Xenial Xerus 64 bits (LTS)'
551
552
            ,url => 'http://cdimage.ubuntu.com/lubuntu/releases/16.04.*/release/'
            ,file_re => 'lubuntu-16.04.*-desktop-amd64.iso'
frankiejol's avatar
frankiejol committed
553
            ,sha256_url => '$url/SHA256SUMS'
554
555
            ,xml => 'yakkety64-amd64.xml'
            ,xml_volume => 'yakkety64-volume.xml'
556
            ,min_disk_size => '10'
557
        }
558
559
560
        ,debian_jessie_32 => {
            name =>'Debian Jessie 32 bits'
            ,description => 'Debian 8 Jessie 32 bits'
561
            ,url => 'http://cdimage.debian.org/cdimage/archive/^8\.1\d+\.\d$/i386/iso-cd/'
562
            ,file_re => 'debian-8.[\d\.]+-i386-xfce-CD-1.iso'
563
            ,md5_url => '$url/MD5SUMS'
564
            ,xml => 'jessie-i386.xml'
565
            ,xml_volume => 'jessie-volume.xml'
566
            ,min_disk_size => '10'
Francesc Guasch's avatar
Francesc Guasch committed
567
            ,arch => 'i686'
568
569
570
571
        }
        ,debian_jessie_64 => {
            name =>'Debian Jessie 64 bits'
            ,description => 'Debian 8 Jessie 64 bits'
572
            ,url => 'http://cdimage.debian.org/cdimage/archive/^8\.1\d+.*\d$/amd64/iso-cd/'
573
574
575
576
            ,file_re => 'debian-8.[\d\.]+-amd64-xfce-CD-1.iso'
            ,md5_url => '$url/MD5SUMS'
            ,xml => 'jessie-amd64.xml'
            ,xml_volume => 'jessie-volume.xml'
577
            ,min_disk_size => '10'
Francesc Guasch's avatar
Francesc Guasch committed
578
            ,arch => 'x86_64'
579
        }
580
581
582
       ,debian_stretch_32 => {
            name =>'Debian Stretch 32 bits'
            ,description => 'Debian 9 Stretch 32 bits (XFCE desktop)'
583
            ,url => 'https://cdimage.debian.org/cdimage/archive/^9\.1\d.*\d$/i386/iso-cd/'
584
585
586
587
588
            ,file_re => 'debian-9.[\d\.]+-i386-xfce-CD-1.iso'
            ,md5_url => '$url/MD5SUMS'
            ,xml => 'jessie-i386.xml'
            ,xml_volume => 'jessie-volume.xml'
            ,min_disk_size => '10'
Francesc Guasch's avatar
Francesc Guasch committed
589
            ,arch => 'i686'
590
591
        }
        ,debian_stretch_64 => {
592
            name =>'Debian Stretch 64 bits'
Francesc Guasch's avatar
Francesc Guasch committed
593
            ,description => 'Debian 9 Stretch 64 bits (XFCE desktop)'
594
            ,url => 'https://cdimage.debian.org/cdimage/archive/^9\.1\d.*/amd64/iso-cd/'
595
            ,file_re => 'debian-9.[\d\.]+-amd64-xfce-CD-1.iso'
596
            ,md5_url => '$url/MD5SUMS'
597
598
            ,xml => 'jessie-amd64.xml'
            ,xml_volume => 'jessie-volume.xml'
599
            ,min_disk_size => '10'
Francesc Guasch's avatar
Francesc Guasch committed
600
            ,arch => 'x86_64'
601
        }
602
603
604
        ,debian_buster_64=> {
            name =>'Debian Buster 64 bits'
            ,description => 'Debian 10 Buster 64 bits (XFCE desktop)'
605
            ,url => 'https://cdimage.debian.org/cdimage/archive/^10\.1\d+.*\d$/amd64/iso-cd/'
606
607
608
609
610
            ,file_re => 'debian-10.[\d\.]+-amd64-xfce-CD-1.iso'
            ,md5_url => '$url/MD5SUMS'
            ,xml => 'jessie-amd64.xml'
            ,xml_volume => 'jessie-volume.xml'
            ,min_disk_size => '10'
Francesc Guasch's avatar
Francesc Guasch committed
611
            ,arch => 'x86_64'
612
613
614
615
        }
        ,debian_buster_32=> {
            name =>'Debian Buster 32 bits'
            ,description => 'Debian 10 Buster 32 bits (XFCE desktop)'
616
            ,url => 'https://cdimage.debian.org/cdimage/archive/^10\.1\d+.*\d$/i386/iso-cd/'
617
            ,file_re => 'debian-10.[\d\.]+-i386-(netinst|xfce-CD-1).iso'
618
619
620
621
            ,md5_url => '$url/MD5SUMS'
            ,xml => 'jessie-i386.xml'
            ,xml_volume => 'jessie-volume.xml'
            ,min_disk_size => '10'
Francesc Guasch's avatar
Francesc Guasch committed
622
            ,arch => 'i686'
623
        }
624
625
        ,debian_bullseye_64=> {
            name =>'Debian Bullseye 64 bits'
Francesc Guasch's avatar
Francesc Guasch committed
626
            ,arch => 'x86_64'
627
628
629
630
631
632
633
            ,description => 'Debian 11 Bullseye 64 bits (netinst)'
            ,url => 'https://cdimage.debian.org/debian-cd/^11\..*\d$/amd64/iso-cd/'
            ,file_re => 'debian-11.[\d\.]+-amd64-netinst.iso'
            ,sha256_url => '$url/SHA256SUMS'
            ,xml => 'jessie-amd64.xml'
            ,xml_volume => 'jessie-volume.xml'
            ,min_disk_size => '10'
Francesc Guasch's avatar
Francesc Guasch committed
634
            ,options => { machine => 'pc-q35', bios => 'UEFI' }
635
636
637
        }
        ,debian_bullseye_32=> {
            name =>'Debian Bullseye 32 bits'
Francesc Guasch's avatar
Francesc Guasch committed
638
            ,arch => 'i686'
639
640
641
642
643
644
645
            ,description => 'Debian 10 Bullseye 32 bits (netinst)'
            ,url => 'https://cdimage.debian.org/debian-cd/^11\..*\d$/i386/iso-cd/'
            ,file_re => 'debian-11.[\d\.]+-i386-netinst.iso'
            ,sha256_url => '$url/SHA256SUMS'
            ,xml => 'jessie-i386.xml'
            ,xml_volume => 'jessie-volume.xml'
            ,min_disk_size => '10'
Francesc Guasch's avatar
Francesc Guasch committed
646
            ,options => { machine => 'pc-i440fx' }
647
        }
648
649
650
        ,devuan_beowulf_amd64=> {
            name =>'Devuan Beowulf 64 bits'
            ,description => 'Devuan Beowulf Desktop Live (amd64)'
Francesc Guasch's avatar
Francesc Guasch committed
651
            ,arch => 'x86_64'
652
653
654
655
656
657
658
659
660
661
            ,url => 'http://tw1.mirror.blendbyte.net/devuan-cd/devuan_beowulf/desktop-live/'
            ,file_re => 'devuan_beowulf_.*_amd64_desktop-live.iso'
            ,sha256_url => '$url/SHASUMS.txt'
            ,xml => 'jessie-amd64.xml'
            ,xml_volume => 'jessie-volume.xml'
            ,min_disk_size => '10'
        }
        ,devuan_beowulf_i386=> {
            name =>'Devuan Beowulf 32 bits'
            ,description => 'Devuan Beowulf Desktop Live (i386)'
Francesc Guasch's avatar
Francesc Guasch committed
662
            ,arch => 'i686'
663
664
665
666
667
668
669
            ,url => 'http://tw1.mirror.blendbyte.net/devuan-cd/devuan_beowulf/desktop-live/'
            ,file_re => 'devuan_beowulf_.*_i386_desktop-live.iso'
            ,sha256_url => '$url/SHASUMS.txt'
            ,xml => 'jessie-i386.xml'
            ,xml_volume => 'jessie-volume.xml'
            ,min_disk_size => '10'
        }
670
671
672
        ,parrot_xfce_amd64 => {
            name => 'Parrot Home Edition XFCE'
            ,description => 'Parrot Home Edition XFCE 64 Bits'
Francesc Guasch's avatar
Francesc Guasch committed
673
            ,arch => 'x86_64'
674
675
            ,xml => 'jessie-amd64.xml'
            ,xml_volume => 'jessie-volume.xml'
Roberto P. Rubio's avatar
Roberto P. Rubio committed
676
677
            ,url => 'https://edge1.parrot.run/parrot/iso/4.11.3/'
            ,file_re => 'Parrot-xfce-4.11.3_amd64.iso'
678
679
680
681
682
683
            ,sha256_url => '$url/signed-hashes.txt'
            ,min_disk_size => '10'
        }
        ,parrot_mate_amd64 => {
		  name => 'Parrot Security Edition MATE'
            ,description => 'Parrot Security Edition MATE 64 Bits'
Francesc Guasch's avatar
Francesc Guasch committed
684
            ,arch => 'x86_64'
685
686
            ,xml => 'jessie-amd64.xml'
            ,xml_volume => 'jessie-volume.xml'
Roberto P. Rubio's avatar
Roberto P. Rubio committed
687
688
            ,url => 'https://edge1.parrot.run/parrot/iso/4.11.3/'
            ,file_re => 'Parrot-security-4.11.3_amd64.iso'
689
690
691
            ,sha256_url => '$url/signed-hashes.txt'
            ,min_disk_size => '10'
        }
692
        ,kali_64 => {
Roberto P. Rubio's avatar
Roberto P. Rubio committed
693
694
            name => 'Kali Linux 2021'
            ,description => 'Kali Linux 2021 64 Bits'
Francesc Guasch's avatar
Francesc Guasch committed
695
            ,arch => 'x86_64'
696
697
            ,xml => 'jessie-amd64.xml'
            ,xml_volume => 'jessie-volume.xml'
Roberto P. Rubio's avatar
Roberto P. Rubio committed
698
699
            ,url => 'https://cdimage.kali.org/kali-2021.\d+/'
            ,file_re => 'kali-linux-2021.\d+-installer-amd64.iso'
700
701
702
703
            ,sha256_url => '$url/SHA256SUMS'
            ,min_disk_size => '10'
        }
        ,kali_64_netinst => {
Roberto P. Rubio's avatar
Roberto P. Rubio committed
704
705
            name => 'Kali Linux 2021 (NetInstaller)'
            ,description => 'Kali Linux 2021 64 Bits (light NetInstall)'
Francesc Guasch's avatar
Francesc Guasch committed
706
            ,arch => 'x86_64'
707
708
            ,xml => 'jessie-amd64.xml'
            ,xml_volume => 'jessie-volume.xml'
Roberto P. Rubio's avatar
Roberto P. Rubio committed
709
710
            ,url => 'https://cdimage.kali.org/kali-2021.\d+/'
            ,file_re => 'kali-linux-2021.\d+-installer-netinst-amd64.iso'
711
712
713
            ,sha256_url => '$url/SHA256SUMS'
            ,min_disk_size => '10'
        }
joelalju's avatar
joelalju committed
714
        ,windows_7 => {
Francesc Guasch's avatar
Francesc Guasch committed
715
          name => 'Windows 7'
716
717
          ,description => 'Windows 7 64 bits. Requires an user provided ISO image.'
            .'<a target="_blank" href="http://ravada.readthedocs.io/en/latest/docs/new_iso_image.html">[help]</a>'
joelalju's avatar
joelalju committed
718
          ,xml => 'windows_7.xml'
joelalju's avatar
joelalju committed
719
          ,xml_volume => 'wisuvolume.xml'
720
          ,min_disk_size => '21'
Francesc Guasch's avatar
Francesc Guasch committed
721
          ,arch => 'x86_64'
joelalju's avatar
joelalju committed
722
723
724
725
726
727
        }
        ,windows_10 => {
          name => 'Windows 10'
          ,description => 'Windows 10 64 bits. Requires an user provided ISO image.'
          .'<a target="_blank" href="http://ravada.readthedocs.io/en/latest/docs/new_iso_image.html">[help]</a>'
          ,xml => 'windows_10.xml'
728
          ,xml_volume => 'windows10-volume.xml'
729
          ,min_disk_size => '21'
730
          ,min_swap_size => '2'
Francesc Guasch's avatar
Francesc Guasch committed
731
          ,arch => 'x86_64'
Francesc Guasch's avatar
Francesc Guasch committed
732
          ,extra_iso => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.215-\d+/virtio-win-0.1.\d+.iso'
joelalju's avatar
joelalju committed
733
        }
joelalju's avatar
joelalju committed
734
735
736
737
738
739
        ,windows_xp => {
          name => 'Windows XP'
          ,description => 'Windows XP 64 bits. Requires an user provided ISO image.'
          .'<a target="_blank" href="http://ravada.readthedocs.io/en/latest/docs/new_iso_image.html">[help]</a>'
          ,xml => 'windows_xp.xml'
          ,xml_volume => 'wisuvolume.xml'
740
          ,min_disk_size => '3'
Francesc Guasch's avatar
Francesc Guasch committed
741
          ,arch => 'x86_64'
joelalju's avatar
joelalju committed
742
743
744
745
746
747
748
        }
        ,windows_12 => {
          name => 'Windows 2012'
          ,description => 'Windows 2012 64 bits. Requires an user provided ISO image.'
          .'<a target="_blank" href="http://ravada.readthedocs.io/en/latest/docs/new_iso_image.html">[help]</a>'
          ,xml => 'windows_12.xml'
          ,xml_volume => 'wisuvolume.xml'
749
          ,min_disk_size => '21'
Francesc Guasch's avatar
Francesc Guasch committed
750
          ,arch => 'x86_64'
joelalju's avatar
joelalju committed
751
752
753
754
755
756
757
        }
        ,windows_8 => {
          name => 'Windows 8.1'
          ,description => 'Windows 8.1 64 bits. Requires an user provided ISO image.'
          .'<a target="_blank" href="http://ravada.readthedocs.io/en/latest/docs/new_iso_image.html">[help]</a>'
          ,xml => 'windows_8.xml'
          ,xml_volume => 'wisuvolume.xml'
758
          ,min_disk_size => '21'
Francesc Guasch's avatar
Francesc Guasch committed
759
          ,arch => 'x86_64'
joelalju's avatar
joelalju committed
760
        }
Francesc Guasch's avatar
Francesc Guasch committed
761
762
763
764
765
766
767
768
        ,windows_11 => {
          name => 'Windows 11'
          ,description => 'Windows 11 64 bits. Requires an user provided ISO image.'
          .'<a target="_blank" href="http://ravada.readthedocs.io/en/latest/docs/new_iso_image.html">[help]</a>'
          ,xml => 'windows_11.xml'
          ,xml_volume => 'windows11-volume.xml'
          ,min_disk_size => '64'
          ,min_swap_size => '2'
Francesc Guasch's avatar
Francesc Guasch committed
769
          ,min_ram => 4
Francesc Guasch's avatar
Francesc Guasch committed
770
771
772
773
          ,arch => 'x86_64'
          ,extra_iso => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.2\d+-\d+/virtio-win-0.1.2\d+.iso'
            ,options => { machine => 'pc-q35', bios => 'UEFI' }
        }
Daniel Sanchez's avatar
Daniel Sanchez committed
774
775
776
777
778
779
       ,empty_32bits => {
          name => 'Empty Machine 32 bits'
          ,description => 'Empty Machine 32 bits Boot PXE'
          ,xml => 'empty-i386.xml'
          ,xml_volume => 'jessie-volume.xml'
          ,min_disk_size => '0'
780
          ,has_cd => 0
Daniel Sanchez's avatar
Daniel Sanchez committed
781
782
783
784
785
786
787
        }
       ,empty_64bits => {
          name => 'Empty Machine 64 bits'
          ,description => 'Empty Machine 64 bits Boot PXE'
          ,xml => 'empty-amd64.xml'
          ,xml_volume => 'jessie-volume.xml'
          ,min_disk_size => '0'
Francesc Guasch's avatar
Francesc Guasch committed
788
          ,arch => 'x86_64'
789
          ,has_cd => 0
Daniel Sanchez's avatar
Daniel Sanchez committed
790
        }
791
    );
792
    $self->_scheduled_fedora_releases(\%data) if $0 !~ /\.t$/;
793
    $self->_update_table($table, $field, \%data);
794
    $self->_update_table_isos_url(\%data);
795
796
797

}

798
799
800
801
sub _update_table_isos_url($self, $data) {
    my $sth = $CONNECTOR->dbh->prepare("SELECT * FROM iso_images WHERE name=?");
    for my $release (sort keys %$data) {
        my $entry = $data->{$release};
Francesc Guasch's avatar
Francesc Guasch committed
802
803
804
805
806
807
808
        if (exists $entry->{options} && $entry->{options} 
            && ref($entry->{options})
        ) {
            unlock_hash(%$entry);
            $entry->{options} = encode_json($entry->{options});
            lock_hash(%$entry);
        }
809
810
811
812
813
814
815
816
817
        $sth->execute($entry->{name});
        my $row = $sth->fetchrow_hashref();
        for my $field (keys %$entry) {
            next if defined $row->{$field} && $row->{$field} eq $entry->{$field};
            my $sth_update = $CONNECTOR->dbh->prepare(
                "UPDATE iso_images SET $field=?"
                ." WHERE id=?"
            );
            $sth_update->execute($entry->{$field}, $row->{id});
818
            warn("INFO: updating $release $field '".($row->{$field} or '')."' -> '$entry->{$field}'\n")
819
820
821
822
823
            if !$FIRST_TIME_RUN && $0 !~ /\.t$/;
        }
    }
}

824
sub _scheduled_fedora_releases($self,$data) {
825

826
    return if !exists $VALID_VM{KVM} ||!$VALID_VM{KVM} || $>;
827
    my $vm = $self->search_vm('KVM') or return; # TODO move ISO downloads off KVM
828

829
830
831
832
    my @now = localtime(time);
    my $year = $now[5]+1900;
    my $month = $now[4]+1;

833
834
835
836
837
838
    my $url_archive
    = 'https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/';

    my $url_current
    = 'http://ftp.halifax.rwth-aachen.de/fedora/linux/releases/';

839
    my $release = 27;
840

841
842
843
844
845
846
    for my $y ( 2018 .. $year ) {
        for my $m ( 5, 11 ) {
            return if $y == $year && $m>$month;
            $release++;
            my $name = "fedora_".$release;
            next if exists $data->{$name};
847
848
849
850

            my $url = $url_archive;
            $url = $url_current if $y>=$year-1;

851
852
853
            my $url_file = $url.$release
                    .'/Workstation/x86_64/iso/Fedora-Workstation-.*-x86_64-'.$release
                    .'-.*\.iso';
854
855
            my @found;
            eval { @found = $vm->_search_url_file($url_file) };
856
857
858
859
            if ( $@ && $@ !~ /Not Found/i ) {
                warn $@;
                return;
            }
860
861
862
863
864
865
866
867
868
869
            if(!@found) {
                next if $url =~ m{//archives};

                $url_file = $url_archive.$release
                    .'/Workstation/x86_64/iso/Fedora-Workstation-.*-x86_64-'.$release
                    .'-.*\.iso';
                @found = $vm->_search_url_file($url_file);
                next if !scalar(@found);
            }

870
871
872
            $data->{$name} = {
            name => 'Fedora '.$release
            ,description => "RedHat Fedora $release Workstation 64 bits"
Francesc Guasch's avatar
Francesc Guasch committed
873
            ,arch => 'x86_64'
874
            ,url => $url_file
875
876
877
878
879
880
881
882
883
            ,xml => 'xenial64-amd64.xml'
            ,xml_volume => 'xenial64-volume.xml'
            ,sha256_url => '$url/Fedora-Workstation-'.$release.'-.*-x86_64-CHECKSUM'
            ,min_disk_size => 10 + $release-27
            };
        }
    }
}

Francesc Guasch's avatar
Francesc Guasch committed
884
sub _add_domain_drivers_display($self) {
Francesc Guasch's avatar
Francesc Guasch committed
885
    my $port_rdp = 3389;
Francesc Guasch's avatar
Francesc Guasch committed
886
887
888
889
890
    my %data = (
        'KVM' => [
            'spice'
            ,'vnc'
            ,{name => 'x2go', data => 22 }
Francesc Guasch's avatar
Francesc Guasch committed
891
            ,{name => 'Windows RDP', value => 'rdp', data => $port_rdp}
Francesc Guasch's avatar
Francesc Guasch committed
892
893
894
895
896
        ]
        ,'Void' => [
            'void'
            ,'spice'
            ,{name => 'x2go', data => 22 }
Francesc Guasch's avatar
Francesc Guasch committed
897
            ,{name => 'Windows RDP', value => 'rdp' , data => $port_rdp }
Francesc Guasch's avatar
Francesc Guasch committed
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
        ]
    );

    my $id_type = Ravada::Utils::max_id($CONNECTOR->dbh, 'domain_drivers_types')+1;
    my $id_option = Ravada::Utils::max_id($CONNECTOR->dbh, 'domain_drivers_options');
    for my $vm ( keys %data) {
        my $type = {
            id => $id_type
            ,name => 'display'
            ,description => 'Display'
            ,vm => $vm
        };

        $self->_update_table('domain_drivers_types','name,vm',$type)
            and do {
            for my $option ( @{$data{$vm}} ) {
                if (!ref($option)) {
                    $option = { name => $option
                        ,value => $option
                    };
                }
                $option->{value} = $option->{name} if !exists $option->{value};
                $option->{id_driver_type} = $id_type;
                $option->{id} = ++$id_option;
                $self->_update_table('domain_drivers_options','id_driver_type,name',$option)
            }
            $id_type++;
        };
    }
}

Francesc Guasch's avatar
Francesc Guasch committed
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
sub _add_domain_drivers_cpu($self) {
    my %data = (
        'KVM' => [
            'custom'
            ,'host-model'
            ,'host-passthrough'
        ]
    );

    my $id_type = Ravada::Utils::max_id($CONNECTOR->dbh, 'domain_drivers_types')+1;
    my $id_option = Ravada::Utils::max_id($CONNECTOR->dbh, 'domain_drivers_options');
    for my $vm ( keys %data) {
        my $type = {
            id => $id_type
            ,name => 'cpu'
            ,description => 'CPU'
            ,vm => $vm
        };

        $self->_update_table('domain_drivers_types','name,vm',$type)
            and do {
            for my $option ( @{$data{$vm}} ) {
                if (!ref($option)) {
                    $option = { name => $option
                        ,value => $option
                    };
                }
                $option->{value} = $option->{name} if !exists $option->{value};
                $option->{id_driver_type} = $id_type;
                $option->{id} = ++$id_option;
                $self->_update_table('domain_drivers_options','id_driver_type,name',$option)
            }
            $id_type++;
        };
    }
}

966
967
968
969
970
971
972
sub _update_domain_drivers_types($self) {

    my $data = {
        image => {
            id => 4,
            ,name => 'image'
           ,description => 'Graphics Options'
973
           ,vm => 'KVM'
974
975
976
977
978
        },
        jpeg => {
            id => 5,
            ,name => 'jpeg'
           ,description => 'Graphics Options'
979
           ,vm => 'KVM'
980
981
982
983
984
        },
        zlib => {
            id => 6,
            ,name => 'zlib'
           ,description => 'Graphics Options'
985
           ,vm => 'KVM'
986
987
988
989
990
        },
        playback => {
            id => 7,
            ,name => 'playback'
           ,description => 'Graphics Options'
991
           ,vm => 'KVM'
992
993
994
995
996
997

        },
        streaming => {
            id => 8,
            ,name => 'streaming'
           ,description => 'Graphics Options'
998
           ,vm => 'KVM'
999
1000

        }
For faster browsing, not all history is shown. View entire blame