Commit 473769c1 authored by joansp's avatar joansp
Browse files

BE mqtt working

parent f4c6956b
...@@ -278,6 +278,7 @@ sub remove_domain { ...@@ -278,6 +278,7 @@ sub remove_domain {
my $user = Ravada::Auth::SQL->search_by_id( $arg{uid}); my $user = Ravada::Auth::SQL->search_by_id( $arg{uid});
$domain->remove( $user); $domain->remove( $user);
} }
=head2 search_domain =head2 search_domain
...@@ -663,8 +664,11 @@ sub _cmd_screenshot { ...@@ -663,8 +664,11 @@ sub _cmd_screenshot {
$bytes = $domain->screenshot($request->args('filename')) if !$bytes; $bytes = $domain->screenshot($request->args('filename')) if !$bytes;
} }
$request->error("No data received") if !$bytes; $request->error("No data received") if !$bytes;
$request->status('done'); my $msg = 'Domain '
.$domain->name
.' screenshot done.'
;
$request->status('done',$msg);
} }
...@@ -771,7 +775,11 @@ sub _cmd_remove { ...@@ -771,7 +775,11 @@ sub _cmd_remove {
if !defined $request->args->{uid}; if !defined $request->args->{uid};
$self->remove_domain(name => $request->args('name'), uid => $request->args('uid')); $self->remove_domain(name => $request->args('name'), uid => $request->args('uid'));
my $msg = 'Domain '
.$request->args('name')
.' removed.'
;
$request->status('done',$msg);
} }
sub _cmd_pause { sub _cmd_pause {
...@@ -787,8 +795,11 @@ sub _cmd_pause { ...@@ -787,8 +795,11 @@ sub _cmd_pause {
my $user = Ravada::Auth::SQL->search_by_id($uid); my $user = Ravada::Auth::SQL->search_by_id($uid);
$domain->pause($user); $domain->pause($user);
my $msg = 'Domain '
$request->status('done'); .$domain->name
.' paused.'
;
$request->status('done',$msg);
} }
...@@ -805,8 +816,11 @@ sub _cmd_resume { ...@@ -805,8 +816,11 @@ sub _cmd_resume {
my $user = Ravada::Auth::SQL->search_by_id($uid); my $user = Ravada::Auth::SQL->search_by_id($uid);
$domain->resume($user); $domain->resume($user);
my $msg = 'Domain '
$request->status('done'); .$domain->name
.' resumed.'
;
$request->status('done',$msg);
} }
...@@ -849,7 +863,11 @@ sub _cmd_prepare_base { ...@@ -849,7 +863,11 @@ sub _cmd_prepare_base {
die "Unknown domain id '$id_domain'\n" if !$domain; die "Unknown domain id '$id_domain'\n" if !$domain;
$domain->prepare_base($user); $domain->prepare_base($user);
my $msg = 'Prepare base on domain '
.$domain->name
.' done.'
;
$request->status('done',$msg);
} }
sub _cmd_remove_base { sub _cmd_remove_base {
...@@ -867,7 +885,11 @@ sub _cmd_remove_base { ...@@ -867,7 +885,11 @@ sub _cmd_remove_base {
die "Unknown domain id '$id_domain'\n" if !$domain; die "Unknown domain id '$id_domain'\n" if !$domain;
$domain->remove_base($user); $domain->remove_base($user);
my $msg = 'Domain'
.$domain->name
.' base removed.'
;
$request->status('done',$msg);
} }
...@@ -889,7 +911,11 @@ sub _cmd_shutdown { ...@@ -889,7 +911,11 @@ sub _cmd_shutdown {
$domain->shutdown(timeout => $timeout, name => $name, user => $user $domain->shutdown(timeout => $timeout, name => $name, user => $user
, request => $request); , request => $request);
my $msg = 'Domain '
.$domain->name
.' shutdown.'
;
$request->status('done',$msg);
} }
sub _cmd_list_vm_types { sub _cmd_list_vm_types {
......
...@@ -9,6 +9,7 @@ use JSON::XS; ...@@ -9,6 +9,7 @@ use JSON::XS;
use Hash::Util; use Hash::Util;
use Ravada; use Ravada;
use Ravada::Front; use Ravada::Front;
use AnyEvent::MQTT;
use vars qw($AUTOLOAD); use vars qw($AUTOLOAD);
...@@ -266,7 +267,7 @@ sub shutdown_domain { ...@@ -266,7 +267,7 @@ sub shutdown_domain {
my $self = {}; my $self = {};
bless($self,$class); bless($self,$class);
return $self->_new_request(command => 'shutdown' , args => encode_json($args)); return $self->_new_request(command => 'shutdown' , args => encode_json($args));
} }
...@@ -289,7 +290,7 @@ sub prepare_base { ...@@ -289,7 +290,7 @@ sub prepare_base {
my $self = {}; my $self = {};
bless($self,$class); bless($self,$class);
return $self->_new_request(command => 'prepare_base' return $self->_new_request(command => 'prepare_base'
, id_domain => $args{id_domain} , id_domain => $args{id_domain}
, args => encode_json( $args )); , args => encode_json( $args ));
...@@ -319,7 +320,7 @@ sub remove_base { ...@@ -319,7 +320,7 @@ sub remove_base {
my $self = {}; my $self = {};
bless($self,$class); bless($self,$class);
return $self->_new_request(command => 'remove_base' return $self->_new_request(command => 'remove_base'
, id_domain => $args{id_domain} , id_domain => $args{id_domain}
, args => encode_json( $args )); , args => encode_json( $args ));
...@@ -467,6 +468,16 @@ sub _send_message { ...@@ -467,6 +468,16 @@ sub _send_message {
my $status = shift; my $status = shift;
my $message = ( shift or $self->error ); my $message = ( shift or $self->error );
$self->_send_message_db($status,$message);
$self->_send_message_mqtt($status,$message);
}
sub _send_message_db {
my $self = shift;
my $status = shift;
my $message = ( shift or $self->error );
my $uid; my $uid;
eval { $uid = $self->args('id_owner') }; eval { $uid = $self->args('id_owner') };
...@@ -484,9 +495,41 @@ sub _send_message { ...@@ -484,9 +495,41 @@ sub _send_message {
"INSERT INTO messages ( id_user, id_request, subject, message ) " "INSERT INTO messages ( id_user, id_request, subject, message ) "
." VALUES ( ?,?,?,?)" ." VALUES ( ?,?,?,?)"
); );
$sth->execute($uid, $self->id,"Command ".$self->command." $domain_name".$self->status $sth->execute($uid, $self->id,"Command ".$self->command." $domain_name".$self->status
,$message); ,$message);
$sth->finish; $sth->finish;
}
sub _send_message_mqtt {
my $self = shift;
my $status = shift;
my $message = ( shift or $self->error );
my $uid;
eval { $uid = $self->args('id_owner') };
eval { $uid = $self->args('uid') } if !$uid;
return if !$uid;
my $domain_name;
eval { $domain_name = $self->args('name') };
$domain_name = '' if !$domain_name;
$domain_name = "$domain_name " if length $domain_name;
$self->_remove_unnecessary_messages() if $self->status eq 'done';
my $mqtt = AnyEvent::MQTT->new(host=>'127.0.0.1');
my $cv = $mqtt->subscribe(topic => "/rvd/$uid",
callback => sub {
my ($uid, $message) = @_;
});
$cv = $mqtt->publish(message => "$message", topic => "/rvd/$uid");
$cv->recv;
} }
sub _remove_unnecessary_messages { sub _remove_unnecessary_messages {
......
...@@ -21,9 +21,9 @@ ...@@ -21,9 +21,9 @@
<a data-toggle="modal" data-target="#modal{{machine.id}}" title="Manage VM">{{machine.name}}</a> <a data-toggle="modal" data-target="#modal{{machine.id}}" title="Manage VM">{{machine.name}}</a>
</td> </td>
<td> <td>
<i ng-show="machine.is_base" class="fa fa-check" aria-hidden="true"></i> <i ng-show="{{machine.is_base}}" class="fa fa-check" aria-hidden="true"></i>
<a ng-hide="machine.is_base" ng-click="prepare(machine.id)" href="" title="Prepare base"><i class="fa fa-times" aria-hidden="true"></i></a> <a ng-hide="{{machine.is_base}}" ng-click="prepare(machine.id)" href="" title="Prepare base"><i class="fa fa-times" aria-hidden="true"></i></a>
</td> </td>
<td> <td>
<a ng-show="list_machines[$index].is_active" ng-click="shutdown(machine.id)"><i class="fa fa-check" aria-hidden="true"></i></a> <a ng-show="list_machines[$index].is_active" ng-click="shutdown(machine.id)"><i class="fa fa-check" aria-hidden="true"></i></a>
......
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/1.1.0/angular-material.min.js"> <script src="https://ajax.googleapis.com/ajax/libs/angular_material/1.1.0/angular-material.min.js">
<script src="/js/form.js"></script> <script src="/js/form.js"></script>
<script src="/js/ravada.js"></script> <script src="/js/ravada.js"></script>
<script type="text/javascript"> <script type="text/javascript">
function show(iD) { function show(iD) {
document.getElementById("spinn"+iD).style.display="block"; document.getElementById("spinn"+iD).style.display="block";
......
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