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

[#33] implementing display ip for Void VM

parent 0ea44ef9
......@@ -11,6 +11,9 @@ use Moose;
use POSIX qw(WNOHANG);
use YAML;
use Socket qw( inet_aton inet_ntoa );
use Sys::Hostname;
use Ravada::Auth;
use Ravada::Request;
use Ravada::VM::KVM;
......@@ -90,6 +93,30 @@ sub _connect_dbh {
}
sub display_ip {
my $ip = $CONFIG->{display_ip};
return $ip if $ip;
my $name = hostname() or die "CRITICAL: I can't find the hostname.\n";
$ip = inet_ntoa(inet_aton($name))
or die "CRITICAL: I can't find IP of $name in the DNS.\n";
if (!$ip || $ip =~ /^127./) {
#TODO Net:DNS
$ip= `host $name`;
chomp $ip;
$ip =~ s/.*?address (\d+)/$1/;
}
if ( !$ip || $ip =~ /^127./ || $ip !~ /^\d+\..*\.\d+$/) {
warn "WARNING: I can't find IP with hostname $name ( $ip )"
.", using localhost\n";
$ip='127.0.0.1';
}
return $ip;
}
sub _init_config {
my $file = shift;
......
......@@ -92,7 +92,7 @@ after 'remove_base' => \&_remove_base_db;
sub _preconditions{
_allow_manage(@_);
_check_free_memory();
# _check_free_memory();
}
sub _allow_manage_args {
......
......@@ -39,7 +39,10 @@ sub name {
};
sub display {
return 'void://hostname:000/';
my $self = shift;
my $ip = (Ravada::display_ip() or '127.0.0.1');
return "void://$ip:0000/";
}
sub is_active {
......
......@@ -27,6 +27,8 @@ my @ARG_RVD = ( config => $FILE_CONFIG, connector => $test->connector);
my @VMS = reverse keys %ARG_CREATE_DOM;
my $USER = create_user("foo","bar");
my $DISPLAY_IP = '99.1.99.1';
#######################################################################33
sub test_create_domain {
......@@ -71,6 +73,23 @@ sub test_files_base {
return;
}
sub test_display {
my ($vm_name, $domain) = @_;
my $display = $domain->display($USER);
my ($ip) = $display =~ m{^\w+://(.*):\d+};
ok($ip,"Expecting an IP from $display, got none") or return;
ok($ip ne '127.0.0.1', "Expecting IP no '127.0.0.1', got '$ip'");
my $expected_ip = $RAVADA::CONFIG->{display_ip} or die "Missing display_ip in ravada.conf";
ok($ip eq $expected_ip,"Expecting display IP '$expected_ip', got '$ip'");
warn "[$vm_name] ".$domain->name." $display";
}
sub test_prepare_base {
my $vm_name = shift;
my $domain = shift;
......@@ -100,6 +119,8 @@ sub test_prepare_base {
my $name_clone = new_domain_name();
$RAVADA::CONFIG->{display_ip} = $DISPLAY_IP;
my $domain_clone = $RVD_BACK->create_domain(
name => $name_clone
,id_owner => $USER->id
......@@ -108,6 +129,8 @@ sub test_prepare_base {
);
ok($domain_clone);
test_devices_clone($vm_name, $domain_clone);
test_display($vm_name, $domain_clone);
ok($domain_clone->id_base && $domain_clone->id_base == $domain->id
,"[$vm_name] Expecting id_base=".$domain->id." got ".($domain_clone->id_base or '<UNDEF>')) or exit;
......
Markdown is supported
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