Possibly fixed the anvil-delete-server hang bug.

* Updated Server->connect_to_libvirt() to check that the target URI's
  SSH fingerprint is recorded before connecting. Also added an alarm
  wrapper around the Sys::Virt->new() call.
* Continued work on anvil-manage-server-system, working on the boot
  order section now.

Signed-off-by: digimer <mkelly@alteeve.ca>
main
digimer 1 year ago
parent 747e759248
commit 081c5ea90e
  1. 25
      Anvil/Tools/Server.pm
  2. 53
      tools/anvil-manage-server-system

@ -346,7 +346,7 @@ sub connect_to_libvirt
target_ip => $target_ip, target_ip => $target_ip,
}}); }});
if ((not $target)or ($target eq "localhost")) if ((not $target) or ($target eq "localhost"))
{ {
# Change to the short host name. # Change to the short host name.
$target = $anvil->Get->short_host_name; $target = $anvil->Get->short_host_name;
@ -383,11 +383,26 @@ sub connect_to_libvirt
# If we don't have a connection, try to establish one now. # If we don't have a connection, try to establish one now.
if (not $anvil->data->{libvirtd}{$target}{connection}) if (not $anvil->data->{libvirtd}{$target}{connection})
{ {
my $uri = "qemu+ssh://".$target_ip."/system"; # Make sure the target is known.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { uri => $uri }}); my $problem = $anvil->Remote->add_target_to_known_hosts({
debug => $debug,
target => $target_ip,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => { problem => $problem }});
### NOTE: For some reason, the below 'alarm'/SIGALRM' hook doesn't work if the ssh target's
### fingerprint isn't known, hence the call above. Whatever is causing this though
### could bite us in other ways.
# Test connect # Test connect
eval { $anvil->data->{libvirtd}{$target}{connection} = Sys::Virt->new(uri => $uri); }; my $uri = "qemu+ssh://".$target_ip."/system";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { uri => $uri }});
eval
{
local $SIG{ALRM} = sub { die "Connection to: [".$uri."] timed out!\n" }; # NB: \n required
alarm 10;
$anvil->data->{libvirtd}{$target}{connection} = Sys::Virt->new(uri => $uri);
alarm 0;
};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"libvirtd::${target}::connection" => $anvil->data->{libvirtd}{$target}{connection}, "libvirtd::${target}::connection" => $anvil->data->{libvirtd}{$target}{connection},
}}); }});
@ -2049,7 +2064,7 @@ sub parse_definition
} }
$anvil->data->{server}{$target}{$server}{$source}{parsed} = $server_xml; $anvil->data->{server}{$target}{$server}{$source}{parsed} = $server_xml;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"server::${target}::${server}::${source}::parsed" => $anvil->data->{server}{$target}{$server}{$source}{parsed}, "server::${target}::${server}::${source}::parsed" => $anvil->data->{server}{$target}{$server}{$source}{parsed},
}}); }});

@ -110,7 +110,7 @@ elsif ($anvil->data->{switches}{ram})
} }
elsif ($anvil->data->{switches}{boot}) elsif ($anvil->data->{switches}{boot})
{ {
#manage_boot($anvil); manage_boot($anvil);
} }
elsif ($anvil->data->{switches}{'boot-menu'}) elsif ($anvil->data->{switches}{'boot-menu'})
{ {
@ -133,6 +133,57 @@ $anvil->nice_exit({exit_code => 0});
# Functions # # Functions #
############################################################################################################# #############################################################################################################
sub manage_boot
{
my ($anvil) = @_;
my $short_host_name = $anvil->Get->short_host_name;
my $host_uuid = $anvil->Get->host_uuid;
my $server_name = $anvil->data->{switches}{server_name};
my $server_uuid = $anvil->data->{switches}{server_uuid};
my $server_host_uuid = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_host_uuid};
my $server_host_name = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:short_host_name' => $short_host_name,
's2:host_uuid' => $host_uuid,
's3:server_name' => $server_name,
's4:server_uuid' => $server_uuid,
's5:server_host_uuid' => $server_host_uuid,
}});
my $from_source = get_definition_source($anvil);
my $server_state = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
from_source => $from_source,
server_state => $server_state,
}});
if ($server_state eq "running")
{
$server_host_name = $anvil->Database->get_host_from_uuid({
short => 1,
host_uuid => $server_host_uuid,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { server_host_name => $server_host_name }});
}
if ($anvil->data->{switches}{boot} eq "#!SET!#")
{
print "Boot device order for: [".$server_name."]\n";
foreach my $boot_order (sort {$a cmp $b} keys %{$anvil->data->{server}{$short_host_name}{$server_name}{$from_source}{boot_order}})
{
my $device_target = $anvil->data->{server}{$short_host_name}{$server_name}{$from_source}{boot_order}{$boot_order}{device_target};
my $device = $anvil->data->{server}{$short_host_name}{$server_name}{$from_source}{boot_order}{$boot_order}{device_type};
my $path = $anvil->data->{server}{$short_host_name}{$server_name}{$from_source}{device}{$device}{target}{$device_target}{path};
print " ".$boot_order.") Target: [".$device_target."], Device: [".$device."], Path: [".$path."]\n";
}
print "To change the boot device, use '--boot <target>' or --boot <target1>,<target2>,...\n";
return(0);
}
print "Updating boot devices.\n";
return(0);
}
sub manage_boot_menu sub manage_boot_menu
{ {
my ($anvil) = @_; my ($anvil) = @_;

Loading…
Cancel
Save