Commit e33db069 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

fix(display): listen depends on remote ip

Try to the detect the interface where the remote IP
comes from, and listen properly on that.

issue #1099
parent 0f0dde6c
......@@ -2462,8 +2462,8 @@ sub _post_start {
$self->display($arg{user});
$self->display_file($arg{user});
$self->info($arg{user});
$self->open_exposed_ports();
}
$self->open_exposed_ports();
Ravada::Request->enforce_limits(at => time + 60);
$self->post_resume_aux;
}
......
......@@ -49,11 +49,11 @@ sub display_info {
return $display_data;
}
sub _set_display($self, $remote_ip=undef) {
sub _set_display($self, $listen_ip=$self->_vm->listen_ip) {
$listen_ip=$self->_vm->listen_ip if !$listen_ip;
# my $ip = ($self->_vm->nat_ip or $self->_vm->ip());
my $ip = $self->_vm->listen_ip($remote_ip);
my $display="void://$ip:5990/";
my $display_data = { display => $display , type => 'void', ip => $ip, port => 5990 };
my $display="void://$listen_ip:5990/";
my $display_data = { display => $display , type => 'void', ip => $listen_ip, port => 5990 };
$self->_store( display => $display_data );
return $display_data;
}
......@@ -215,9 +215,16 @@ sub shutdown_now {
sub start($self, @args) {
my %args;
%args = @args if scalar(@args) % 2 == 0;
my $listen_ip = delete $args{listen_ip};
my $remote_ip = delete $args{remote_ip};
my $user = delete $args{user};
delete $args{'id_vm'};
confess "Error: unknown args ".Dumper(\%args) if keys %args;
$listen_ip = $self->_vm->listen_ip($remote_ip) if !$listen_ip;
$self->_store(is_active => 1);
$self->_set_display( $remote_ip );
$self->_set_display( $listen_ip );
}
sub prepare_base {
......@@ -481,8 +488,7 @@ sub get_info {
return $info;
}
sub _set_default_info {
my $self = shift;
sub _set_default_info($self, $listen_ip=undef) {
my $info = {
max_mem => 512*1024
,memory => 512*1024,
......@@ -492,6 +498,7 @@ sub _set_default_info {
,ip =>'1.1.1.'.int(rand(254)+1)
};
$self->_store(info => $info);
$self->_set_display($listen_ip);
my %controllers = $self->list_controllers;
for my $name ( sort keys %controllers) {
next if $name eq 'disk';
......
......@@ -607,10 +607,12 @@ sub _interface_ip($self, $remote_ip=undef) {
}
sub listen_ip($self, $remote_ip=undef) {
return Ravada::display_ip() if Ravada::display_ip();
return $self->_interface_ip($remote_ip) if $remote_ip;
return (Ravada::display_ip()
or $self->public_ip
return (
$self->public_ip
or $self->ip()
);
}
......
......@@ -80,6 +80,8 @@ sub create_domain {
my $volatile = delete $args{volatile};
my $active = ( delete $args{active} or $volatile or $user->is_temporary or 0);
my $listen_ip = delete $args{listen_ip};
confess if $args{name} eq 'tst_vm_v20_volatile_clones_02' && !$listen_ip;
my $domain = Ravada::Domain::Void->new(
%args
, domain => $args{name}
......@@ -89,7 +91,7 @@ sub create_domain {
"-e ".$domain->_config_file." && echo 1" );
chomp $out;
die "Error: Domain $args{name} already exists " if $out;
$domain->_set_default_info();
$domain->_set_default_info($listen_ip);
$domain->_store( autostart => 0 );
$domain->_store( is_active => $active );
$domain->set_memory($args{memory}) if $args{memory};
......@@ -136,7 +138,7 @@ sub create_domain {
, target => 'hdc'
);
$domain->_set_default_drivers();
$domain->_set_default_info();
$domain->_set_default_info($listen_ip);
$domain->_store( is_active => 0 );
$domain->_store( is_active => 1 ) if $volatile || $user->is_temporary;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment