* Added a check to anvil-delete-server to remove the XML definition file.

* Added checks to anvil-provision-server to see if an existing server name is flagged as DELETED, instead of outright rejecting a given server name.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 4 years ago
parent ac6531ddf2
commit e052c75e2f
  1. 4
      share/words.xml
  2. 14
      tools/anvil-delete-server
  3. 78
      tools/anvil-provision-server

@ -655,6 +655,8 @@ It should be provisioned in the next minute or two.</key>
<key name="job_0216">The server delete is complete on this host!</key> <key name="job_0216">The server delete is complete on this host!</key>
<key name="job_0217">It looks like ScanCore has not yet run on one or both nodes in this Anvil! system. Missing resource data, so unable to proceed.</key> <key name="job_0217">It looks like ScanCore has not yet run on one or both nodes in this Anvil! system. Missing resource data, so unable to proceed.</key>
<key name="job_0218">Manually calling 'scan-drbd' to ensure that the new agent is recorded.</key> <key name="job_0218">Manually calling 'scan-drbd' to ensure that the new agent is recorded.</key>
<key name="job_0219">The server name: [#!variable!server_name!#] is already used by another server.</key>
<key name="job_0220">Deleting the server's definition file: [#!variable!file!#]...</key>
<!-- Log entries --> <!-- Log entries -->
<key name="log_0001">Starting: [#!variable!program!#].</key> <key name="log_0001">Starting: [#!variable!program!#].</key>
@ -1654,6 +1656,8 @@ Are you sure that you want to delete the server: [#!variable!server_name!#]? [Ty
<key name="message_0216">The server is running here, assigning the job to this host.</key> <key name="message_0216">The server is running here, assigning the job to this host.</key>
<key name="message_0217">Preparing to delete a server.</key> <key name="message_0217">Preparing to delete a server.</key>
<key name="message_0218">Preparing to migrate a server (or all servers).</key> <key name="message_0218">Preparing to migrate a server (or all servers).</key>
<key name="message_0219">- #!variable!server_name!# (Current state: [#!variable!server_state!#])</key>
<key name="message_0220">- * #!variable!server_name!# (Deleted, name can be reused)</key>
<!-- Success messages shown to the user --> <!-- Success messages shown to the user -->
<key name="ok_0001">Saved the mail server information successfully!</key> <key name="ok_0001">Saved the mail server information successfully!</key>

@ -195,6 +195,20 @@ WHERE
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "job_0215"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "job_0215"});
} }
# Delete the XML definition file.
my $resource_file = $anvil->data->{path}{directories}{shared}{definitions}."/".$server_name.".xml";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { resource_file => $resource_file }});
if (-f $resource_file)
{
# Remove it.
$anvil->Job->update_progress({
progress => 80,
message => "job_0220,!!file!".$resource_file."!!",
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "job_0220", variables => { file => $resource_file }});
unlink $resource_file;
}
$anvil->Job->update_progress({ $anvil->Job->update_progress({
progress => 100, progress => 100,
message => "job_0216", message => "job_0216",

@ -423,8 +423,8 @@ sub provision_server
my ($handle, $return_code) = $anvil->System->call({ my ($handle, $return_code) = $anvil->System->call({
background => 1, background => 1,
shell_call => $shell_call, shell_call => $shell_call,
stdout_file => "/var/log/anvil_server_".$server.".stdout", stdout_file => "/var/log/anvil-server_".$server.".stdout",
stderr_file => "/var/log/anvil_server_".$server.".stderr", stderr_file => "/var/log/anvil-server_".$server.".stderr",
}); });
my $pid = $handle->pid(); my $pid = $handle->pid();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
@ -1235,6 +1235,15 @@ sub parse_job_data
server => $server, server => $server,
}}); }});
if (exists $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$server}) if (exists $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$server})
{
# Is this name used by a server marked as DELETED?
my $server_uuid = $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$server}{server_uuid};
my $server_state = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
server_uuid => $server_uuid,
server_state => $server_state,
}});
if ($server_state ne "DELETED")
{ {
# Duplicate name # Duplicate name
$anvil->Job->update_progress({ $anvil->Job->update_progress({
@ -1245,6 +1254,7 @@ sub parse_job_data
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => 'err', key => "error_0198", variables => { server_name => $anvil->data->{job}{server_name} }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => 'err', key => "error_0198", variables => { server_name => $anvil->data->{job}{server_name} }});
$anvil->nice_exit({exit_code => 1}); $anvil->nice_exit({exit_code => 1});
} }
}
if (not $anvil->data->{job}{server_name}) if (not $anvil->data->{job}{server_name})
{ {
@ -1565,6 +1575,7 @@ sub interactive_ask_server_name
### TODO: Figure out how many rows we have and break the server list into columns if too long. ### TODO: Figure out how many rows we have and break the server list into columns if too long.
my $retry = 0; my $retry = 0;
my $duplicate = "";
while(1) while(1)
{ {
my $default = ""; my $default = "";
@ -1579,14 +1590,42 @@ sub interactive_ask_server_name
# Show all the current server names. # Show all the current server names.
if ($retry) if ($retry)
{
if ($duplicate)
{
print $anvil->Words->string({key => "job_0219", variables => { server_name => $duplicate }})."\n\n";
$duplicate = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { duplicate => $duplicate }});
}
else
{ {
print $anvil->Words->string({key => "job_0159"})."\n\n"; print $anvil->Words->string({key => "job_0159"})."\n\n";
} }
}
my $anvil_uuid = $anvil->data->{new_server}{anvil_uuid}; my $anvil_uuid = $anvil->data->{new_server}{anvil_uuid};
print $anvil->Words->string({key => "job_0160", variables => { anvil_name => $anvil->data->{new_server}{anvil_name} }})."\n"; print $anvil->Words->string({key => "job_0160", variables => { anvil_name => $anvil->data->{new_server}{anvil_name} }})."\n";
foreach my $server_name (sort {$a cmp $b} keys %{$anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}}) foreach my $server_name (sort {$a cmp $b} keys %{$anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}})
{ {
print "- ".$server_name."\n"; my $server_uuid = $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$server_name}{server_uuid};
my $server_state = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
server_uuid => $server_uuid,
server_state => $server_state,
}});
if ($server_state eq "DELETED")
{
print "- ".$server_name." ("..")\n";
print $anvil->Words->string({key => "message_0220", variables => {
server_name => $server_name,
}})."\n";
}
else
{
print $anvil->Words->string({key => "message_0219", variables => {
server_name => $server_name,
server_state => $server_state,
}})."\n";
}
} }
print $terminal->Tgoto('cm', 0, 3)."? "; print $terminal->Tgoto('cm', 0, 3)."? ";
@ -1602,14 +1641,41 @@ sub interactive_ask_server_name
# Reload in case a new anvil! was saved while we waited. # Reload in case a new anvil! was saved while we waited.
$anvil->Database->get_servers(); $anvil->Database->get_servers();
if (($answer) && (not exists $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$answer})) if ($answer)
{
# Duplicate?
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { answer => $answer }});
if (exists $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$answer})
{
my $server_uuid = $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$answer}{server_uuid};
my $server_state = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
server_uuid => $server_uuid,
server_state => $server_state,
}});
if ($server_state eq "DELETED")
{
# Valid, we can re-use deleted server names.
$anvil->data->{new_server}{name} = $answer;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"new_server::name" => $anvil->data->{new_server}{name},
}});
}
else
{
# Invalid, duplicate.
$duplicate = $answer;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { duplicate => $duplicate }});
}
}
else
{ {
# Valid. # Valid.
$anvil->data->{new_server}{name} = $answer; $anvil->data->{new_server}{name} = $answer;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"new_server::name" => $anvil->data->{new_server}{name}, "new_server::name" => $anvil->data->{new_server}{name},
}}); }});
}
last; last;
} }
else else
@ -2218,7 +2284,7 @@ sub interactive_ask_server_os
}}); }});
# Still here? # Still here?
$os_list .= " - [".sprintf("%-10s", $os_code)."] - ".$os_name."\n"; $os_list .= " - ".sprintf("%-10s", $os_code)." - ".$os_name."\n";
} }
my $retry = 0; my $retry = 0;

Loading…
Cancel
Save