Commit 987395e9 authored by joansp's avatar joansp
Browse files

PING BE and Remove Base

parent 098f5a3f
......@@ -74,7 +74,7 @@ sub BUILD {
}
if ( $self->connector ) {
$CONNECTOR = $self->connector
$CONNECTOR = $self->connector
} else {
$CONNECTOR = $self->_connect_dbh();
$self->connector($CONNECTOR);
......@@ -101,7 +101,7 @@ Returns the default display IP read from the config file
sub display_ip {
my $ip = $CONFIG->{display_ip};
return $ip if $ip;
}
......@@ -207,13 +207,13 @@ sub _check_vms {
Creates a new domain based on an ISO image or another domain.
my $domain = $ravada->create_domain(
my $domain = $ravada->create_domain(
name => $name
, id_iso => 1
);
my $domain = $ravada->create_domain(
my $domain = $ravada->create_domain(
name => $name
, id_base => 3
);
......@@ -380,11 +380,11 @@ sub list_domains_data {
# eval { $domain->id };
# warn $@ if $@;
# next if $@;
# push @domains, { id => $domain->id
# push @domains, { id => $domain->id
# , name => $domain->name
# ,is_base => $domain->is_base
# ,is_active => $domain->is_active
# }
# }
# return \@domains;
......@@ -553,11 +553,11 @@ sub process_requests {
if ($err && $err =~ /libvirt error code: 38/) {
if ( $n_retry < 3) {
warn $req->id." ".$req->command." to retry" if $DEBUG;
$req->status("retry ".++$n_retry)
$req->status("retry ".++$n_retry)
}
}
warn "req ".$req->id." , command: ".$req->command." , status: ".$req->status()
." , error: '".($req->error or 'NONE')."'"
." , error: '".($req->error or 'NONE')."'"
if $DEBUG || $debug;
}
......@@ -578,7 +578,7 @@ Returnsa list ofthe types of Virtual Machines available on this system
sub list_vm_types {
my $self = shift;
my %type;
for my $vm (@{$self->vm}) {
my ($name) = ref($vm) =~ /.*::(.*)/;
......@@ -598,7 +598,7 @@ sub _execute {
if !$sub;
if ($dont_fork || !$CAN_FORK ) {
eval { $sub->($self,$request) };
my $err = ($@ or '');
$request->error($err);
......@@ -610,7 +610,7 @@ sub _execute {
die "I can't fork" if !defined $pid;
if ($pid == 0) {
$request->status("forked $$");
eval {
eval {
$sub->($self,$request);
};
my $err = ( $@ or '');
......
......@@ -25,7 +25,7 @@ our $args_manage = { name => 1 , uid => 1 };
our $args_prepare = { id_domain => 1 , uid => 1 };
our %VALID_ARG = (
create_domain => {
create_domain => {
vm => 1
,name => 1
,id_iso => 1
......@@ -234,7 +234,7 @@ sub _check_args {
my $valid_args = $VALID_ARG{$sub};
for (keys %{$args}) {
confess "Invalid argument $_ , valid args ".Dumper($valid_args)
confess "Invalid argument $_ , valid args ".Dumper($valid_args)
if !$valid_args->{$_};
}
......@@ -251,7 +251,7 @@ sub _check_args {
Requests to stop a domain
my $req = Ravada::Request->shutdown_domain( name => 'name' , uid => $user->id );
my $req = Ravada::Request->shutdown_domain( name => 'name' , uid => $user->id
my $req = Ravada::Request->shutdown_domain( name => 'name' , uid => $user->id
,timeout => $timeout );
=cut
......@@ -290,7 +290,7 @@ sub prepare_base {
my $self = {};
bless($self,$class);
return $self->_new_request(command => 'prepare_base'
return $self->_new_request(command => 'prepare_base'
, id_domain => $args{id_domain}
, args => encode_json( $args ));
......@@ -320,7 +320,7 @@ sub remove_base {
my $self = {};
bless($self,$class);
return $self->_new_request(command => 'remove_base'
return $self->_new_request(command => 'remove_base'
, id_domain => $args{id_domain}
, args => encode_json( $args ));
......@@ -638,7 +638,7 @@ sub AUTOLOAD {
my $sth = $$CONNECTOR->dbh->prepare("UPDATE requests set $name=? "
." WHERE id=?");
eval {
eval {
$sth->execute($value, $self->{id});
$sth->finish;
};
......
......@@ -17,10 +17,10 @@
.controller("machines", machinesCrtl)
.controller("messages", messagesCrtl)
.controller("users", usersCrtl)
function newMachineCtrl($scope, $http) {
$http.get('/list_images.json').then(function(response) {
......@@ -84,7 +84,7 @@
$http.get('/pingbackend.json').then(function(response) {
$scope.pingbe = response.data;
});
$scope.shutdown = function(machineId){
......@@ -117,6 +117,11 @@
$http.get(toGet);
};
$scope.removeb = function(machineId){
var toGet = '/machine/remove_b/'+machineId+'.json';
$http.get(toGet);
};
};
function swListMach() {
......@@ -185,7 +190,7 @@
$scope.checkbox = [];
//if it is checked make the user admin, otherwise remove admin
$scope.stateChanged = function(id,userid) {
$scope.stateChanged = function(id,userid) {
if($scope.checkbox[id]) { //if it is checked
$http.get('/users/make_admin/' + userid + '.json')
location.reload();
......@@ -250,4 +255,3 @@
});
};
<div class="panel-body">
<div class="col-lg-12">
<div ng-hide="pingbe" class="alert alert-danger">
<strong>Error!</strong> Backend no available!
</div>
<table class="table table-striped">
<thead>
<tr>
......@@ -8,7 +11,7 @@
<th>Base</th>
<th>Active</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
......@@ -33,7 +36,7 @@
<a ng-show="{{machine.is_base}}" class="btn btn-primary btn-sm" href="/machine/clone/{{machine.id}}.html"><i class="fa fa-files-o" aria-hidden="true"></i>&nbsp Clone</a>
<button type="button" ng-click="screenshot(machine.id)" ng-show="{{machine.is_active}}" class="btn btn-primary btn-sm"><i class="fa fa-camera" aria-hidden="true"></i>&nbspScreenshot</button>
<button type="button" ng-click="shutdown(machine.id)" ng-show="{{machine.is_active}}" class="btn btn-warning btn-sm"></strong><i class="fa fa-power-off" aria-hidden="true"></i>&nbsp ShutDown</button>
......@@ -44,8 +47,8 @@
</tr>
</tbody>
</table>
<div ng-repeat="machine in list_machines">
</table>
<div ng-repeat="machine in list_machines">
<div id="modal{{machine.id}}" class="modal fade" role="dialog">
<div class="modal-dialog">
......@@ -61,7 +64,7 @@
<div style="width:100%; margin-bottom:10px;">
<img src="/img/screenshots/{{machine.id}}.png" width="400" alt="No screenshot available for this machine">
</div>
<div style="width:100%; margin-bottom:10px;">
<a class="btn btn-primary btn-sm" href="/machine/view/{{machine.id}}.html"><i class="fa fa-desktop" aria-hidden="true"></i>&nbsp View</a>
......@@ -70,33 +73,32 @@
<button type="button" ng-click="resume(machine.id)" ng-show="{{machine.is_active && machine.is_paused}}" class="btn btn-success btn-sm"><i class="fa fa-repeat" aria-hidden="true"></i>&nbsp Resume</button>
<button type="button" ng-click="pause(machine.id)" ng-show="{{machine.is_active && !machine.is_paused}}" class="btn btn-success btn-sm"><i class="fa fa-pause" aria-hidden="true"></i>&nbsp Pause</button>
</div>
</div>
<div style="width:100%; margin-bottom:10px;">
<a ng-show="{{machine.is_base}}" class="btn btn-primary btn-sm" href="/machine/clone/{{machine.id}}.html"><i class="fa fa-files-o" aria-hidden="true"></i>&nbsp Clone</a>
<button type="button" ng-click="prepare(machine.id)" ng-hide="{{machine.is_base}}" class="btn btn-primary btn-sm"><i class="fa fa-plus" aria-hidden="true"></i>&nbsp Prepare Base</button>
<button type="button" ng-click="prepare(machine.id)" class="btn btn-primary btn-sm"><i class="fa fa-plus" aria-hidden="true"></i>&nbsp Prepare Base</button>
<button type="button" ng-click="screenshot(machine.id)" ng-show="{{machine.is_active}}" class="btn btn-primary btn-sm"><i class="fa fa-camera" aria-hidden="true"></i>&nbsp Screenshot</button>
<button type="button" ng-click="shutdown(machine.id)" ng-show="{{machine.is_active}}" class="btn btn-warning btn-sm"></strong><i class="fa fa-power-off" aria-hidden="true"></i>&nbsp ShutDown</button>
<button type="button" ng-click="removeb(machine.id)" ng-show="{{machine.is_base}}" class="btn btn-warning btn-sm"><i class="fa fa-trash-o" aria-hidden="true"></i>&nbsp Remove Base</button>
<a class="btn btn-danger btn-sm" href="/machine/remove/{{machine.id}}.html"><strong>&nbsp;<i class="fa fa-trash-o" aria-hidden="true"></i></strong> Delete</a>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
......@@ -228,6 +228,11 @@ get '/machine/prepare/*.json' => sub {
return prepare_machine($c);
};
get '/machine/remove_b/*.json' => sub {
my $c = shift;
return remove_base($c);
};
get '/machine/screenshot/*.json' => sub {
my $c = shift;
return screenshot_machine($c);
......@@ -402,8 +407,8 @@ sub login {
}
}
$c->render(
template => 'bootstrap/start'
,login => $login
template => 'bootstrap/start'
,login => $login
,error => \@error
);
......@@ -438,9 +443,9 @@ sub quick_start {
}
$c->render(
template => 'bootstrap/list_bases'
template => 'bootstrap/list_bases'
,id_base => $id_base
,login => $login
,login => $login
,_anonymous => 0
,error => \@error
);
......@@ -573,12 +578,12 @@ sub _search_req_base_error {
}
sub access_denied {
my $c = shift;
my $msg = 'Access denied to '.$c->req->url->to_abs->path;
$msg .= ' for user '.$USER->name if $USER;
return $c->render(text => $msg);
}
......@@ -611,7 +616,7 @@ sub provision {
if ( $req->status ne 'done' ) {
$c->stash(error_title => "Request ".$req->command." ".$req->status());
$c->stash(error =>
$c->stash(error =>
"Domain provisioning request not finished, status='".$req->status."'.");
$c->stash(link => "/request/".$req->id.".html");
......@@ -620,7 +625,7 @@ sub provision {
}
$domain = $RAVADA->search_domain($name);
if ( $req->error ) {
$c->stash(error => $req->error)
$c->stash(error => $req->error)
} elsif (!$domain) {
$c->stash(error => "I dunno why but no domain $name");
}
......@@ -703,11 +708,11 @@ sub make_admin {
return login($c) if !_logged_in($c);
my ($id) = $c->req->url->to_abs->path =~ m{/(\d+).json};
warn "id usuari $id";
Ravada::Auth::SQL::make_admin($id);
}
sub remove_admin {
......@@ -715,11 +720,11 @@ sub remove_admin {
return login($c) if !_logged_in($c);
my ($id) = $c->req->url->to_abs->path =~ m{/(\d+).json};
warn "id usuari $id";
Ravada::Auth::SQL::remove_admin($id);
}
sub manage_machine {
......@@ -735,7 +740,7 @@ sub manage_machine {
Ravada::Request->shutdown_domain(name => $domain->name, uid => $USER->id) if $c->param('shutdown');
Ravada::Request->start_domain(name => $domain->name, uid => $USER->id) if $c->param('start');
Ravada::Request->pause_domain(name => $domain->name, uid => $USER->id)
Ravada::Request->pause_domain(name => $domain->name, uid => $USER->id)
if $c->param('pause');
Ravada::Request->resume_domain(name => $domain->name, uid => $USER->id) if $c->param('resume');
......@@ -839,6 +844,19 @@ sub remove_machine {
return $c->render( template => 'bootstrap/remove_machine' );
}
sub remove_base {
my $c = shift;
return login($c) if !_logged_in($c);
my $domain = _search_requested_machine($c);
my $req = Ravada::Request->remove_base(
id_domain => $domain->id
,uid => $USER->id
);
$c->render(json => { request => $req->id});
}
sub screenshot_machine {
my $c = shift;
......@@ -990,7 +1008,7 @@ sub _new_anonymous_user {
for my $n ( 4 .. 32 ) {
$name = substr($name_mojo,0,$n);
my $user;
eval {
eval {
$user = Ravada::Auth::SQL->new( name => $name );
$user = undef if !$user->id;
};
......@@ -1010,7 +1028,7 @@ __DATA__
<h1>Welcome to SPICE !</h1>
<form method="post">
User Name: <input name="login" value ="<%= $login %>"
User Name: <input name="login" value ="<%= $login %>"
type="text"><br/>
Password: <input type="password" name="password" value=""><br/>
Base: <select name="id_base">
......@@ -1018,7 +1036,7 @@ __DATA__
<option value="<%= $option %>"><%= $base->{$option} %></option>
% }
</select><br/>
<input type="submit" name="submit" value="launch">
</form>
% if (scalar @$error) {
......@@ -1043,7 +1061,7 @@ __DATA__
% layout 'default';
<h1>Run</h1>
Hi <%= $name %>,
Hi <%= $name %>,
<a href="<%= $url %>">click here</a>
@@ layouts/default.html.ep
......
......@@ -11,8 +11,7 @@
<!--MACHINES SELECTION-->
<div class="page-header" ng-controller="machines">
<div ng-hide="{{pingbe}}" class="alert alert-danger">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<div ng-hide="pingbe" class="alert alert-danger">
<strong>Error!</strong> Backend no available!
</div>
<div class="row">
......
......@@ -8,41 +8,38 @@
<!--BASES AND DOMAINS LIST-->
<div ng-controller="machines">
<div ng-hide="{{pingbe}}" class="alert alert-danger">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<strong>Error!</strong> Backend no available!
</div>
<div class="page-header">
<div class="panel panel-default">
<div class="panel-heading">
<h2>Machines List
<h2>Machines List
<button type="button" style="float: right; margin: 0 0 0 15px;" class="btn btn-success" data-toggle="modal" data-target="#modalNM">New Machine</button>
<a style="float: right; margin: 0 10px;" class="btn btn-info" href="/machines"><i class="fa fa-refresh" aria-hidden="true"></i></A>
</h2>
</div>
<sol-show-listmachines></sol-show-listmachines>
</div>
</div>
<div class="page-header">
<sol-show-machines-notifications><sol-show-machines-notifications>
<sol-show-machines-notifications><sol-show-machines-notifications>
</div>
</div>
<div id="modalNM" class="modal fade" role="dialog" ng-controller="new_machine">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<sol-show-newmachine></sol-show-newmachine>
</div>
</div>
......@@ -51,7 +48,7 @@
</div>
</div>
%= include 'bootstrap/scripts'
</body>
</html>
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