Unverified Commit 60af6eff authored by Francesc Guasch's avatar Francesc Guasch Committed by GitHub
Browse files

Fix ip NAT (#1678)

fix(networking): choose NAT IP first

* try first IP from agent

close  #1672
parent 7dc7abbf
...@@ -3512,10 +3512,15 @@ sub open_exposed_ports($self) { ...@@ -3512,10 +3512,15 @@ sub open_exposed_ports($self) {
return if !@ports; return if !@ports;
return if !$self->is_active; return if !$self->is_active;
if ( ! $self->ip ) { my $ip = $self->ip;
if ( ! $ip ) {
die "Error: No ip in domain ".$self->name.". Retry.\n"; die "Error: No ip in domain ".$self->name.". Retry.\n";
} }
if (!$self->_vm->_is_ip_nat($ip)) {
die "Error: No NAT ip in domain ".$self->name." found. Retry.\n";
}
$self->display_info(Ravada::Utils::user_daemon); $self->display_info(Ravada::Utils::user_daemon);
for my $expose ( @ports ) { for my $expose ( @ports ) {
$self->_open_exposed_port($expose->{internal_port}, $expose->{name} $self->_open_exposed_port($expose->{internal_port}, $expose->{name}
......
...@@ -1644,7 +1644,7 @@ sub _ip_agent($self) { ...@@ -1644,7 +1644,7 @@ sub _ip_agent($self) {
$found = $addr->{addr} if !$found; $found = $addr->{addr} if !$found;
return $addr->{addr} return $addr->{addr}
if $self->_vm->_is_ip_bridged($addr->{addr}); if $self->_vm->_is_ip_nat($addr->{addr});
} }
} }
return $found; return $found;
...@@ -1659,6 +1659,9 @@ sub _ip_agent($self) { ...@@ -1659,6 +1659,9 @@ sub _ip_agent($self) {
#} #}
sub ip($self) { sub ip($self) {
my ($ip) = $self->_ip_agent();
return $ip if $ip;
my @ip; my @ip;
eval { @ip = $self->domain->get_interface_addresses(Sys::Virt::Domain::INTERFACE_ADDRESSES_SRC_LEASE) }; eval { @ip = $self->domain->get_interface_addresses(Sys::Virt::Domain::INTERFACE_ADDRESSES_SRC_LEASE) };
warn $@ if $@; warn $@ if $@;
...@@ -1667,8 +1670,7 @@ sub ip($self) { ...@@ -1667,8 +1670,7 @@ sub ip($self) {
# @ip = $self->_ip_arp(); # @ip = $self->_ip_arp();
# return $ip[0]->{addrs}->[0]->{addr} if $ip[0]; # return $ip[0]->{addrs}->[0]->{addr} if $ip[0];
return $self->_ip_agent(); return;
} }
=head2 set_max_mem =head2 set_max_mem
......
...@@ -2573,7 +2573,7 @@ sub list_machine_types($self) { ...@@ -2573,7 +2573,7 @@ sub list_machine_types($self) {
return %ret_types; return %ret_types;
} }
sub _is_ip_bridged($self, $ip0) { sub _is_ip_nat($self, $ip0) {
my $ip = NetAddr::IP->new($ip0); my $ip = NetAddr::IP->new($ip0);
for my $net ( $self->vm->list_networks ) { for my $net ( $self->vm->list_networks ) {
my $xml = XML::LibXML->load_xml(string my $xml = XML::LibXML->load_xml(string
......
...@@ -422,6 +422,10 @@ sub file_exists( $self, $file ) { ...@@ -422,6 +422,10 @@ sub file_exists( $self, $file ) {
return 0; return 0;
} }
sub _is_ip_nat($self, $ip) {
return 1;
}
#########################################################################3 #########################################################################3
1; 1;
...@@ -15,16 +15,16 @@ use feature qw(signatures); ...@@ -15,16 +15,16 @@ use feature qw(signatures);
######################################################################## ########################################################################
sub test_bridge($vm) { sub test_nat($vm) {
for my $net ( $vm->vm->list_all_networks ) { for my $net ( $vm->vm->list_all_networks ) {
my $xml = XML::LibXML->load_xml(string my $xml = XML::LibXML->load_xml(string
=> $net->get_xml_description()); => $net->get_xml_description());
my ($xml_ip) = $xml->findnodes("/network/ip"); my ($xml_ip) = $xml->findnodes("/network/ip");
my $address = $xml_ip->getAttribute('address'); my $address = $xml_ip->getAttribute('address');
$address =~ s/\.\d+$/.4/; $address =~ s/\.\d+$/.4/;
is($vm->_is_ip_bridged($address),1); is($vm->_is_ip_nat($address),1);
} }
is($vm->_is_ip_bridged("127.0.0.1"),0); is($vm->_is_ip_nat("127.0.0.1"),0);
} }
######################################################################## ########################################################################
...@@ -44,7 +44,8 @@ for my $vm_name ( 'KVM' ) { ...@@ -44,7 +44,8 @@ for my $vm_name ( 'KVM' ) {
diag($msg) if !$vm; diag($msg) if !$vm;
skip $msg,10 if !$vm; skip $msg,10 if !$vm;
test_bridge($vm); test_nat($vm);
} }
} }
......
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