@ -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 } ,
} } ) ;
} } ) ;