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

BE mqtt working

parent f4c6956b
......@@ -278,6 +278,7 @@ sub remove_domain {
my $user = Ravada::Auth::SQL->search_by_id( $arg{uid});
$domain->remove( $user);
}
=head2 search_domain
......@@ -663,8 +664,11 @@ sub _cmd_screenshot {
$bytes = $domain->screenshot($request->args('filename')) 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 {
if !defined $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 {
......@@ -787,8 +795,11 @@ sub _cmd_pause {
my $user = Ravada::Auth::SQL->search_by_id($uid);
$domain->pause($user);
$request->status('done');
my $msg = 'Domain '
.$domain->name
.' paused.'
;
$request->status('done',$msg);
}
......@@ -805,8 +816,11 @@ sub _cmd_resume {
my $user = Ravada::Auth::SQL->search_by_id($uid);
$domain->resume($user);
$request->status('done');
my $msg = 'Domain '
.$domain->name
.' resumed.'
;
$request->status('done',$msg);
}
......@@ -849,7 +863,11 @@ sub _cmd_prepare_base {
die "Unknown domain id '$id_domain'\n" if !$domain;
$domain->prepare_base($user);
my $msg = 'Prepare base on domain '
.$domain->name
.' done.'
;
$request->status('done',$msg);
}
sub _cmd_remove_base {
......@@ -867,7 +885,11 @@ sub _cmd_remove_base {
die "Unknown domain id '$id_domain'\n" if !$domain;
$domain->remove_base($user);
my $msg = 'Domain'
.$domain->name
.' base removed.'
;
$request->status('done',$msg);
}
......@@ -889,7 +911,11 @@ sub _cmd_shutdown {
$domain->shutdown(timeout => $timeout, name => $name, user => $user
, request => $request);
my $msg = 'Domain '
.$domain->name
.' shutdown.'
;
$request->status('done',$msg);
}
sub _cmd_list_vm_types {
......
......@@ -9,6 +9,7 @@ use JSON::XS;
use Hash::Util;
use Ravada;
use Ravada::Front;
use AnyEvent::MQTT;
use vars qw($AUTOLOAD);
......@@ -266,7 +267,7 @@ sub shutdown_domain {
my $self = {};
bless($self,$class);
return $self->_new_request(command => 'shutdown' , args => encode_json($args));
}
......@@ -289,7 +290,7 @@ sub prepare_base {
my $self = {};
bless($self,$class);
return $self->_new_request(command => 'prepare_base'
, id_domain => $args{id_domain}
, args => encode_json( $args ));
......@@ -319,7 +320,7 @@ sub remove_base {
my $self = {};
bless($self,$class);
return $self->_new_request(command => 'remove_base'
, id_domain => $args{id_domain}
, args => encode_json( $args ));
......@@ -467,6 +468,16 @@ sub _send_message {
my $status = shift;
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;
eval { $uid = $self->args('id_owner') };
......@@ -484,9 +495,41 @@ sub _send_message {
"INSERT INTO messages ( id_user, id_request, subject, message ) "
." VALUES ( ?,?,?,?)"
);
$sth->execute($uid, $self->id,"Command ".$self->command." $domain_name".$self->status
,$message);
$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 {
......
......@@ -21,9 +21,9 @@
<a data-toggle="modal" data-target="#modal{{machine.id}}" title="Manage VM">{{machine.name}}</a>
</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>
<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 @@
<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/ravada.js"></script>
<script type="text/javascript">
function show(iD) {
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