Commit 95801b74 authored by frankiejol's avatar frankiejol
Browse files

wip(backend): purge backups

parent b5494652
......@@ -3805,6 +3805,24 @@ sub _cmd_compact($self, $request) {
$domain->compact($request);
}
sub _cmd_purge($self, $request) {
my $id_domain = $request->args('id_domain');
my $domain = Ravada::Domain->open($id_domain)
or do {
$request->retry(0);
Ravada::Request->refresh_vms();
die "Error: domain $id_domain not found\n";
};
my $uid = $request->args('uid');
my $user = Ravada::Auth::SQL->search_by_id($uid);
die "Error: user ".$user->name." not allowed to compact ".$domain->name
unless $user->is_operator || $uid == $domain->_data('id_owner');
$domain->purge($request);
}
sub _migrate_base($self, $domain, $node, $uid, $request) {
my $base = Ravada::Domain->open($domain->id_base);
return if $base->base_in_vm($node->id);
......@@ -4180,6 +4198,7 @@ sub _req_method {
,change_hardware => \&_cmd_change_hardware
,set_time => \&_cmd_set_time
,compact => \&_cmd_compact
,purge => \&_cmd_purge
# Domain ports
,expose => \&_cmd_expose
......
......@@ -1586,7 +1586,7 @@ sub info($self, $user) {
,volatile_clones => $self->volatile_clones
,id_vm => $self->_data('id_vm')
};
for (qw(comment screenshot id_owner shutdown_disconnected)) {
for (qw(comment screenshot id_owner shutdown_disconnected is_compacted has_backups)) {
$info->{$_} = $self->_data($_);
}
if ($is_active) {
......@@ -5363,12 +5363,17 @@ sub compact($self, $request=undef) {
$keep_backup = $request->defined_arg('keep_backup') if $request;
$keep_backup = 1 if !defined $keep_backup;
my $backed_up = '';
$backed_up = " [backed up]" if $keep_backup;
my $out = '';
for my $vol ( $self->list_volumes_info ) {
next if !$vol->file || $vol->file =~ /iso$/;
my $vm = $self->_vm->new ( host => 'localhost' );
$vol->vm($vm);
$request->error("compacting ".$vol->file) if $request;
if ( !$self->is_active ) {
my $vm = $self->_vm->new ( host => 'localhost' );
$vol->vm($vm);
}
$request->error("compacting ".$vol->file."$backed_up") if $request;
$out .= $vol->info->{target}." ".($vol->compact($keep_backup) or '');
}
$request->error($out) if $request;
......@@ -5377,7 +5382,7 @@ sub compact($self, $request=undef) {
$self->_data('has_backups' => $self->_data('has_backups') +1 ) if $keep_backup;
}
sub purge($self) {
sub purge($self, $request=undef) {
my $vm = $self->_vm->new ( host => 'localhost' );
for my $vol ( $self->list_volumes_info ) {
next if !$vol->file || $vol->file =~ /iso$/;
......
......@@ -114,7 +114,8 @@ our %VALID_ARG = (
,migrate => { uid => 1, id_node => 1, id_domain => 1, start => 2, remote_ip => 2
,shutdown => 2, shutdown_timeout => 2
}
,compact => { uid => 1, id_domain => 1 }
,compact => { uid => 1, id_domain => 1 , keep_backup => 2 }
,purge => { uid => 1, id_domain => 1 }
#users
,post_login => { user => 1, locale => 2 }
......
......@@ -42,4 +42,44 @@
<br><br>
</div>
<hr>
<div class="container">
<div class="row mt-2">
<div class="col-lg-2" align="right">
<button class="btn btn-outline-dark"
ng-disabled="showmachine.is_compacted"
ng-click="request('compact',{'id_domain': showmachine.id , 'keep_backup': true })"
><%=l 'Compact' %></button>
</div>
<div class="col-md-7">
<div><%=l 'Compact disk volumes' %></div>
<div ng-show="showmachine.is_compacted">
This virtual machine has already been compacted
</div>
</div>
</div>
<div class="row mt-2">
<div class="col-lg-2" align="right">
<button class="btn btn-outline-dark"
ng-disabled="!showmachine.has_backups"
ng-click="request('purge',{'id_domain': showmachine.id })"
><%=l 'Purge' %></button>
</div>
<div class="col-md-7">
<span><%=l 'Purge disk volumes' %></span>
<div ng-hide="showmachine.has_backups">
This virtual machine has no backups to purge
</div>
</div>
</div>
</div>
<div ng-show="pending_request">
%= include "/main/pending_request"
</div>
</div>
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