Commit 7e99faeb authored by Francesc Guasch's avatar Francesc Guasch
Browse files

Merge branch 'main' into refactor/table_domains_kvm2

parents 736c50a4 13cdb11d
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at ravada@telecos.upc.edu. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
Welcome to the Ravada community
Grant and accept constructive critique within desired privacy to resolve problems.
Contact the project team at ravada@telecos.upc.edu if unable.
......@@ -4462,6 +4462,7 @@ sub _cmd_prepare_base {
die "Unknown domain id '$id_domain'\n" if !$domain;
$self->_remove_unnecessary_request($domain);
$self->_remove_unnecessary_downs($domain);
$domain->prepare_base(user => $user, with_cd => $with_cd);
......@@ -4642,6 +4643,7 @@ sub _cmd_shutdown {
);
my $user = Ravada::Auth::SQL->search_by_id( $uid);
$self->_remove_unnecessary_request($domain);
$domain->shutdown(timeout => $timeout, user => $user
, request => $request);
......@@ -4667,6 +4669,7 @@ sub _cmd_force_shutdown {
my $user = Ravada::Auth::SQL->search_by_id( $uid);
die "Error: unknown user id=$uid in request= ".$request->id if !$user;
$self->_remove_unnecessary_request($domain);
$domain->force_shutdown($user,$request);
}
......@@ -4708,6 +4711,7 @@ sub _cmd_reboot {
);
my $user = Ravada::Auth::SQL->search_by_id( $uid);
$self->_remove_unnecessary_request($domain);
$domain->reboot(timeout => $timeout, user => $user
, request => $request);
......@@ -4732,6 +4736,7 @@ sub _cmd_force_reboot {
my $user = Ravada::Auth::SQL->search_by_id( $uid);
$self->_remove_unnecessary_request($domain);
$domain->force_reboot($user,$request);
}
......@@ -5413,13 +5418,24 @@ sub _refresh_down_domains($self, $active_domain, $active_vm) {
}
}
sub _remove_unnecessary_request($self, $domain, $command = ['set_time', 'open_exposed_ports']) {
$command = [$command] if !ref($command);
my %remove = map { $_ => 1 } @$command;
my @requests = $domain->list_requests(1);
for my $req (@requests) {
$req->status('done') if $remove{$req->command};
$req->_remove_messages();
}
}
sub _remove_unnecessary_downs($self, $domain) {
my @requests = $domain->list_requests(1);
my $uid_daemon = Ravada::Utils::user_daemon->id();
for my $req (@requests) {
$req->status('done') if $req->command =~ /shutdown/
&& (!$req->at_time || $req->defined_arg('uid') == $uid_daemon );
$req->status('done')
if $req->command =~ /shutdown/ && (!$req->at_time || $req->at_time <= time+180);
$req->_remove_messages();
}
}
......
......@@ -4381,7 +4381,6 @@ Returns a hashref of the hardware controllers for this virtual machine
=cut
sub get_controllers($self) {
my $info;
my %controllers = $self->list_controllers();
......@@ -5414,7 +5413,31 @@ sub _post_change_hardware($self, $hardware, $index, $data=undef) {
$self->needs_restart(1) if $self->is_known && $self->_data('status') eq 'active';
}
sub _fix_hw_booleans($data) {
for my $key (keys %$data) {
next if !ref($data->{$key});
if (ref($data->{$key}) eq 'HASH') {
_fix_hw_booleans($data->{$key});
} elsif(ref($data->{$key}) eq 'JSON::PP::Boolean') {
$data->{$key} = ''.$data->{$key};
} else {
confess "Error: expecting scalar or hash or boolean "
.Dumper($data);
}
}
}
sub _fix_hw_ignore_fields($data) {
for my $key (keys %$data) {
delete $data->{$key} if $key =~ /^_/;
}
}
sub _around_change_hardware($orig, $self, $hardware, $index=undef, $data=undef) {
_fix_hw_booleans($data);
_fix_hw_ignore_fields($data);
my $real_id_vm;
if ($hardware eq 'disk' && !$self->_vm->is_local) {
$real_id_vm = $self->_vm->id;
......
......@@ -62,6 +62,7 @@ our %SET_DRIVER_SUB = (
,playback => \&_set_driver_playback
,streaming => \&_set_driver_streaming
,disk => \&_set_driver_disk
,cpu => \&_set_driver_cpu
);
our %GET_CONTROLLER_SUB = (
......@@ -2176,6 +2177,10 @@ sub _set_driver_disk($self, $value) {
return $self->change_hardware('disk',0,{driver => $value });
}
sub _set_driver_cpu($self, $value) {
return $self->change_hardware('cpu',0,{cpu => { mode => $value}});
}
sub set_controller($self, $name, $number=undef, $data=undef) {
my $sub = $SET_CONTROLLER_SUB{$name};
die "I can't get controller $name for domain ".$self->name
......@@ -2628,12 +2633,20 @@ sub change_hardware($self, $hardware, @args) {
return $sub->($self, @args);
}
sub _fix_hw_disk_args($data) {
for (qw( allocation backing bus device driver_cache driver_name driver_type name target type )) {
delete $data->{$_};
}
}
sub _change_hardware_disk($self, $index, $data) {
my @volumes = $self->list_volumes_info();
confess "Error: Unknown volume $index, only ".(scalar(@volumes)-1)." found"
.Dumper(\@volumes)
if $index>=scalar(@volumes);
_fix_hw_disk_args($data);
my $driver = delete $data->{driver};
my $boot = delete $data->{boot};
......@@ -2775,6 +2788,14 @@ sub _fix_hw_video_args($data) {
}
delete $data->{acceleration} unless $driver eq 'virtio';
if (exists $data->{primary}) {
if ($data->{primary}) {
$data->{primary} = 'yes'
} else {
delete $data->{primary};
}
}
}
sub _change_hardware_features($self, $index, $data) {
......@@ -2791,6 +2812,10 @@ sub _change_hardware_features($self, $index, $data) {
my ($features) = $doc->findnodes('/domain/features');
if (!$features) {
my ($domain) = $doc->findnodes("/domain");
$features = $domain->addNewChild(undef,'features');
}
for my $field (keys %$data) {
next if $field =~ /^_/;
my ($item) = $features->findnodes($field);
......@@ -2842,15 +2867,15 @@ sub _change_hardware_cpu($self, $index, $data) {
$data = $self->_default_cpu()
if !keys %$data;
lock_hash(%$data);
delete $data->{cpu}->{model}->{'$$hashKey'};
lock_hash(%$data);
my $doc = XML::LibXML->load_xml(string => $self->xml_description);
my $count = 0;
my $changed = 0;
my ($n_vcpu) = $doc->findnodes('/domain/vcpu/text()');
if ($n_vcpu ne $data->{vcpu}->{_text}) {
if (exists $data->{vcpu} && $n_vcpu ne $data->{vcpu}->{_text}) {
my ($vcpu) = $doc->findnodes('/domain/vcpu');
$vcpu->removeChildNodes();
$vcpu->appendText($data->{vcpu}->{_text});
......@@ -2905,8 +2930,13 @@ sub _change_hardware_sound($self, $index, $data) {
}
sub _change_hardware_video($self, $index, $data) {
confess "Error: nothing to change ".Dumper($data)
if !keys %$data;
if (!keys %$data) {
$data = { 'type' => 'qxl'
,'ram' => 65536
,'vram' => 65536
,'heads' => 1
};
}
_fix_hw_video_args($data);
......@@ -2934,6 +2964,10 @@ sub _change_hardware_video($self, $index, $data) {
_remove_acceleration($model);
$model->setAttribute('primary' => 'yes');
}
if ($field eq 'primary' && $data->{$field}) {
_remove_all_video_primary($devices);
$changed++;
}
$model->setAttribute($field,$data->{$field});
$changed++;
if ($field eq 'type' && $data->{$field} ne 'qxl') {
......@@ -2975,10 +3009,18 @@ sub _change_xml($xml, $name, $data) {
}
sub _change_hardware_network($self, $index, $data) {
confess if !defined $index;
die "Error: index number si required.\n" if !defined $index;
my $doc = XML::LibXML->load_xml(string => $self->xml_description);
if (!keys %$data) {
$data = {
driver => 'virtio'
,type => 'nat'
,network => 'default'
}
}
my $type = delete $data->{type};
my $driver = lc(delete $data->{driver} or '');
my $bridge = delete $data->{bridge};
......@@ -2991,10 +3033,10 @@ sub _change_hardware_network($self, $index, $data) {
die "Error: Unknown type '$type' . Known: bridge, NAT"
if $type && $type !~ /^(bridge|nat)$/;
die "Error: Bridged type requires bridge ".Dumper($data)
die "Error: Bridged type requires bridge.\n"
if $type && $type eq 'bridge' && !$bridge;
die "Error: NAT type requires network ".Dumper($data)
die "Error: NAT type requires network.\n"
if $type && $type eq 'nat' && !$network;
$type = 'network' if $type && $type eq 'nat';
......
......@@ -14,10 +14,10 @@ use feature qw(signatures);
our %GET_CONTROLLER_SUB = (
usb => \&_get_controller_usb
,'0cpu' => \&_get_controller_cpu
,'cpu' => \&_get_controller_cpu
,disk => \&_get_controller_disk
,display => \&_get_controller_display
,'1features' => \&_get_controller_features
,'features' => \&_get_controller_features
,network => \&_get_controller_network
,video => \&_get_controller_video
,sound => \&_get_controller_sound
......@@ -34,6 +34,7 @@ our %GET_DRIVER_SUB = (
,streaming => \&_get_driver_streaming
,disk => \&_get_driver_disk
,display => \&_get_driver_display
,cpu => \&_get_driver_cpu
);
......@@ -79,6 +80,7 @@ sub _get_controller_video($self) {
}
$item->{_name} = $name;
_xml_elements($model,$item);
$item->{_primary} = $item->{primary} if exists $item->{primary} && $item->{primary};
lock_hash(%$item);
push @ret,($item);
}
......@@ -127,14 +129,20 @@ sub _get_controller_cpu($self) {
}
sub _get_controller_features($self) {
my $doc = XML::LibXML->load_xml(string => $self->_data_extra('xml'));
die "Error: no xml found for ".$self->name
if !$doc;
my $item = {
_name => 'features'
,_order => 1
};
my ($xml) = $doc->findnodes("/domain/features");
_xml_elements($xml, $item);
_xml_elements($xml, $item) if $xml;
for my $feat (sort qw(acpi pae apic hap kvm vmport)) {
$item->{$feat} = 0 if !exists $item->{$feat};
......@@ -146,6 +154,7 @@ sub _get_controller_features($self) {
sub _xml_elements($xml, $item) {
confess if !defined $xml;
my $text = $xml->textContent;
$item->{_text} = $text if $text && $text !~ /\n/m;
......@@ -186,7 +195,7 @@ sub _get_controller_network($self) {
$count++;
push @ret,({
type => $type
,name => $name
,_name => $name
,driver => $model->getAttribute('type')
,bridge => $source->getAttribute('bridge')
,network => $source->getAttribute('network')
......@@ -249,6 +258,10 @@ sub _get_driver_generic($self,$xml_path,$attribute=undef) {
return @ret;
}
sub _get_driver_cpu($self) {
return $self->_get_driver_generic('/domain/cpu','mode');
}
sub _get_driver_graphics {
my $self = shift;
my $xml_path = shift;
......
......@@ -988,6 +988,12 @@ msgstr "Conserveu el CD per als clons"
msgid "Accept"
msgstr "Acceptar"
msgid "Close"
msgstr "Tancar"
msgid "Apply"
msgstr "Aplicar"
msgid "Fail"
msgstr "Falla"
......
......@@ -941,6 +941,12 @@ msgstr "Keep the CD for the clones"
msgid "Accept"
msgstr "Accept"
msgid "Close"
msgstr "Close"
msgid "Apply"
msgstr "Apply"
msgid "Fail"
msgstr "Fail"
......
......@@ -312,7 +312,7 @@ msgid "Password"
msgstr "Contraseña"
msgid "Start session"
msgstr "Iniciar sesión\n"
msgstr "Iniciar sesión"
msgid "bits) in your computer."
msgstr "bits) en tu ordenador."
......
......@@ -401,10 +401,17 @@ sub _old_info($self, $key, $new_count=undef, $new_changed=undef) {
return ($old_count, $old_changed);
}
sub _date_changed_table($self, $table) {
sub _date_changed_table($self, $table, $id) {
my $rvd = $self->ravada;
my $sth = $rvd->_dbh->prepare("SELECT MAX(date_changed) FROM $table");
$sth->execute;
my $sth;
if (defined $id) {
$sth = $rvd->_dbh->prepare("SELECT MAX(date_changed) FROM $table "
." WHERE id=?");
$sth->execute($id);
} else {
$sth = $rvd->_dbh->prepare("SELECT MAX(date_changed) FROM $table");
$sth->execute;
}
my ($date) = $sth->fetchrow;
return ($date or '');
}
......@@ -420,7 +427,9 @@ sub _count_table($self, $table) {
sub _new_info($self, $key) {
my $channel = $self->clients->{$key}->{channel};
$channel =~ s{/.*}{};
$channel =~ s{/(.*)}{};
my $id;
$id = $1 if defined $1;
my $table0 = $TABLE_CHANNEL{$channel} or return;
if (!ref($table0)) {
......@@ -435,7 +444,7 @@ sub _new_info($self, $key) {
$count .= $self->_count_table($table);
$date .= ":" if $date;
$date .= $self->_date_changed_table($table)
$date .= $self->_date_changed_table($table, $id);
}
return ($count, $date);
......@@ -446,16 +455,17 @@ sub _send_answer($self, $ws_client, $channel, $key = $ws_client) {
my $exec = $SUB{$channel} or die "Error: unknown channel $channel";
my $old_ret;
if (!defined $TIME0{$channel} || time < $TIME0{$channel}+60) {
if (defined $TIME0{$channel} && time < $TIME0{$channel}+60) {
my ($old_count, $old_changed) = $self->_old_info($key);
my ($new_count, $new_changed) = $self->_new_info($key);
$old_ret = $self->clients->{$key}->{ret};
return $old_ret if defined $new_count && defined $new_changed
&& $old_count eq $new_count && $old_changed eq $new_changed;
$self->_old_info($key, $new_count, $new_changed);
$old_ret = $self->clients->{$key}->{ret};
}
$TIME0{$channel} = time;
......@@ -466,12 +476,14 @@ sub _send_answer($self, $ws_client, $channel, $key = $ws_client) {
if ( defined $ret && _different($ret, $old_ret )) {
warn "WS: send $channel" if $DEBUG;
$ws_client->send( { json => $ret } );
warn localtime(time)." WS: send $channel " if $DEBUG;
$ws_client->send( {json => $ret} );
$self->clients->{$key}->{ret} = $ret;
}
$self->unsubscribe($key) if $channel eq 'ping_backend' && $ret eq 2;
$self->unsubscribe($key) if !$ret;
if (!$ret) {
$self->unsubscribe($key);
}
}
sub subscribe($self, %args) {
......
......@@ -446,5 +446,10 @@ ul.alert-dropdown {
span.loading {
color: darkgray;
text-width: italic;
font-style: italic;
}
span.info {
color: darkgray;
font-style: italic;
}
'use strict';
var ravadaApp = angular.module("ravada.app",['ngResource','ngSanitize','ravada.booking'])
.config( [
'$compileProvider',
......@@ -32,8 +30,6 @@
.controller("notifCrtl", notifCrtl)
.controller("run_domain_req",run_domain_req_ctrl)
function newMachineCtrl($scope, $http) {
$http.get('/list_images.json').then(function(response) {
......@@ -246,7 +242,8 @@
$scope.timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
$scope.exec_time_start = new Date();
$scope.exec_time = new Date();
$scope.edit = 0;
$scope.edit = "";
$scope.lock_info = false;
$scope.getUnixTimeFromDate = function(date) {
date = (date instanceof Date) ? date : date ? new Date(date) : new Date();
......@@ -256,23 +253,32 @@
$scope.isPastTime = function(date, now_date) {
return $scope.getUnixTimeFromDate(date) < $scope.getUnixTimeFromDate(now_date ? now_date : new Date());
};
$scope.toggle_edit = function(item) {
if (!item._edit) {
item._edit = true;
$scope.edit++;
$scope.set_edit=function(name,index) {
if(!name) {
$scope.edit = '';
} else {
item._edit = false;
$scope.edit--;
$scope.edit = name+index;
$scope.lock_info = true;
}
}
$scope.edit = 0;
};
$scope.toggle_edit=function(name,index) {
if(!name || $scope.edit == name+index) {
$scope.edit = '';
} else {
$scope.edit = name+index;
$scope.lock_info = true;
}
};
$scope.is_edit = function(name,index) {
return $scope.edit == name+index;
};
var subscribed_extra = false;
var subscribe_machine_info= function(url) {
var ws = new WebSocket(url);
ws.onopen = function(event) { ws.send('machine_info/'+$scope.showmachineId) };
ws.onmessage = function(event) {
if ($scope.edit) return;
var data = JSON.parse(event.data);
if (data === null || typeof(data) == undefined ) {
ws.close();
......@@ -280,6 +286,16 @@
return;
}
$scope.$apply(function () {
if ($scope.lock_info) {
$scope.showmachine.requests = data.requests;
return;
}
$scope.hardware = Object.keys(data.hardware);
$scope.hardware.sort(function(a,b) {
if( a == 'features' && b != 'cpu') return -1;
if( b == 'features' && b != 'cpu') return 1;
return a >b;
});
$scope.showmachine = data;
$scope.copy_is_volatile = $scope.showmachine.is_volatile;
if (!subscribed_extra) {
......@@ -287,6 +303,7 @@
subscribe_nodes(url,data.type);
//subscribe_bases(url);
}
if ($scope.edit) { $scope.lock_info = true }
});
_select_new_base();
}
......@@ -615,7 +632,7 @@
//On load code
// $scope.showmachineId = window.location.pathname.split("/")[3].split(".")[0] || -1 ;
$scope.add_hardware = function(hardware, number, extra) {
$scope.add_hardware = function(hardware, extra) {
if (hardware == 'disk' && ! extra) {
$scope.show_new_disk = true;
return;
......@@ -635,7 +652,6 @@
$scope.request('add_hardware'
, { 'id_domain': $scope.showmachine.id
,'name': hardware
,'number': number
,'data': extra
})
};
......@@ -658,7 +674,6 @@
}