Commit 506b62bf authored by Francesc Guasch's avatar Francesc Guasch
Browse files

Merge branch 'master' of https://github.com/UPC/ravada

parents 32df3c8b feebf32b
......@@ -3383,6 +3383,15 @@ sub _cmd_list_isos($self, $request){
$request->output(encode_json(\@isos));
}
sub _cmd_set_time($self, $request) {
my $id_domain = $request->args('id_domain');
my $domain = Ravada::Domain->open($id_domain)
or confess "Error: domain $id_domain not found";
return if !$domain->is_active;
eval { $domain->set_time() };
die "$@ , retry.\n" if $@;
}
sub _clean_requests($self, $command, $request=undef, $status='requested') {
my $query = "DELETE FROM requests "
." WHERE command=? "
......@@ -3645,6 +3654,7 @@ sub _req_method {
,add_hardware => \&_cmd_add_hardware
,remove_hardware => \&_cmd_remove_hardware
,change_hardware => \&_cmd_change_hardware
,set_time => \&_cmd_set_time
# Domain ports
,expose => \&_cmd_expose
......
......@@ -59,6 +59,7 @@ requires 'resume';
requires 'rename';
requires 'dettach';
requires 'set_time';
#storage
requires 'add_volume';
......@@ -1848,7 +1849,10 @@ sub is_locked {
$self->_init_connector() if !defined $$CONNECTOR;
my $sth = $$CONNECTOR->dbh->prepare("SELECT id,at_time FROM requests "
." WHERE id_domain=? AND status <> 'done'");
." WHERE id_domain=? AND status <> 'done'"
." AND command <> 'open_iptables' "
." AND command <> 'set_time'"
);
$sth->execute($self->id);
my ($id, $at_time) = $sth->fetchrow;
$sth->finish;
......@@ -2963,6 +2967,10 @@ sub _post_start {
$self->display_file($arg{user});
$self->info($arg{user});
}
Ravada::Request->set_time(uid => Ravada::Utils::user_daemon->id
, id_domain => $self->id
, retry => 10
);
Ravada::Request->enforce_limits(at => time + 60);
Ravada::Request->manage_pools(
uid => Ravada::Utils::user_daemon->id
......@@ -4264,7 +4272,7 @@ sub _run_netstat($self, $force=undef) {
&& ( time - $self->_vm->{_netstat_time} < $TIME_CACHE_NETSTAT+1 ) ) {
return $self->_vm->{_netstat};
}
my @cmd = ("/bin/netstat", "-tan");
my @cmd = ("/bin/ss", "-tn","-o","state","established");
my ( $out, $err) = $self->_vm->run_command(@cmd);
$self->_vm->{_netstat} = $out;
$self->_vm->{_netstat_time} = time;
......@@ -4281,8 +4289,8 @@ sub _client_connection_status($self, $force=undef) {
my @out = split(/\n/,$netstat_out);
for my $line (@out) {
my @netstat_info = split(/\s+/,$line);
if ( $netstat_info[3] eq $ip.":".$port ) {
return 'connected' if $netstat_info[5] eq 'ESTABLISHED';
if ( $netstat_info[2] eq $ip.":".$port ) {
return 'connected';
}
}
return 'disconnected';
......
......@@ -562,14 +562,15 @@ sub _post_remove_base_domain {
sub post_resume_aux($self) {
my $time = time();
eval {
$self->domain->set_time($time, 0, 0);
$self->set_time();
};
if ($@) {
$@='' if $@ !~ /libvirt error code: 86 /;
die $@ if $@;
}
die "$@\n" if $@ && $@ !~ /libvirt error code: 86,/;
}
sub set_time($self) {
my $time = time();
$self->domain->set_time($time, 0, 0);
}
=head2 display_info
......
......@@ -499,6 +499,7 @@ sub _set_default_info($self, $listen_ip=undef) {
,n_virt_cpu => 1
,state => 'UNKNOWN'
,ip =>'1.1.1.'.int(rand(254)+1)
,time => time
};
$self->_store(info => $info);
$self->_set_display($listen_ip);
......@@ -510,6 +511,10 @@ sub _set_default_info($self, $listen_ip=undef) {
return $info;
}
sub set_time($self) {
$self->_set_info(time => time );
}
sub set_max_memory {
my $self = shift;
my $value = shift;
......
......@@ -193,4 +193,10 @@ sub _get_controller_disk($self) {
return map { $_->info } $self->list_volumes_info();
}
sub set_time($self) {
Ravada::Request->set_time(uid => Ravada::Utils::user_daemon->id
, id_domain => $self->id
, retry => 10
);
}
1;
......@@ -97,6 +97,7 @@ our %VALID_ARG = (
,enforce_limits => { timeout => 2, _force => 2 }
,refresh_machine => { id_domain => 1, uid => 1 }
,rebase => { uid => 1, id_base => 1, id_domain => 1 }
,set_time => { uid => 1, id_domain => 1 }
# ports
,expose => { uid => 1, id_domain => 1, port => 1, name => 2, restricted => 2, id_port => 2}
,remove_expose => { uid => 1, id_domain => 1, port => 1}
......
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