Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
weblate committed Sep 29, 2023
2 parents 70ec1d1 + cda6f07 commit 47df3fe
Show file tree
Hide file tree
Showing 36 changed files with 1,193 additions and 154 deletions.
2 changes: 1 addition & 1 deletion etc/xml/windows_11.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<vmport state='off'/>
<smm state='on'/>
</features>
<cpu mode='host-model' check='partial'>
<cpu mode='custom' check='partial'>
<topology sockets='1' cores='2' threads='2'/>
</cpu>
<clock offset='localtime'>
Expand Down
111 changes: 100 additions & 11 deletions lib/Ravada.pm
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ sub _update_isos {
,file_re => 'alpine-standard-3.16.*-x86_64.iso'
,sha256_url => '$url/alpine-standard-3.16.*.iso.sha256'
,min_disk_size => '2'
,options => { machine => 'pc-q35', bios => 'UEFI' }
,options => { machine => 'pc-q35', bios => 'UEFI'
}
}
,alpine381_32 => {
name => 'Alpine 3.16 32 bits'
Expand Down Expand Up @@ -706,7 +707,7 @@ sub _update_isos {
name =>'Debian Bullseye 64 bits'
,arch => 'x86_64'
,description => 'Debian 11 Bullseye 64 bits (netinst)'
,url => 'https://cdimage.debian.org/debian-cd/^11\..*\d$/amd64/iso-cd/'
,url => 'https://cdimage.debian.org/cdimage/archive/11.[\d\.]+/amd64/iso-cd/'
,file_re => 'debian-11.[\d\.]+-amd64-netinst.iso'
,sha256_url => '$url/SHA256SUMS'
,xml => 'jessie-amd64.xml'
Expand All @@ -717,15 +718,42 @@ sub _update_isos {
,debian_bullseye_32=> {
name =>'Debian Bullseye 32 bits'
,arch => 'i686'
,description => 'Debian 10 Bullseye 32 bits (netinst)'
,url => 'https://cdimage.debian.org/debian-cd/^11\..*\d$/i386/iso-cd/'
,description => 'Debian 11 Bullseye 32 bits (netinst)'
,url => 'https://cdimage.debian.org/cdimage/archive/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'
,options => { machine => 'pc-i440fx' }
}
,debian_bookworm_64 => {
name =>'Debian Bookworm 64 bits'
,arch => 'x86_64'
,description => 'Debian 12 Bookworm 64 bits (netinst)'
,url => 'https://cdimage.debian.org/debian-cd/12[\.\d]+/amd64/iso-cd/'
,file_re => 'debian-12.[\d\.]+-amd64-netinst.iso'
,sha256_url => '$url/SHA256SUMS'
,xml => 'jessie-amd64.xml'
,xml_volume => 'jessie-volume.xml'
,min_disk_size => '11'
,min_ram => 3
,options => { machine => 'pc-q35', bios => 'UEFI' }
}
,debian_bookworm_32 => {
name =>'Debian Bookworm 32 bits'
,arch => 'i686'
,description => 'Debian 12 Bookworm 32 bits (netinst)'
,url => 'https://cdimage.debian.org/debian-cd/12[\.\d]+/i386/iso-cd/'
,file_re => 'debian-12.[\d\.]+-i386-netinst.iso'
,sha256_url => '$url/SHA256SUMS'
,xml => 'jessie-amd64.xml'
,xml_volume => 'jessie-volume.xml'
,min_disk_size => '11'
,min_ram => 3
,options => { machine => 'pc-i440fx'}
}

,devuan_beowulf_amd64=> {
name =>'Devuan Beowulf 64 bits'
,description => 'Devuan Beowulf Desktop Live (amd64)'
Expand Down Expand Up @@ -839,7 +867,9 @@ sub _update_isos {
,min_ram => 4
,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' }
,options => { machine => 'pc-q35', bios => 'UEFI'
,hardware => { cpu => { cpu => { topology => { threads => 2, cores => 2}}}}
}
}
,empty_32bits => {
name => 'Empty Machine 32 bits'
Expand Down Expand Up @@ -912,7 +942,8 @@ sub _update_table_isos_url($self, $data) {
." WHERE id=?"
);
$sth_update->execute($entry->{$field}, $row->{id});
warn("INFO: updating $release $field '".($row->{$field} or '')."' -> '$entry->{$field}'\n")
warn("INFO: updating $release $field ".Dumper($row->{$field})." -> "
.Dumper($entry->{$field})."\n")
if !$FIRST_TIME_RUN && $0 !~ /\.t$/;
}
}
Expand Down Expand Up @@ -1395,7 +1426,7 @@ sub _update_table($self, $table, $field, $data, $verbose=0) {
warn("INFO: $table : $row->{$field} already added.\n") if $verbose;
next;
}
warn("INFO: updating $table : ".Dumper($data->{$name})."\n")
warn("INFO: updating $table [ $name ] : ".Dumper($data->{$name})."\n")
if !$FIRST_TIME_RUN && $0 !~ /\.t$/;

my $sql =
Expand Down Expand Up @@ -3309,9 +3340,9 @@ sub _add_extra_iso($domain, $request, $previous_request) {
return $req_add;
}

sub _check_args($args,@) {
sub _check_args($args,@fields) {
my %args_check = %$args;
for my $field (@_) {
for my $field (@fields) {
delete $args_check{$field};
}
confess "ERROR: Unknown arguments ".Dumper(\%args_check) if keys %args_check;
Expand Down Expand Up @@ -5129,6 +5160,51 @@ sub _cmd_reboot {

}

sub _cmd_shutdown_start($self, $request) {
my $uid = $request->args('uid');
my $id_domain = $request->args('id_domain');
my $id_vm = $request->defined_arg('id_vm');

my $domain;
if ($id_vm) {
my $vm = Ravada::VM->open($id_vm);
$domain = $vm->search_domain_by_id($id_domain);
} else {
$domain = $self->search_domain_by_id($id_domain);
}
die "Unknown domain '$id_domain'\n" if !$domain;

my $user = Ravada::Auth::SQL->search_by_id( $uid);

die "USER $uid not authorized to restart machine ".$domain->name
unless $domain->_data('id_owner') == $user->id || $user->is_operator;

my $timeout = ($request->defined_arg('timeout') or $domain->_timeout_shutdown() or 60);

for my $try ( 0 .. 1 ) {
$domain->shutdown(timeout => $timeout, user => $user
, request => $request);

for ( 0 .. $timeout+1 ) {
last if !$domain->is_active;
sleep 1;
}
last if !$domain->is_active;
}

my $req_shutdown = Ravada::Request->force_shutdown_domain(
uid => $user->id
,id_domain => $domain->id
,after_request => $request->id
);

Ravada::Request->start_domain(
uid => $user->id
,id_domain => $domain->id
,after_request => $req_shutdown->id
);
}

sub _cmd_force_reboot {
my $self = shift;
my $request = shift;
Expand Down Expand Up @@ -5642,7 +5718,12 @@ sub _refresh_active_domains($self, $request=undef) {
my %active_domain;

if ($id_domain) {
my $domain = $self->search_domain_by_id($id_domain);
my $domain;
eval { $domain = $self->search_domain_by_id($id_domain) };
if ( $@ ) {
next if $@ =~ /not found/;
warn $@;
}
$self->_refresh_active_domain($domain, \%active_domain) if $domain;
} else {
my @domains;
Expand All @@ -5653,7 +5734,12 @@ sub _refresh_active_domains($self, $request=undef) {
@domains) {
$request->error("checking $domain_data->{name}") if $request;
next if $active_domain{$domain_data->{id}};
my $domain = Ravada::Domain->open($domain_data->{id});
my $domain;
eval { $domain = Ravada::Domain->open($domain_data->{id}) };
if ( $@ ) {
next if $@ =~ /not found/;
warn $@;
}
next if !$domain;
$self->_refresh_active_domain($domain, \%active_domain);
$self->_remove_unnecessary_downs($domain) if !$domain->is_active;
Expand Down Expand Up @@ -6060,6 +6146,7 @@ sub _req_method {
,enforce_limits => \&_cmd_enforce_limits
,force_shutdown => \&_cmd_force_shutdown
,force_reboot => \&_cmd_force_reboot
,shutdown_start => \&_cmd_shutdown_start
,rebase => \&_cmd_rebase

,refresh_storage => \&_cmd_refresh_storage
Expand Down Expand Up @@ -6430,6 +6517,8 @@ sub _cmd_close_exposed_ports($self, $request) {
my $user = Ravada::Auth::SQL->search_by_id( $uid ) or die "Error: user $uid not found";

my $domain = Ravada::Domain->open($request->id_domain);
return if !$domain;

die "Error: user ".$user->name." not authorized to delete iptables rule"
unless $user->is_admin || $domain->_data('id_owner') == $uid;

Expand Down
1 change: 1 addition & 0 deletions lib/Ravada/Auth.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use strict;
our $LDAP_OK;
our $SSO_OK;

use Data::Dumper;
use Ravada::Auth::SQL;

=head1 NAME
Expand Down
6 changes: 6 additions & 0 deletions lib/Ravada/Auth/SSO.pm
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ sub _get_session_userid_by_ticket
my ($cookie) = @_;
my $result;
die 'Can\'t read pubkey file (sso->cookie->pub_key value at ravada.conf file)' if (! -r $$CONFIG->{sso}->{cookie}->{pub_key});

eval { $result = Authen::ModAuthPubTkt::pubtkt_verify(publickey => $$CONFIG->{sso}->{cookie}->{pub_key}, keytype => $$CONFIG->{sso}->{cookie}->{type}, ticket => $cookie); };
die $@ ? $@ : 'Cannot validate ticket' if ((! $result) || ($@));
my %data = Authen::ModAuthPubTkt::pubtkt_parse($cookie);
Expand Down Expand Up @@ -123,6 +124,11 @@ sub init {
return 0;
}
}
if (!$$CONFIG->{sso}->{cookie}->{type}) {
$ERR = "Error: missing sso / cookie / type in config file\n";
warn $ERR unless $warn++;
return 0;
}
for my $field (qw(priv_key pub_key)) {
if ( !exists $$CONFIG->{sso}->{cookie}->{$field}
|| ! $$CONFIG->{sso}->{cookie}->{$field}) {
Expand Down
40 changes: 29 additions & 11 deletions lib/Ravada/Domain.pm
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ sub _around_start($orig, $self, @arg) {

$self->_start_preconditions(@arg);

$self->_pre_start_internal();

$self->_data( 'post_shutdown' => 0);
$self->_data( 'post_hibernated' => 0);

Expand All @@ -320,7 +322,7 @@ sub _around_start($orig, $self, @arg) {
$enable_host_devices = $request->defined_arg('enable_host_devices') if $request;
$enable_host_devices = 1 if !defined $enable_host_devices;

for (;;) {
for (1 .. 5) {
eval { $self->_start_checks(@arg) };
my $error = $@;
if ($error) {
Expand Down Expand Up @@ -375,6 +377,7 @@ sub _around_start($orig, $self, @arg) {
&& $error !~ /process exited while connecting to monitor/
&& $error !~ /Could not run .*swtpm/i
&& $error !~ /virtiofs/
&& $error !~ /child process/i
;

if ($error && $self->id_base && !$self->is_local && $self->_vm->enabled) {
Expand Down Expand Up @@ -701,7 +704,9 @@ sub _around_add_volume {
($name) = $file =~ m{.*/(.*)} if !$name && $file;
$name = $self->name if !$name;

$name .= "-".$args{target}."-".Ravada::Utils::random_name(4);
$name .= "-".$args{target}."-".Ravada::Utils::random_name(4)
if $name !~ /\.iso$/;

$args{name} = $name;
}

Expand All @@ -714,10 +719,12 @@ sub _around_add_volume {
$args{allocation} = Ravada::Utils::size_to_number($args{allocation})
if exists $args{allocation} && defined $args{allocation};

my $free = $self->_vm->free_disk();
my $storage = $args{storage};

my $free = $self->_vm->free_disk($storage);
my $free_out = int($free / 1024 / 1024 / 1024 ) * 1024 *1024 *1024;

confess "Error creating volume, out of space $size . Disk free: "
die "Error creating volume, out of space $size . Disk free: "
.Ravada::Utils::number_to_size($free_out)
."\n"
if exists $args{size} && $args{size} && $args{size} >= $free;
Expand Down Expand Up @@ -1547,7 +1554,7 @@ Returns the id of the domain

sub id($self) {
return $self->{_id} if exists $self->{_id};
my $id = $_[0]->_data('id');
my $id = $self->_data('id');
$self->{_id} = $id;
return $id;
}
Expand Down Expand Up @@ -1660,6 +1667,10 @@ sub _data($self, $field, $value=undef, $table='domains') {

sub _data_extra($self, $field, $value=undef) {
$self->_insert_db_extra() if !$self->is_known_extra();
if (defined $value) {
my $old = $self->_data_extra($field);
return if defined $old && $old eq $value;
}
return $self->_data($field, $value, "domains_".lc($self->type));
}

Expand Down Expand Up @@ -1940,9 +1951,6 @@ sub display($self, $user) {

my ($display_info) = grep { $_->{driver} !~ /-tls$/ } @display_info;

confess "Error: I can't find builtin display info for ".$self->name." ".ref($self)."\n".Dumper($display_info)
if !exists $display_info->{port};

return '' if !$display_info->{driver} || !$display_info->{ip}
|| !$display_info->{port};

Expand Down Expand Up @@ -3041,9 +3049,17 @@ sub _remove_start_requests($self) {
}
}

# it may be superceeded in child class
sub _post_shutdown_internal {}

# it may be superceeded in child class
sub _pre_start_internal {}

sub _post_shutdown {
my $self = shift;

$self->_post_shutdown_internal();

my %arg = @_;
my $timeout = delete $arg{timeout};
if (!defined $timeout) {
Expand Down Expand Up @@ -4022,7 +4038,7 @@ sub _post_resume {
return $self->_post_start(@_);
}

sub _timeout_shutdown($self, $value) {
sub _timeout_shutdown($self, $value=undef) {
$TIMEOUT_SHUTDOWN = $value if defined $value;
return $TIMEOUT_SHUTDOWN;
}
Expand Down Expand Up @@ -4518,6 +4534,7 @@ Check if the domain has swap volumes defined, and clean them

sub clean_swap_volumes {
my $self = shift;
return if $self->is_active();
for my $vol ( $self->list_volumes_info) {
confess if !$vol->domain;
if ($vol->file && $vol->file =~ /\.SWAP\.\w+$/) {
Expand Down Expand Up @@ -5607,7 +5624,7 @@ sub _run_iptstate($self, $force=undef) {
&& ( time - $self->_vm->{_iptstate_time} < $TIME_CACHE_NETSTAT+1 ) ) {
return $self->_vm->{_iptstate};
}
my @cmd = ("iptstate", "-1");
my @cmd = ("iptstate", "-1","-L","--no-color","-o");
my ( $out, $err) = $self->_vm->run_command(@cmd);
$self->_vm->{_iptstate} = $out;
$self->_vm->{_iptstate_time} = time;
Expand Down Expand Up @@ -5666,6 +5683,7 @@ hardware change can be applied.
=cut

sub needs_restart($self, $value=undef) {
return $self->_data('needs_restart') if !defined $value;
return $self->_data('needs_restart',$value);
}

Expand All @@ -5689,7 +5707,7 @@ sub _post_change_hardware($self, $hardware, $index, $data=undef) {
}
$self->info(Ravada::Utils->user_daemon) if $self->is_known();

$self->needs_restart(1) if $self->is_known && $self->_data('status') eq 'active' && $hardware ne 'memory';
$self->needs_restart(1) if $self->is_known && $self->_data('status') eq 'active' && $hardware ne 'memory' && $hardware !~ /cpu/;
$self->post_prepare_base() if $self->is_base();
}

Expand Down
Loading

0 comments on commit 47df3fe

Please sign in to comment.