Commit 1f91c259 authored by Francesc Guasch's avatar Francesc Guasch Committed by frankiejol
Browse files

feat(frontend): show network interfaces hw address (#1539)

issue #1534
parent ed88578b
......@@ -1910,7 +1910,7 @@ sub _upgrade_tables {
$self->_upgrade_table('domains','status','varchar(32) DEFAULT "shutdown"');
$self->_upgrade_table('domains','display','text');
#$self->_upgrade_table('domains','display_file','text DEFAULT NULL');
$self->_upgrade_table('domains','info','varchar(255) DEFAULT NULL');
$self->_upgrade_table('domains','info','TEXT DEFAULT NULL');
$self->_upgrade_table('domains','internal_id','varchar(64) DEFAULT NULL');
$self->_upgrade_table('domains','volatile_clones','int NOT NULL default 0');
$self->_upgrade_table('domains','comment',"varchar(80) DEFAULT ''");
......
......@@ -1545,7 +1545,16 @@ sub get_info {
$info->{cpu_time} = $info->{cpuTime};
$info->{n_virt_cpu} = $info->{nrVirtCpu};
confess Dumper($info) if !$info->{n_virt_cpu};
$info->{ip} = $self->ip() if $self->is_active();
if ( $self->is_active() ) {
$info->{ip} = $self->ip();
my @interfaces;
eval { @interfaces = $self->domain->get_interface_addresses(Sys::Virt::Domain::INTERFACE_ADDRESSES_SRC_LEASE) };
my @interfaces2;
eval { @interfaces2 = $self->domain->get_interface_addresses(Sys::Virt::Domain::INTERFACE_ADDRESSES_SRC_AGENT) };
@interfaces = @interfaces2 if !scalar(@interfaces);
$info->{interfaces} = \@interfaces;
}
lock_keys(%$info);
return $info;
......
......@@ -668,6 +668,13 @@ sub get_info {
return $info;
}
sub _new_mac($mac='ff:54:00:a7:49:71') {
my $num =sprintf "%02X", rand(0xff);
my @macparts = split/:/,$mac;
$macparts[5] = $num;
return join(":",@macparts);
}
sub _set_default_info($self, $listen_ip=undef) {
my $info = {
max_mem => 512*1024
......@@ -676,6 +683,7 @@ sub _set_default_info($self, $listen_ip=undef) {
,n_virt_cpu => 1
,state => 'UNKNOWN'
,ip =>'1.1.1.'.int(rand(254)+1)
,mac => _new_mac()
,time => time
};
$self->_store(info => $info);
......@@ -686,6 +694,10 @@ sub _set_default_info($self, $listen_ip=undef) {
next if $name eq 'disk' || $name eq 'display';
$self->set_controller($name, 1) unless exists $hardware->{$name}->[0];
}
$info->{interfaces}->[0] = {
hwaddress => $info->{mac}
,address => $info->{ip}
};
return $info;
}
......
......@@ -700,6 +700,32 @@ sub _iptables_save($vm,$table=undef,$chain=undef) {
return @out;
}
sub test_interfaces($vm) {
my $domain = $BASE->clone(name => new_domain_name, user => user_admin);
$domain->start( remote_ip => '10.1.1.2', user => user_admin);
_wait_ip2($vm, $domain);
my $info = $domain->info(user_admin);
my $domain_f = Ravada::Front::Domain->open($domain->id);
my $info_f = $domain_f->info(user_admin);
ok(exists $info_f->{ip},"Expecting ip in front domain info");
is($info_f->{ip}, $domain->ip);
ok($info_f->{interfaces},"Expecting interfaces on ".$domain->_vm->type)
and isa_ok($info_f->{interfaces},"ARRAY","Expecting mac address is a list")
and do {
my $found = 0;
for my $if (@{$info_f->{interfaces}}) {
$found++;
like($if->{hwaddr}, qr/^[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]/);
}
ok($found,"Expecting some interfaces, found=$found") or exit;
};
$domain->remove(user_admin);
}
sub test_redirect_ip_duplicated($vm) {
diag("Test redirect ip duplicated ".$vm->type);
my $internal_port = 22;
......@@ -901,7 +927,12 @@ sub test_clone_exports_add_ports($vm) {
}
sub _wait_ip2($vm_name, $domain) {
<<<<<<< HEAD
for ( 1 .. 30 ) {
=======
$domain->start(user => user_admin, remote_ip => '1.2.3.5') unless $domain->is_active();
for ( 1 .. 22 ) {
>>>>>>> bfcb8f0a... feat(frontend): show network interfaces hw address (#1539)
return $domain->ip if $domain->ip;
diag("Waiting for ".$domain->name. " ip") if !(time % 10);
sleep 1;
......@@ -1312,6 +1343,8 @@ for my $vm_name ( vm_names() ) {
flush_rules() if !$<;
import_base($vm);
test_interfaces($vm);
test_redirect_ip_duplicated($vm);
test_open_port_duplicated($vm);
test_close_port($vm);
......
......@@ -38,6 +38,7 @@
<li><b>Internal IP:</b><span ng-show="domain.ip"> {{domain.ip}}</span>
<span ng-hide="domain.ip"><i>waiting for network to come up</i></span>
</li>
<li ng-show="domain.interfaces"><b>Hardware address</b> {{domain.interfaces[0].hwaddr}} </li>
<li><b>Max Memory:</b> {{domain.max_mem}}</li>
<li><b>Memory:</b> {{domain.memory}}</li>
<li><b>CPUs:</b> {{domain.nrVirtCpu}}</li>
......
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