* Started work on DRBD->get_next_resource(), that will eventually return the next free DRBD minor and TCP port numbers.

* Fixed a bug in scan-drbd that was still looking for the scan_drbd_resource_uuid from the resource config file. Also added a check to see if 'scan-drbd::resource_status' directory exists before trying to read the files in it.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 4 years ago
parent a7f0676a0f
commit 162f4913b1
  1. 63
      Anvil/Tools/DRBD.pm
  2. 82
      scancore-agents/scan-drbd/scan-drbd
  3. 1
      share/words.xml
  4. 18
      tools/anvil-provision-server
  5. 24
      tools/test.pl

@ -514,6 +514,69 @@ sub get_devices
} }
=head2 get_next_resource
This returns the next free DRBD minor number and the next free TCP port. The minor number is the first one found to be free. The TCP port is allocated in steps of three. That is to say, if the last used TCP port is '7790', then '7793' is considered the next free port. This is to ensure that if a DR host is added or used, the three adjacent ports are available for use in one resource configuration.
Minor numbers are not grouped as resources and volumes can be referenced by name, so the DRBD minor number is less important for human users.
my ($free_minor, $free_port) = $anvil->DRBD->get_next_resource({anvil_uuid => "a5ae5242-e9d3-46c9-9ce8-306855aa56db"})
If there is a problem, two empty strings will be returned.
Parameters;
=head3 anvil_uuid (required)
This is the Anvil! in which we're looking for the next free resources.
=cut
sub get_next_resource
{
my $self = shift;
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "DRBD->get_next_resource()" }});
my $free_minor = "";
my $free_port = "";
my $anvil_uuid = defined $parameter->{anvil_uuid} ? $parameter->{anvil_uuid} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
anvil_uuid => $anvil_uuid,
}});
if (not $anvil_uuid)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "DRBD->get_next_resource()", parameter => "anvil_uuid" }});
return($free_minor, $free_port);
}
$anvil->Database->get_anvils({debug => $debug});
if (not exists $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid})
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0162", variables => { anvil_uuid => $anvil_uuid }});
return($free_minor, $free_port);
}
# Read in the resource information from both nodes. They _should_ be identical, but that's not 100%
# certain.
my $node1_host_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid};
my $node2_host_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node2_host_uuid};
my $dr1_host_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
node1_host_uuid => $node1_host_uuid,
node2_host_uuid => $node2_host_uuid,
dr1_host_uuid => $dr1_host_uuid,
}});
my $query = "
;";
return($free_minor, $free_port);
}
=head2 get_status =head2 get_status
This parses the DRBD status on the local or remote system. The data collected is stored in the following hashes; This parses the DRBD status on the local or remote system. The data collected is stored in the following hashes;

@ -73,7 +73,8 @@ if (($anvil->data->{scancore}{'scan-drbd'}{disable}) && (not $anvil->data->{swit
} }
# Handle start-up tasks # Handle start-up tasks
my $problem = $anvil->ScanCore->agent_startup({debug => 2, agent => $THIS_FILE}); my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }});
if ($problem) if ($problem)
{ {
$anvil->nice_exit({exit_code => 1}); $anvil->nice_exit({exit_code => 1});
@ -138,8 +139,8 @@ sub process_drbd
"s2:old_scan_drbd_common_xml" => $old_scan_drbd_common_xml, "s2:old_scan_drbd_common_xml" => $old_scan_drbd_common_xml,
}}); }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"s01:scan_drbd_uuid" => $new_scan_drbd_flush_disk, "s01:scan_drbd_uuid" => $scan_drbd_uuid,
"s02:scan_drbd_common_xml_diff" => $new_scan_drbd_flush_md, "s02:scan_drbd_common_xml_diff" => $scan_drbd_common_xml_diff,
"s03:new_scan_drbd_flush_disk" => $new_scan_drbd_flush_disk, "s03:new_scan_drbd_flush_disk" => $new_scan_drbd_flush_disk,
"s04:old_scan_drbd_flush_disk" => $old_scan_drbd_flush_disk, "s04:old_scan_drbd_flush_disk" => $old_scan_drbd_flush_disk,
"s05:new_scan_drbd_flush_md" => $new_scan_drbd_flush_md, "s05:new_scan_drbd_flush_md" => $new_scan_drbd_flush_md,
@ -294,20 +295,20 @@ sub process_resource
{ {
my ($anvil, $resource) = @_; my ($anvil, $resource) = @_;
my $new_scan_drbd_resource_name = $resource; my $scan_drbd_resource_uuid = "";
my $scan_drbd_resource_uuid = $anvil->data->{new}{resource}{$resource}{scan_drbd_resource_uuid}; my $scan_drbd_resource_name = $resource;
my $new_scan_drbd_resource_up = $anvil->data->{new}{resource}{$resource}{up}; my $new_scan_drbd_resource_up = $anvil->data->{new}{resource}{$resource}{up};
my $new_scan_drbd_resource_xml = $anvil->data->{new}{resource}{$resource}{xml}; my $new_scan_drbd_resource_xml = $anvil->data->{new}{resource}{$resource}{xml};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"s1:scan_drbd_resource_uuid" => $scan_drbd_resource_uuid, "s1:scan_drbd_resource_name" => $scan_drbd_resource_name,
"s2:new_scan_drbd_resource_name" => $new_scan_drbd_resource_name, "s2:new_scan_drbd_resource_up" => $new_scan_drbd_resource_up,
"s3:new_scan_drbd_resource_up" => $new_scan_drbd_resource_up, "s3:new_scan_drbd_resource_xml" => $new_scan_drbd_resource_xml,
"s4:new_scan_drbd_resource_xml" => $new_scan_drbd_resource_xml,
}}); }});
if (exists $anvil->data->{old}{resource_to_uuid}{$new_scan_drbd_resource_name}) if (exists $anvil->data->{old}{resource_to_uuid}{$scan_drbd_resource_name})
{ {
# If there was a UUID from the resource file, it's the one # If there was a UUID from the resource file, it's the one
$scan_drbd_resource_uuid = $anvil->data->{old}{resource_to_uuid}{$scan_drbd_resource_name}{uuid};
my $old_scan_drbd_resource_name = $anvil->data->{old}{scan_drbd_resource}{scan_drbd_resource_uuid}{$scan_drbd_resource_uuid}{scan_drbd_resource_name}; my $old_scan_drbd_resource_name = $anvil->data->{old}{scan_drbd_resource}{scan_drbd_resource_uuid}{$scan_drbd_resource_uuid}{scan_drbd_resource_name};
my $old_scan_drbd_resource_up = $anvil->data->{old}{scan_drbd_resource}{scan_drbd_resource_uuid}{$scan_drbd_resource_uuid}{scan_drbd_resource_up}; my $old_scan_drbd_resource_up = $anvil->data->{old}{scan_drbd_resource}{scan_drbd_resource_uuid}{$scan_drbd_resource_uuid}{scan_drbd_resource_up};
my $old_scan_drbd_resource_xml = $anvil->data->{old}{scan_drbd_resource}{scan_drbd_resource_uuid}{$scan_drbd_resource_uuid}{scan_drbd_resource_xml}; my $old_scan_drbd_resource_xml = $anvil->data->{old}{scan_drbd_resource}{scan_drbd_resource_uuid}{$scan_drbd_resource_uuid}{scan_drbd_resource_xml};
@ -317,15 +318,18 @@ sub process_resource
"s2:old_scan_drbd_resource_up" => $old_scan_drbd_resource_up, "s2:old_scan_drbd_resource_up" => $old_scan_drbd_resource_up,
"s3:xml_difference" => $xml_difference, "s3:xml_difference" => $xml_difference,
"s4:old_scan_drbd_resource_xml" => $old_scan_drbd_resource_xml, "s4:old_scan_drbd_resource_xml" => $old_scan_drbd_resource_xml,
"s5:new_scan_drbd_resource_xml" => $new_scan_drbd_resource_xml,
}}); }});
die if not defined $old_scan_drbd_resource_xml;
my $update = 0; my $update = 0;
if ($new_scan_drbd_resource_name ne $old_scan_drbd_resource_name) if ($scan_drbd_resource_name ne $old_scan_drbd_resource_name)
{ {
# Name has changed. # Name has changed.
$update = 1; $update = 1;
my $variables = { my $variables = {
new_value => $new_scan_drbd_resource_name, new_value => $scan_drbd_resource_name,
old_value => $old_scan_drbd_resource_name, old_value => $old_scan_drbd_resource_name,
}; };
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_drbd_message_0010", variables => $variables}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_drbd_message_0010", variables => $variables});
@ -336,7 +340,7 @@ sub process_resource
# Resoure state has changed. # Resoure state has changed.
$update = 1; $update = 1;
my $variables = { my $variables = {
resource_name => $new_scan_drbd_resource_name, resource_name => $scan_drbd_resource_name,
new_value => $new_scan_drbd_resource_up ? "#!string!scan_drbd_unit_0004!#" : "#!string!scan_drbd_unit_0005!#", new_value => $new_scan_drbd_resource_up ? "#!string!scan_drbd_unit_0004!#" : "#!string!scan_drbd_unit_0005!#",
old_value => $old_scan_drbd_resource_up ? "#!string!scan_drbd_unit_0004!#" : "#!string!scan_drbd_unit_0005!#", old_value => $old_scan_drbd_resource_up ? "#!string!scan_drbd_unit_0004!#" : "#!string!scan_drbd_unit_0005!#",
}; };
@ -348,7 +352,7 @@ sub process_resource
# Resource came back. # Resource came back.
$update = 1; $update = 1;
my $variables = { my $variables = {
resource_name => $new_scan_drbd_resource_name, resource_name => $scan_drbd_resource_name,
new_config => $new_scan_drbd_resource_xml, new_config => $new_scan_drbd_resource_xml,
}; };
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_drbd_message_0012", variables => $variables}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_drbd_message_0012", variables => $variables});
@ -359,7 +363,7 @@ sub process_resource
# Resoure state has changed. # Resoure state has changed.
$update = 1; $update = 1;
my $variables = { my $variables = {
resource_name => $new_scan_drbd_resource_name, resource_name => $scan_drbd_resource_name,
differnce => $xml_difference, differnce => $xml_difference,
new_config => $new_scan_drbd_resource_xml, new_config => $new_scan_drbd_resource_xml,
}; };
@ -372,7 +376,7 @@ sub process_resource
UPDATE UPDATE
scan_drbd_resources scan_drbd_resources
SET SET
scan_drbd_resource_name = ".$anvil->Database->quote($new_scan_drbd_resource_name).", scan_drbd_resource_name = ".$anvil->Database->quote($scan_drbd_resource_name).",
scan_drbd_resource_up = ".$anvil->Database->quote($new_scan_drbd_resource_up).", scan_drbd_resource_up = ".$anvil->Database->quote($new_scan_drbd_resource_up).",
scan_drbd_resource_xml = ".$anvil->Database->quote($new_scan_drbd_resource_xml).", scan_drbd_resource_xml = ".$anvil->Database->quote($new_scan_drbd_resource_xml).",
modified_date = ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})." modified_date = ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})."
@ -392,15 +396,17 @@ WHERE
else else
{ {
# New resource. # New resource.
$scan_drbd_resource_uuid = $anvil->DRBD->resource_uuid({ ### This was the old way
resource => $new_scan_drbd_resource_name, #$scan_drbd_resource_uuid = $anvil->DRBD->resource_uuid({
resource_file => $anvil->data->{new}{resource}{$new_scan_drbd_resource_name}{config_file}, # resource => $scan_drbd_resource_name,
new_resource_uuid => $anvil->Get->uuid(), # resource_file => $anvil->data->{new}{resource}{$scan_drbd_resource_name}{config_file},
}); # new_resource_uuid => $anvil->Get->uuid(),
#});
$scan_drbd_resource_uuid = $anvil->Get->uuid();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { scan_drbd_resource_uuid => $scan_drbd_resource_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { scan_drbd_resource_uuid => $scan_drbd_resource_uuid }});
my $variables = { my $variables = {
resource_name => $new_scan_drbd_resource_name, resource_name => $scan_drbd_resource_name,
resource_state => $new_scan_drbd_resource_up ? "#!string!scan_drbd_unit_0004!#" : "#!string!scan_drbd_unit_0005!#", resource_state => $new_scan_drbd_resource_up ? "#!string!scan_drbd_unit_0004!#" : "#!string!scan_drbd_unit_0005!#",
resource_xml => $new_scan_drbd_resource_xml, resource_xml => $new_scan_drbd_resource_xml,
}; };
@ -420,7 +426,7 @@ INSERT INTO
) VALUES ( ) VALUES (
".$anvil->Database->quote($scan_drbd_resource_uuid).", ".$anvil->Database->quote($scan_drbd_resource_uuid).",
".$anvil->Database->quote($anvil->Get->host_uuid).", ".$anvil->Database->quote($anvil->Get->host_uuid).",
".$anvil->Database->quote($new_scan_drbd_resource_name).", ".$anvil->Database->quote($scan_drbd_resource_name).",
".$anvil->Database->quote($new_scan_drbd_resource_up).", ".$anvil->Database->quote($new_scan_drbd_resource_up).",
".$anvil->Database->quote($new_scan_drbd_resource_xml).", ".$anvil->Database->quote($new_scan_drbd_resource_xml).",
".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})." ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})."
@ -431,7 +437,7 @@ INSERT INTO
} }
# Now process volumes # Now process volumes
process_volumes($anvil, $new_scan_drbd_resource_name, $scan_drbd_resource_uuid); process_volumes($anvil, $scan_drbd_resource_name, $scan_drbd_resource_uuid);
process_peers($anvil, $resource, $scan_drbd_resource_uuid); process_peers($anvil, $resource, $scan_drbd_resource_uuid);
@ -1190,17 +1196,18 @@ sub gather_data
"new::resource::${resource}::config_file" => $anvil->data->{new}{resource}{$resource}{config_file}, "new::resource::${resource}::config_file" => $anvil->data->{new}{resource}{$resource}{config_file},
}}); }});
### NOTE: We don't do this anymore.
# See if there's a scan_drbd_resource_uuid in the config file. # See if there's a scan_drbd_resource_uuid in the config file.
my $scan_drbd_resource_uuid = $anvil->DRBD->resource_uuid({ #my $scan_drbd_resource_uuid = $anvil->DRBD->resource_uuid({
resource => $resource, # resource => $resource,
resource_file => $conf_file, # resource_file => $conf_file,
}); #});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { scan_drbd_resource_uuid => $scan_drbd_resource_uuid }}); #$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { scan_drbd_resource_uuid => $scan_drbd_resource_uuid }});
#
$anvil->data->{new}{resource}{$resource}{scan_drbd_resource_uuid} = $scan_drbd_resource_uuid eq "!!error!!" ? "" : $scan_drbd_resource_uuid; #$anvil->data->{new}{resource}{$resource}{scan_drbd_resource_uuid} = $scan_drbd_resource_uuid eq "!!error!!" ? "" : $scan_drbd_resource_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { #$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
"new::resource::${resource}::scan_drbd_resource_uuid" => $anvil->data->{new}{resource}{$resource}{scan_drbd_resource_uuid}, # "new::resource::${resource}::scan_drbd_resource_uuid" => $anvil->data->{new}{resource}{$resource}{scan_drbd_resource_uuid},
}}); #}});
foreach my $host ($name->findnodes('./host')) foreach my $host ($name->findnodes('./host'))
{ {
@ -1307,6 +1314,12 @@ sub gather_data
} }
} }
# If DRBD is stopped, this directory won't exist.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"scan-drbd::resource_status" => $anvil->data->{'scan-drbd'}{resource_status},
}});
if (-d $anvil->data->{'scan-drbd'}{resource_status})
{
local(*DIRECTORY); local(*DIRECTORY);
opendir(DIRECTORY, $anvil->data->{'scan-drbd'}{resource_status}); opendir(DIRECTORY, $anvil->data->{'scan-drbd'}{resource_status});
while(my $file = readdir(DIRECTORY)) while(my $file = readdir(DIRECTORY))
@ -1325,6 +1338,7 @@ sub gather_data
} }
} }
closedir(DIRECTORY); closedir(DIRECTORY);
}
#print "Sync progress:\n"; #print "Sync progress:\n";
#print " ".sprintf("%-${longest_resource}s", "Res")." ".sprintf("%-${longest_connection}s", "To")." Vol\n"; #print " ".sprintf("%-${longest_resource}s", "Res")." ".sprintf("%-${longest_connection}s", "To")." Vol\n";

@ -270,6 +270,7 @@ The error was:
<key name="error_0195">Unable to get the install ISO to use for the new server: [#!variable!server_name!#] from the job UUID: [#!variable!job_uuid!#].</key> <key name="error_0195">Unable to get the install ISO to use for the new server: [#!variable!server_name!#] from the job UUID: [#!variable!job_uuid!#].</key>
<key name="error_0196">The install disc ISO: [#!variable!install_iso!#] to be used for the new server: [#!variable!server_name!#] wasn't found on this system.</key> <key name="error_0196">The install disc ISO: [#!variable!install_iso!#] to be used for the new server: [#!variable!server_name!#] wasn't found on this system.</key>
<key name="error_0197">The driver disc ISO: [#!variable!install_iso!#] to be used for the new server: [#!variable!server_name!#] wasn't found on this system.</key> <key name="error_0197">The driver disc ISO: [#!variable!install_iso!#] to be used for the new server: [#!variable!server_name!#] wasn't found on this system.</key>
<key name="error_0198">The new server's name: [#!variable!server_name!#] is already in use. Has this job already run?</key>
<!-- Table headers --> <!-- Table headers -->
<key name="header_0001">Current Network Interfaces and States</key> <key name="header_0001">Current Network Interfaces and States</key>

@ -169,6 +169,21 @@ sub run_jobs
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => 'err', key => "error_0187", variables => { job_uuid => $anvil->data->{switches}{'job-uuid'} }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => 'err', key => "error_0187", variables => { job_uuid => $anvil->data->{switches}{'job-uuid'} }});
$anvil->nice_exit({exit_code => 1}); $anvil->nice_exit({exit_code => 1});
} }
# Is the server name unique?
$anvil->Database->get_servers();
if (exists $anvil->data->{servers}{anvil_uuid}{$server_anvil_uuid}{server_name}{$server_name})
{
# Duplicate name
$anvil->Job->update_progress({
progress => 100,
message => "error_0198,!!server_name!".$server_name."!!",
job_status => "failed",
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => 'err', key => "error_0198", variables => { server_name => $server_name }});
$anvil->nice_exit({exit_code => 1});
}
if (not $cpu_cores) if (not $cpu_cores)
{ {
$anvil->Job->update_progress({ $anvil->Job->update_progress({
@ -317,6 +332,9 @@ sub run_jobs
} }
} }
# Still alive? Ready to go!
my $drbd_minor = $anvil->DRBD->get_next_resource({})
return(0); return(0);
} }

@ -26,26 +26,8 @@ $anvil->Get->switches;
$anvil->Database->connect({debug => 3}); $anvil->Database->connect({debug => 3});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0132"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0132"});
my $anvil_uuid = "2ac4dbcb-25d2-44b2-ae07-59707b0551ca"; my $anvil_uuid = "a5ae5242-e9d3-46c9-9ce8-306855aa56db";
my $node1_host_uuid = "92d0106c-8717-45da-a413-663d50323982"; my ($free_minor, $free_port) = $anvil->DRBD->get_next_resource({anvil_uuid => "a5ae5242-e9d3-46c9-9ce8-306855aa56db"})
my $node2_host_uuid = "8da3d2fe-783a-4619-abb5-8ccae58f7bd6"; print "Next free minor: [".$free_minor."], port: [".$free_port."]\n";
my $primary_host_uuid = $anvil->Cluster->get_primary_host_uuid({debug => 2, anvil_uuid => $anvil_uuid});
if (not $primary_host_uuid)
{
print "Neither node is primary.\n";
}
elsif ($primary_host_uuid eq $node1_host_uuid)
{
print "Node 1 is primary\n";
}
elsif ($primary_host_uuid eq $node2_host_uuid)
{
print "Node 2 is primary\n";
}
else
{
print "wtf? [".$primary_host_uuid."]\n";
}
$anvil->nice_exit({exit_code => 0}); $anvil->nice_exit({exit_code => 0});

Loading…
Cancel
Save