diff --git a/Anvil/Tools/Server.pm b/Anvil/Tools/Server.pm index 97196ed6..41e3166f 100755 --- a/Anvil/Tools/Server.pm +++ b/Anvil/Tools/Server.pm @@ -80,12 +80,15 @@ This looks on an Anvil! for what servers are running where. =cut +sub find +{ +} =head2 get_status -This reads in a server's XML definition file from disk, if available, and from memory, if the server is running. The XML is analyzed and data is stored in the following locations; +This reads in a server's XML definition file from disk, if available, and from memory, if the server is running. The XML is analyzed and data is stored under 'server::::from_disk::x' for data from the on-disk XML and 'server::::from_memory::x'. + - - Any pre-existing data on the server is flushed before the new information is processed. @@ -142,6 +145,9 @@ sub get_status } $anvil->data->{server}{$server}{from_memory}{host} = ""; + # We're going to map DRBD devices to resources, so we need to collect that data now. + $anvil->DRBD->get_devices({debug => $debug}); + # Is this a local call or a remote call? my $shell_call = $anvil->data->{path}{exe}{virsh}." dumpxml ".$server; my $host = $anvil->_short_hostname; @@ -212,8 +218,6 @@ sub get_status }); } - die; - return(0); } @@ -261,9 +265,6 @@ sub _parse_definition return(1); } - # We're going to map DRBD devices to resources, so we need to collect that data now. - $anvil->DRBD->get_devices({debug => $debug}); - my $xml = XML::Simple->new(); my $server_xml = ""; eval { $server_xml = $xml->XMLin($definition, KeyAttr => {}, ForceArray => 1) }; @@ -290,7 +291,7 @@ sub _parse_definition $anvil->data->{server}{$server}{$source}{info}{boot_menu} = $server_xml->{os}->[0]->{bootmenu}->[0]->{enable}; $anvil->data->{server}{$server}{$source}{info}{architecture} = $server_xml->{os}->[0]->{type}->[0]->{arch}; $anvil->data->{server}{$server}{$source}{info}{machine} = $server_xml->{os}->[0]->{type}->[0]->{machine}; - $anvil->data->{server}{$server}{$source}{info}{id} = $server_xml->{id}; + $anvil->data->{server}{$server}{$source}{info}{id} = exists $server_xml->{id} ? $server_xml->{id} : 0; $anvil->data->{server}{$server}{$source}{info}{emulator} = $server_xml->{devices}->[0]->{emulator}->[0]; $anvil->data->{server}{$server}{$source}{info}{acpi} = exists $server_xml->{features}->[0]->{acpi} ? 1 : 0; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { diff --git a/ocf/alteeve/server b/ocf/alteeve/server index 3c77b48c..fb275e14 100755 --- a/ocf/alteeve/server +++ b/ocf/alteeve/server @@ -392,6 +392,14 @@ sub validate_all # Read in an parse the server's XML. $anvil->Server->get_status({debug => 2, server => $anvil->data->{environment}{OCF_RESKEY_name}}); + + # Is the name in the definition file what we expect? + validate_name($anvil); + + # Make sure the emulator it wants is the one we have. + validate_emulator($anvil); + + # Which DRBD resources do I need? return(0); @@ -452,7 +460,29 @@ sub validate_emulator { my ($anvil) = @_; - + # What emulator is this using? + my $server = $anvil->data->{environment}{OCF_RESKEY_name}; + my $emulator = $anvil->data->{server}{$server}{from_disk}{info}{emulator}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + emulator => $emulator, + "server::${server}::from_disk::info::emulator" => $anvil->data->{server}{$server}{from_disk}{info}{emulator} + }}); + if (not -e $emulator) + { + # It doesn't exist. Exit with OCF_ERR_INSTALLED (5). + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "log_0401", variables => { + emulator => $emulator, + definition_file => $anvil->data->{server}{definition_file}, + }}); + $anvil->nice_exit({exit_code => 5}); + } + if (not -x $emulator) + { + # We can't execute it. Exit with OCF_ERR_PERM (4). + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "log_0402", variables => { emulator => $emulator }}); + $anvil->nice_exit({exit_code => 4}); + } + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "log_0364"}); return(0); } @@ -462,7 +492,21 @@ sub validate_name { my ($anvil) = @_; - + # Is the name in the definition file what we expect? + my $server = $anvil->data->{environment}{OCF_RESKEY_name}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + server => $server, + "server::${server}::from_disk::info::name" => $anvil->data->{server}{$server}{from_disk}{info}{name}, + }}); + if ($server ne $anvil->data->{server}{$server}{from_disk}{info}{name}) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "log_0403", variables => { + server => $server, + name => $anvil->data->{server}{definition_xml}->{name}, + }}); + $anvil->nice_exit({exit_code => 1}); + } + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "log_0363"}); return(0); }