* 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 030f4a7efc
commit 86228e9d1d
  1. 4
      share/words.xml
  2. 14
      tools/anvil-delete-server
  3. 108
      tools/anvil-provision-server
  4. 38
      tools/test.pl

@ -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_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_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 -->
<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_0217">Preparing to delete a server.</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 -->
<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"});
}
# 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({
progress => 100,
message => "job_0216",

@ -423,8 +423,8 @@ sub provision_server
my ($handle, $return_code) = $anvil->System->call({
background => 1,
shell_call => $shell_call,
stdout_file => "/var/log/anvil_server_".$server.".stdout",
stderr_file => "/var/log/anvil_server_".$server.".stderr",
stdout_file => "/var/log/anvil-server_".$server.".stdout",
stderr_file => "/var/log/anvil-server_".$server.".stderr",
});
my $pid = $handle->pid();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
@ -1236,14 +1236,24 @@ sub parse_job_data
}});
if (exists $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$server})
{
# Duplicate name
$anvil->Job->update_progress({
progress => 100,
message => "error_0198,!!server_name!".$anvil->data->{job}{server_name}."!!",
job_status => "failed",
});
$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});
# 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
$anvil->Job->update_progress({
progress => 100,
message => "error_0198,!!server_name!".$anvil->data->{job}{server_name}."!!",
job_status => "failed",
});
$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});
}
}
if (not $anvil->data->{job}{server_name})
@ -1564,7 +1574,8 @@ sub interactive_ask_server_name
$anvil->Database->get_servers({debug => 2});
### 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)
{
my $default = "";
@ -1580,13 +1591,41 @@ sub interactive_ask_server_name
# Show all the current server names.
if ($retry)
{
print $anvil->Words->string({key => "job_0159"})."\n\n";
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";
}
}
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";
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)."? ";
@ -1602,14 +1641,41 @@ sub interactive_ask_server_name
# Reload in case a new anvil! was saved while we waited.
$anvil->Database->get_servers();
if (($answer) && (not exists $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$answer}))
if ($answer)
{
# Valid.
$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},
}});
# 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.
$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},
}});
}
last;
}
else
@ -2218,7 +2284,7 @@ sub interactive_ask_server_os
}});
# Still here?
$os_list .= " - [".sprintf("%-10s", $os_code)."] - ".$os_name."\n";
$os_list .= " - ".sprintf("%-10s", $os_code)." - ".$os_name."\n";
}
my $retry = 0;

@ -26,10 +26,38 @@ $anvil->Get->switches;
$anvil->Database->connect({debug => 3});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0132"});
my ($free_minor, $free_port) = $anvil->DRBD->get_next_resource({debug => 2, anvil_uuid => "1aded871-fcb1-4473-9b97-6e9c246fc568"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
free_minor => $free_minor,
free_port => $free_port,
}});
my $key_string = 'message_0190
job_0185
job_0186,!!minor!5!!,!!port!7803!!
job_0188,!!job_uuid!12eeded2-c5bb-4295-8c8e-665bd9c9b83a!!,!!peer_name!mk-a02n01.digimer.ca!!
job_0189,!!lv_path!/dev/mk-a02n02_ssd0/srv02-lab02_0!!
job_0218
job_0190,!!resource!srv02-lab02!!
job_0191,!!resource!srv02-lab02!!
job_0192
job_0195
job_0203,!!resource!srv02-lab02!!
job_0199,!!shell_call!/usr/bin/virt-install --connect qemu:///system \
--name srv02-lab02 \
--os-variant win2k19 \
--memory 8192 \
--events on_poweroff=destroy,on_reboot=restart \
--vcpus 6,sockets=1,cores=6 \
--cpu host \
--network bridge=ifn1_bridge1,model=virtio \
--graphics spice \
--sound ich9 \
--clock offset=localtime \
--boot menu=on \
--disk path=/dev/drbd/by-res/srv02-lab02/0,target.bus=virtio,driver.io=threads,cache=writeback,driver.discard=unmap,boot.order=1 \
--disk path=/mnt/shared/files/Windows_Server_2019_eval.iso,device=cdrom,shareable=on,boot.order=2 \
--disk path=/mnt/shared/files/virtio-win-0.1.185.iso,device=cdrom,shareable=on,boot.order=3 --force \
--noautoconsole --wait -1 > /var/log/anvil-server_srv02-lab02.log
!!
job_0200';
my ($free_minor, $free_port) = $anvil->Words->parse_banged_string({
debug => 2,
key_string => $key_string,
});
$anvil->nice_exit({exit_code => 0});

Loading…
Cancel
Save