Commit e6b4607e authored by Roberto P. Rubio's avatar Roberto P. Rubio
Browse files

Añade boton force-reboot

parent 5b4ee92b
......@@ -3504,6 +3504,30 @@ sub _cmd_reboot {
}
sub _cmd_force_reboot {
my $self = shift;
my $request = shift;
my $uid = $request->args('uid');
my $id_domain = $request->args('id_domain');
my $id_vm = $request->defined_arg('id_vm');
my $domain;
if ($id_vm) {
my $vm = Ravada::VM->open($id_vm);
$domain = $vm->search_domain_by_id($id_domain);
} else {
$domain = $self->search_domain_by_id($id_domain);
}
die "Unknown domain '$id_domain'\n" if !$domain;
my $user = Ravada::Auth::SQL->search_by_id( $uid);
$domain->force_reboot($user,$request);
}
sub _cmd_list_vm_types {
my $self = shift;
my $request = shift;
......@@ -4087,6 +4111,7 @@ sub _req_method {
,list_vm_types => \&_cmd_list_vm_types
,enforce_limits => \&_cmd_enforce_limits
,force_shutdown => \&_cmd_force_shutdown
,force_reboot => \&_cmd_force_reboot
,rebase => \&_cmd_rebase
,refresh_storage => \&_cmd_refresh_storage
......
......@@ -57,6 +57,8 @@ requires 'force_shutdown';
requires '_do_force_shutdown';
requires 'reboot';
requires 'reboot_now';
requires 'force_reboot';
requires '_do_force_reboot';
requires 'pause';
requires 'resume';
......@@ -185,10 +187,11 @@ after 'shutdown' => \&_post_shutdown;
around 'shutdown_now' => \&_around_shutdown_now;
around 'force_shutdown' => \&_around_shutdown_now;
before 'reboot' => \&_pre_shutdown;
after 'reboot' => \&_post_shutdown;
before 'reboot' => \&_allow_shutdown;
after 'reboot' => \&_post_reboot;
around 'reboot_now' => \&_around_reboot_now;
around 'force_reboot' => \&_around_reboot_now;
before 'remove_base' => \&_pre_remove_base;
after 'remove_base' => \&_post_remove_base;
......@@ -2510,6 +2513,13 @@ sub _post_shutdown {
&& !$is_active;
}
sub _post_reboot {
my $self = shift;
$self->_data(status => 'rebooted');
$self->_remove_iptables();
$self->_close_exposed_port();
}
sub _around_is_active($orig, $self) {
if (!$self->_vm) {
......@@ -2565,7 +2575,19 @@ sub _around_shutdown_now {
$self->_post_shutdown(user => $user) if $self->is_known();
}
sub _around_reboot_now { _around_shutdown_now(@_); }
sub _around_reboot_now {
my $orig = shift;
my $self = shift;
my $user = shift;
$self->_vm->connect;
$self->list_disks;
$self->_pre_shutdown(user => $user);
if ($self->is_active) {
$self->$orig($user);
}
$self->_post_shutdown(user => $user) if $self->is_known();
}
sub _around_name($orig,$self) {
return $self->{_name} if $self->{_name};
......@@ -3102,6 +3124,11 @@ sub _timeout_shutdown($self, $value) {
return $TIMEOUT_SHUTDOWN;
}
sub _timeout_reboot($self, $value) {
$TIMEOUT_REBOOT = $value if defined $value;
return $TIMEOUT_REBOOT;
}
sub _post_start {
my $self = shift;
my %arg;
......
......@@ -871,19 +871,28 @@ sub reboot {
return;
}
return $self->_do_force_shutdown() if $args{force};
return $self->_do_reboot();
}
sub force_reboot {
my $self = shift;
return $self->_do_force_reboot() if $self->is_active;
}
sub _do_force_reboot {
my $self = shift;
return if !$self->domain->is_active;
eval { $self->domain->reset() };
warn $@ if $@;
}
sub _do_reboot {
my $self = shift;
warn "_do_reboot";
warn "RET" and
return if !$self->domain->is_active;
eval { $self->domain->reboot() };
warn ">>> $@";
die $@ if $@;
}
=head2 reboot_now
......
......@@ -239,6 +239,15 @@ sub reboot {
$self->_store(is_active => 0);
}
sub force_reboot {
return reboot_now(@_);
}
sub _do_force_reboot {
my $self = shift;
return $self->_store(is_active => 0);
}
sub reboot_now {
my $self = shift;
my $user = shift;
......
......@@ -932,6 +932,7 @@ sub list_requests($self, $id_domain_req=undef, $seconds=60) {
|| $command eq 'manage_pools'
;
next if ( $command eq 'force_shutdown'
|| $command eq 'force_reboot'
|| $command eq 'start'
|| $command eq 'shutdown'
|| $command eq 'reboot'
......
......@@ -67,6 +67,7 @@ sub open($self, $id) {
sub autostart($self ) { return $self->_data('autostart') }
sub _do_force_shutdown { confess "TODO" }
sub _do_force_reboot { confess "TODO" }
sub add_volume { confess "TODO" }
sub remove_volume { confess "TODO" }
sub clean_swap_volumes { confess "TODO" }
......@@ -91,6 +92,8 @@ sub display_file_tls($self, $user) {
sub force_shutdown { confess "TODO" }
sub force_reboot { confess "TODO" }
sub get_info($self) {
my $info = $self->_data('info');
return {} if !$info;
......
......@@ -68,6 +68,7 @@ our %VALID_ARG = (
,force_shutdown_domain => { id_domain => 1, uid => 1, at => 2, id_vm => 2 }
,reboot_domain => { name => 2, id_domain => 2, uid => 1, timeout => 2, at => 2
, id_vm => 2 }
,force_reboot_domain => { id_domain => 1, uid => 1, at => 2, id_vm => 2 }
,screenshot => { id_domain => 1 }
,domain_autostart => { id_domain => 1 , uid => 1, value => 2 }
,copy_screenshot => { id_domain => 1 }
......@@ -498,6 +499,26 @@ sub shutdown_domain {
return $self->_new_request(command => 'shutdown' , args => $args);
}
=head2 force_reboot_domain
Requests to stop a domain now !
my $req = Ravada::Request->force_reboot_domain( name => 'name' , uid => $user->id );
=cut
sub force_reboot_domain {
my $proto = shift;
my $class=ref($proto) || $proto;
my $args = _check_args('force_reboot_domain', @_ );
my $self = {};
bless($self,$class);
return $self->_new_request(command => 'force_reboot' , args => $args);
}
=head2 reboot_domain
Requests to reboot a domain
......
......@@ -2226,7 +2226,8 @@ sub reboot_machine {
my ($domain, $type) = _search_requested_machine($c);
my $req;
$req = Ravada::Request->reboot_domain(id_domain => $domain->id, uid => $USER->id);
$req = Ravada::Request->force_reboot_domain(id_domain => $domain->id, uid => $USER->id) if ($c->param('force'));;
$req = Ravada::Request->reboot_domain(id_domain => $domain->id, uid => $USER->id) unless ($c->param('force'));;
return $c->redirect_to('/machines') if $type eq 'html';
return $c->render(json => { req => $req->id });
......
<div class="nav flex-column nav-pills bg-light" id="v-pills-tab" role="tablist" aria-orientation="vertical">
% if (($USER->can_change_settings($domain->id)) && !$domain->is_base) {
<a class="nav-link" id="v-pills-actions-tab" ng-click="refresh_machine()" href="#v-pills-actions" data-toggle="pill" role="tab" aria-controls="v-pills-icons" aria-selected="true"><%=l 'Actions' %></a>
% }
% if ($USER->can_change_settings($domain->id)) {
<a class="nav-link active" id="v-pills-description-tab" ng-click="refresh_machine()" href="#v-pills-description" data-toggle="pill" role="tab" aria-controls="v-pills-description" aria-selected="true"><%=l 'Description' %></a>
% }
% if (($USER->can_change_settings($domain->id)) && !$domain->is_base) {
<a class="nav-link" id="v-pills-actions-tab" ng-click="refresh_machine()" href="#v-pills-actions" data-toggle="pill" role="tab" aria-controls="v-pills-actions" aria-selected="true"><%=l 'Actions' %></a>
% }
% if ($USER->can_change_settings($domain->id)) {
<a class="nav-link" id="v-pills-rename-tab" ng-click="refresh_machine()" href="#v-pills-rename" data-toggle="pill" role="tab" aria-controls="v-pills-rename" aria-selected="true"><%=l 'Rename' %></a>
% }
......
......@@ -10,62 +10,69 @@
<br><br>
<div>
<div ng-show="showmachine.is_active">
<div ng-show="showmachine.can_hibernate">
<button type="button" class="btn btn-warning btn-sm"
ng-click="action('machine','hibernate',showmachine.id)"
ng-disabled="!showmachine.is_active"
title="<%=l 'Hibernate' %>">
<i class="fa fa-pause"></i>
</button>
<span><%=l 'Hibernate' %></span>
<br><br>
</div>
<div ng-show="showmachine.can_hibernate">
<button type="button" class="btn btn-warning btn-sm"
ng-click="action('machine','hibernate',showmachine.id)"
ng-disabled="!showmachine.is_active"
title="<%=l 'Hibernate' %>">
<i class="fa fa-pause"></i>
</button>
<span><%=l 'Hibernate' %></span>
<br><br>
</div>
<div ng-show="showmachine.can_shutdown">
<button type="button" class="btn btn-danger btn-sm"
ng-click="action('machine','shutdown',showmachine.id)"
ng-disabled="!showmachine.is_active"
title="<%=l 'ShutDown' %>">
<i class="fa fa-power-off"></i>
</button>
<span><%=l 'ShutDown' %></span>
<br><br>
</div>
<div ng-show="showmachine.can_shutdown">
<button type="button" class="btn btn-danger btn-sm"
ng-click="action('machine','shutdown',showmachine.id)"
ng-disabled="!showmachine.is_active"
title="<%=l 'ShutDown' %>">
<i class="fa fa-power-off"></i>
</button>
<span><%=l 'ShutDown' %></span>
<br><br>
</div>
<div ng-show="showmachine.can_shutdown">
<button type="button" class="btn btn-danger btn-sm"
ng-click="action('machine','shutdown',showmachine.id, { force: true })"
ng-disabled="!showmachine.is_active"
title="<%=l 'Force ShutDown' %>">
<i class="fa fa-power-off"></i>
</button>
<span><%=l 'Force ShutDown' %></span>
<br><br>
</div>
<div ng-show="showmachine.can_shutdown">
<button type="button" class="btn btn-danger btn-sm"
ng-click="action('machine','shutdown',showmachine.id, { force: true })"
ng-disabled="!showmachine.is_active"
title="<%=l 'Force ShutDown' %>">
<i class="fa fa-power-off"></i>
</button>
<span><%=l 'Force ShutDown' %></span>
<br><br>
</div>
<div ng-show="showmachine.can_reboot">
<button type="button" class="btn btn-danger btn-sm"
ng-click="action('machine','reboot',showmachine.id)"
ng-disabled="!showmachine.is_active"
title="<%=l 'Reboot' %>">
<i class="fa fa-power-off"></i>
</button>
<span><%=l 'Reboot' %></span>
<br><br>
</div>
<div ng-show="showmachine.can_reboot">
<button type="button" class="btn btn-danger btn-sm"
ng-click="action('machine','reboot',showmachine.id)"
ng-disabled="!showmachine.is_active"
title="<%=l 'Reboot' %>">
<i class="fa fa-power-off"></i>
</button>
<span><%=l 'Reboot' %></span>
<br><br>
</div>
<div ng-show="showmachine.can_view">
<a type="button" class="btn btn-primary btn-sm"
ng-href="/machine/view/{{showmachine.id}}.html"
title="<%=l 'View' %>">
<i class="fa fa-desktop"></i>
</a>
<span><%=l 'View' %></span>
<br><br>
</div>
<div ng-show="showmachine.can_reboot">
<button type="button" class="btn btn-danger btn-sm"
ng-click="action('machine','reboot',showmachine.id, { force: true })"
ng-disabled="!showmachine.is_active"
title="<%=l 'Force Reboot' %>">
<i class="fa fa-power-off"></i>
</button>
<span><%=l 'Force Reboot' %></span>
<br><br>
</div>
<div ng-show="showmachine.can_view">
<a type="button" class="btn btn-primary btn-sm"
ng-href="/machine/view/{{showmachine.id}}.html"
title="<%=l 'View' %>">
<i class="fa fa-desktop"></i>
</a>
<span><%=l 'View' %></span>
<br><br>
</div>
</div>
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