* Updated anvil-delete-server to accept '--server' and '--force' to allow direct deletion of a server without interacting with the menu system.

This partially addresses issue #321.

Signed-off-by: digimer <mkelly@alteeve.ca>
main
digimer 2 years ago
parent bc3d04ad2e
commit 5bb1c631cf
  1. 14
      man/anvil-delete-server.8
  2. 88
      tools/anvil-delete-server

@ -1,13 +1,13 @@
.\" Manpage for the Anvil! server removal tool
.\" Contact mkelly@alteeve.com to report issues, concerns or suggestions.
.TH anvil-delete-server "8" "August 02 2022" "Anvil! Intelligent Availability™ Platform"
.TH anvil-delete-server "8" "June 06 2023" "Anvil! Intelligent Availability™ Platform"
.SH NAME
anvil-delete-server \- This program deletes a server from an Anvil! sub-cluster.
.SH SYNOPSIS
.B anvil-delete-server
\fI\,<command> \/\fR[\fI\,options\/\fR]
.SH DESCRIPTION
This deletes a server, running or stopped, from an Anvil! subcluster. The resource allocated to this server are removed and returned to the resource pool as well.
This deletes a server, running or stopped, from an Anvil! sub-cluster. The resource allocated to this server are removed and returned to the resource pool as well.
.TP
This action is permanent!
.TP
@ -23,9 +23,17 @@ When logging, record sensitive data, like passwords.
Set the log level to 1, 2 or 3 respectively. Be aware that level 3 generates a significant amount of log data.
.SS "Commands:"
.TP
\fB\-\-job-uuid\fR <name>
\fB\-\-job-uuid\fR <UUID>
The program is normally run as a job, with data on how to configure the host defined in the job. This switch allows the running of a specific job. If this is not set, the program will search for a job that has not yet been picked up by another process. If found, that job UUID is used automatically.
.IP
.SS "Commands:"
.TP
\fB\-\-force\fR
When used with \fB\-\-server\fR, no confirmation prompt will be shown. Use this with caution!
.TP
\fB\-\-server\fR <name or UUID>
This is the server to be deleted. It can either be the name or UUID. If not provided, a list of servers on the Anvil! node this command is run from will be shown where you can select the one to delete.
.TP
.SH AUTHOR
Written by Madison Kelly, Alteeve staff and the Anvil! project contributors.
.SH "REPORTING BUGS"

@ -29,7 +29,10 @@ my $anvil = Anvil::Tools->new();
# Read switches (target ([user@]host[:port]) and the file with the target's password. If the password is
# passed directly, it will be used. Otherwise, the password will be read from the database.
$anvil->Get->switches({list => ["job-uuid"], man => $THIS_FILE});
$anvil->Get->switches({list => [
"force",
"server",
"job-uuid"], man => $THIS_FILE});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => $anvil->data->{switches}});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
@ -91,6 +94,11 @@ if ($anvil->data->{switches}{'job-uuid'})
# Job data will be in $anvil->data->{jobs}{job_data}
run_jobs($anvil);
}
elsif ($anvil->data->{switches}{server})
{
# User specified what they want deleted.
confirm_server_delete($anvil);
}
else
{
if (not $anvil->data->{sys}{anvil_uuid})
@ -111,7 +119,6 @@ $anvil->nice_exit({exit_code => 0});
# Functions #
#############################################################################################################
# This actually provisions a VM.
sub run_jobs
{
@ -496,6 +503,38 @@ sub parse_job_data
return(0);
}
# This allows a user to specify the server they want deleted without going through the meny system.
sub confirm_server_delete
{
my ($anvil) = @_;
$anvil->Get->server_from_switch({
debug => 2,
server => $anvil->data->{switches}{server},
anvil_uuid => $anvil->data->{sys}{anvil_uuid},
});
if (not $anvil->data->{switches}{server_name})
{
# Not found.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => 'err', key => "error_0277", variables => { server => $anvil->data->{switches}{server} }});
$anvil->nice_exit({exit_code => 1});
}
# Ask the user to confirm, if needed. Note that this method requires '--force', not '-y' or '--Yes'.
if (not $anvil->data->{switches}{force})
{
get_confirmation($anvil);
}
else
{
# They're forcing, save.
save_job($anvil);
}
return(0);
}
# This will ask the user to select a server.
sub ask_for_server
@ -588,7 +627,23 @@ sub ask_for_server
}
}
$anvil->Get->server_from_switch({
debug => 2,
server => $delete_uuid,
anvil_uuid => $anvil->data->{sys}{anvil_uuid},
});
# Ask the user to confirm.
get_confirmation($anvil);
return(0);
}
sub get_confirmation
{
my ($anvil) = @_;
my $delete_uuid = $anvil->data->{switches}{server_uuid};
my $server_name = $anvil->data->{servers}{server_uuid}{$delete_uuid}{server_name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
delete_uuid => $delete_uuid,
@ -600,15 +655,35 @@ sub ask_for_server
chomp $answer;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { answer => $answer }});
if (lc($answer) eq "yes")
if ($answer eq "Yes")
{
### Save the job!
save_job($anvil);
}
else
{
# Abort.
print $anvil->Words->string({key => "message_0022"})."\n";
$anvil->nice_exit({exit_code => 0});
}
return(0);
}
sub save_job
{
my ($anvil) = @_;
# Is the server running?
print $anvil->Words->string({key => "message_0213"})."\n";
$anvil->Database->get_anvils();
my $hosts = [];
my $anvil_uuid = $anvil->data->{sys}{anvil_uuid};;
my $password = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_password};
my $server_name = $anvil->data->{switches}{server_name};
my $server_uuid = $anvil->data->{switches}{server_uuid};
my $delete_uuid = $server_uuid;
push @{$hosts}, $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid};
push @{$hosts}, $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node2_host_uuid};
if ($anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid})
@ -691,13 +766,6 @@ sub ask_for_server
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }});
$anvil->nice_exit({exit_code => 0});
}
else
{
# Abort.
print $anvil->Words->string({key => "message_0022"})."\n";
$anvil->nice_exit({exit_code => 0});
}
return(0);
}

Loading…
Cancel
Save