Skip to content

Commit

Permalink
Merge branch 'main' into feat/book_hd
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejol committed Apr 26, 2024
2 parents 3c3550b + df781a0 commit b393a6a
Show file tree
Hide file tree
Showing 12 changed files with 298 additions and 24 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@

**Bugfixes**

- Node Option Not Available [\#2032]

**Refactors**
27 changes: 27 additions & 0 deletions deb/debianize.pl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use Carp qw(confess);
use Cwd qw(getcwd);
use Data::Dumper;
use File::Path qw(remove_tree make_path);
use IPC::Run3;
use lib './lib';
Expand Down Expand Up @@ -93,6 +94,32 @@ sub remove_not_needed {
die "Missing $path" if ! -e $path;
remove_tree($path);
}
remove_custom_files("public/js/custom");
}

sub remove_custom_files {
my $dir = shift;
opendir my $ls,$dir or die "$! $dir";
while ( my $file = readdir $ls) {
next if $file =~ m/^\.+$/;
my $path = "$dir/$file";
if ( -d $path ) {
die "Error: no dirs should be in $dir";
} elsif ( -f $path ) {
if ($file !~ /insert_here/) {
my ($dir_dst, $component) = $dir =~ m{(.*)/(.*)};
die "Unknown dir $dir " if !exists $DIR{$dir_dst};
my $deb_path = "$DIR_DST/$DIR{$dir_dst}/$component/$file";
if (! -e $deb_path ) {
($component) = $dir =~ m{.*/(\w+/\w+)};
$deb_path = "$DIR_DST/$DIR{$dir_dst}/$component/$file";
}
unlink $deb_path or die "$! $deb_path";
}
} else {
warn "Warning: unknown file type $file (neither file nor dir)";
}
}
}

sub create_md5sums {
Expand Down
5 changes: 5 additions & 0 deletions etc/rvd_front.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@
,file => '/var/log/ravada/rvd_front.log'
,level => 'debug'
}
,status => {
allowed => [
'127.0.0.1'
]
}
};
29 changes: 15 additions & 14 deletions lib/Ravada.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package Ravada;
use warnings;
use strict;

our $VERSION = '2.2.0';
our $VERSION = '2.2.1';

use utf8;

Expand Down Expand Up @@ -463,19 +463,7 @@ sub _update_isos {
,arch => 'x86_64'
}

,serena64 => {
name => 'Mint 18.1 Mate 64 bits'
,description => 'Mint Serena 18.1 with Mate Desktop based on Ubuntu Xenial 64 bits'
,arch => 'x86_64'
,xml => 'xenial64-amd64.xml'
,xml_volume => 'xenial64-volume.xml'
,url => 'https://mirrors.edge.kernel.org/linuxmint/stable/18.3'
,file_re => 'linuxmint-18.3-mate-64bit.iso'
,md5_url => ''
,md5 => 'c5cf5c5d568e2dfeaf705cfa82996d93'
,min_disk_size => '10'

}

,mint20_64 => {
name => 'Mint 20 Mate 64 bits'
,description => 'Mint Ulyana 20 with Mate Desktop 64 bits'
Expand Down Expand Up @@ -1477,6 +1465,8 @@ sub _remove_old_isos {

,"DELETE FROM iso_images "
." WHERE name like 'Alpine%3.8%'"
,"DELETE FROM iso_images "
." WHERE name like 'Mint 18.1 Mate 64 bits'"
) {
my $sth = $CONNECTOR->dbh->prepare($sql);
$sth->execute();
Expand Down Expand Up @@ -2753,6 +2743,17 @@ sub _sql_insert_defaults($self){
,name => 'time'
,value => '21:00'
}
,{
id_parent => '/backend'
,name => 'limits'
,value => undef
}
,{
id_parent => '/backend/limits'
,name => 'startup_ram'
,value => 1
}


]
);
Expand Down
4 changes: 4 additions & 0 deletions lib/Ravada/Domain.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,8 @@ sub _check_has_clones {
sub _check_free_vm_memory {
my $self = shift;

return if !Ravada::Front::setting(undef,"/backend/limits/startup_ram");

my $vm_free_mem = $self->_vm->free_memory;

my $domain_memory = $self->info(Ravada::Utils::user_daemon)->{memory};
Expand Down Expand Up @@ -2977,6 +2979,7 @@ sub _copy_clone($self, %args) {
$id_owner = $user->id if (! $id_owner);
my $alias = delete $args{alias};
my $options = delete $args{options};
my $start = delete $args{start};

confess "ERROR: Unknown arguments ".join(",",sort keys %args)
if keys %args;
Expand All @@ -2988,6 +2991,7 @@ sub _copy_clone($self, %args) {
push @copy_arg, ( memory => $memory ) if $memory;
push @copy_arg, ( volatile => $volatile ) if $volatile;
push @copy_arg, ( options => $options ) if $options;
push @copy_arg, ( start => $start ) if $start;

$request->status("working","Copying domain ".$self->name
." to $name") if $request;
Expand Down
2 changes: 1 addition & 1 deletion lib/Ravada/Domain/KVM.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3659,7 +3659,7 @@ sub reload_config($self, $doc) {
$new_domain = $self->_vm->vm->define_domain($doc->toString);
};

cluck ''.$@ if $@;
die ''.$@ if $@;

$self->domain($new_domain);

Expand Down
4 changes: 2 additions & 2 deletions lib/Ravada/VM/Void.pm
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,9 @@ sub list_routes {

sub list_virtual_networks($self) {

my $dir_net = $self->dir_img."/networks/";
my $dir_net = $self->dir_img."/networks";
if (!$self->file_exists($dir_net)) {
my ($out, $err) = $self->run_command("mkdir", $dir_net);
my ($out, $err) = $self->run_command("mkdir","-p", $dir_net);
die $err if $err;
}
my @files = $self->list_files($dir_net,qr/.yml$/);
Expand Down
5 changes: 4 additions & 1 deletion public/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ ravadaApp.directive("solShowMachine", swMach)
$scope.set_autostart= function(machineId, value) {
$http.get("/machine/autostart/"+machineId+"/"+value);
};
$scope.set_public = function(machineId, value) {
$scope.set_public = function(machineId, value, show_clones) {
if (value) value=1;
else value = 0;
$http.get("/machine/public/"+machineId+"/"+value)
Expand All @@ -509,6 +509,9 @@ ravadaApp.directive("solShowMachine", swMach)
}
});

if ( value == 0 ) {
$http.get("/machine/set/"+machineId+"/show_clones/"+show_clones);
}
};

$scope.can_remove_base = function(machine) {
Expand Down
81 changes: 80 additions & 1 deletion script/rvd_front
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ hook before_routes => sub {
|| $url =~ m{^/fallback/font}
;

return if $url =~ m{^/(anonymous_logout|login|logout|requirements|robots.txt|favicon.ico)};
return if $url =~ m{^/(anonymous_logout|login|logout|requirements|robots.txt|favicon.ico|status\.)};

my $bases_anonymous = $RAVADA->list_bases_anonymous(_remote_ip($c));
return access_denied($c) if $url =~ m{^/anonymous} && !@$bases_anonymous;
Expand Down Expand Up @@ -3080,6 +3080,85 @@ get '/host_devices/templates/list/(#id_vm)' => sub($c) {

};

sub _request_recent() {
my @now = localtime(time);
$now[4]++;
for ( 1 .. 4 ){
$now[$_] = "0".$now[$_] if length ($now[$_])<2
}
my $now = "".($now[5]+1900)."-$now[4]-$now[3] $now[2]:$now[1]";
$now[1]--;
my $now2 = "".($now[5]+1900)."-$now[4]-$now[3] $now[2]:$now[1]";
my $sth = $RAVADA->_dbh->prepare(
"SELECT date_changed,status,command FROM requests ORDER BY date_changed DESC LIMIT 10"
);
$sth->execute();
my $n = 100;
while (my ($date_changed, $status, $command) = $sth->fetchrow ) {
next if $status !~ /working|done/;
return 1 if $date_changed =~ /^($now|$now2)/;
last if $n--<0;
}
return 0;
}

sub _ping_backend() {
return 1 if _request_recent();

my $req = Ravada::Request->ping_backend();
$RAVADA->wait_request($req, 10);
if ($req->status eq 'done' && !$req->error) {
return 1;
}
return 0;
}

get '/status.(#type)'=> sub($c) {
my $remote_ip = _remote_ip($c);

my %allowed = ('127.0.0.1' => 1);
if (exists $CONFIG_FRONT->{status} && $CONFIG_FRONT->{status}->{allowed}) {
if (ref($CONFIG_FRONT->{status}->{allowed}) eq 'ARRAY') {
for my $ip ( @{$CONFIG_FRONT->{status}->{allowed}} ) {
warn $ip;
$allowed{$ip}++;
}
} else {
$allowed{$CONFIG_FRONT->{status}->{allowed}}++;
}
}
return access_denied($c) unless $allowed{$remote_ip};
my $backend = _ping_backend();
if ($backend) {
$backend='true';
} else {
$backend='false';
}
my $status = { backend => $backend, frontend => 'true' };
my $sth = $RAVADA->_dbh->prepare("SELECT name,is_active "
." FROM vms "
." ORDER BY 'name'"
);
$sth->execute;

my $sth_active = $RAVADA->_dbh->prepare("SELECT count(*) "
." FROM domains "
." WHERE status='active' AND id_vm=? "
);
while ( my $row = $sth->fetchrow_hashref) {
$sth_active->execute($row->{id});
$row->{vms}=$sth_active->fetchrow;
if ($row->{is_active}) {
$row->{status} = 'active';
} else {
$row->{status} = 'disabled';
}
delete $row->{is_active};
push@{$status->{nodes}},($row);
}
return $c->render(json => $status);
};

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

sub _init_error {
Expand Down
4 changes: 0 additions & 4 deletions t/device/10_templates.t
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ sub _mangle_dom_hd_void($domain) {
$config->{hardware}->{host_devices}->[0]->{vendor_id} = $new_id;
$domain->_store(hardware => $config->{hardware});

warn $device_name;
$sth = connector->dbh->prepare("UPDATE host_devices_domain set name=?"
." WHERE id=?");
$sth->execute($device_name, $id_hd);
Expand Down Expand Up @@ -805,11 +804,8 @@ sub test_templates($vm) {

_fix_host_device($host_device) if $vm->type eq 'KVM';

warn 11;
test_hd_in_domain($vm, $host_device);
warn 12;
test_hd_dettach($vm, $host_device);
warn 13;

my $req = Ravada::Request->list_host_devices(
uid => user_admin->id
Expand Down
Loading

0 comments on commit b393a6a

Please sign in to comment.