diff --git a/Anvil/Tools/DRBD.pm b/Anvil/Tools/DRBD.pm index 153b037a..44c2dfd3 100755 --- a/Anvil/Tools/DRBD.pm +++ b/Anvil/Tools/DRBD.pm @@ -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 This parses the DRBD status on the local or remote system. The data collected is stored in the following hashes; diff --git a/scancore-agents/scan-drbd/scan-drbd b/scancore-agents/scan-drbd/scan-drbd index 19cb95b7..b5d66b25 100755 --- a/scancore-agents/scan-drbd/scan-drbd +++ b/scancore-agents/scan-drbd/scan-drbd @@ -58,7 +58,7 @@ if (($< != 0) && ($> != 0)) $anvil->data->{scancore}{'scan-drbd'}{disable} = 0; $anvil->data->{scancore}{'scan-drbd'}{'auto-undefine'} = 1; -$anvil->data->{switches}{force} = 0; +$anvil->data->{switches}{force} = 0; $anvil->Storage->read_config(); @@ -73,7 +73,8 @@ if (($anvil->data->{scancore}{'scan-drbd'}{disable}) && (not $anvil->data->{swit } # 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) { $anvil->nice_exit({exit_code => 1}); @@ -138,8 +139,8 @@ sub process_drbd "s2:old_scan_drbd_common_xml" => $old_scan_drbd_common_xml, }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { - "s01:scan_drbd_uuid" => $new_scan_drbd_flush_disk, - "s02:scan_drbd_common_xml_diff" => $new_scan_drbd_flush_md, + "s01:scan_drbd_uuid" => $scan_drbd_uuid, + "s02:scan_drbd_common_xml_diff" => $scan_drbd_common_xml_diff, "s03:new_scan_drbd_flush_disk" => $new_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, @@ -294,20 +295,20 @@ sub process_resource { my ($anvil, $resource) = @_; - my $new_scan_drbd_resource_name = $resource; - my $scan_drbd_resource_uuid = $anvil->data->{new}{resource}{$resource}{scan_drbd_resource_uuid}; - 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 $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_xml = $anvil->data->{new}{resource}{$resource}{xml}; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { - "s1:scan_drbd_resource_uuid" => $scan_drbd_resource_uuid, - "s2:new_scan_drbd_resource_name" => $new_scan_drbd_resource_name, - "s3:new_scan_drbd_resource_up" => $new_scan_drbd_resource_up, - "s4:new_scan_drbd_resource_xml" => $new_scan_drbd_resource_xml, + "s1:scan_drbd_resource_name" => $scan_drbd_resource_name, + "s2:new_scan_drbd_resource_up" => $new_scan_drbd_resource_up, + "s3: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 + $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_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}; @@ -317,15 +318,18 @@ sub process_resource "s2:old_scan_drbd_resource_up" => $old_scan_drbd_resource_up, "s3:xml_difference" => $xml_difference, "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; - 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. $update = 1; my $variables = { - new_value => $new_scan_drbd_resource_name, + new_value => $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}); @@ -336,7 +340,7 @@ sub process_resource # Resoure state has changed. $update = 1; 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!#", 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. $update = 1; my $variables = { - resource_name => $new_scan_drbd_resource_name, + resource_name => $scan_drbd_resource_name, new_config => $new_scan_drbd_resource_xml, }; $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. $update = 1; my $variables = { - resource_name => $new_scan_drbd_resource_name, + resource_name => $scan_drbd_resource_name, differnce => $xml_difference, new_config => $new_scan_drbd_resource_xml, }; @@ -372,7 +376,7 @@ sub process_resource UPDATE scan_drbd_resources 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_xml = ".$anvil->Database->quote($new_scan_drbd_resource_xml).", modified_date = ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})." @@ -392,15 +396,17 @@ WHERE else { # New resource. - $scan_drbd_resource_uuid = $anvil->DRBD->resource_uuid({ - resource => $new_scan_drbd_resource_name, - resource_file => $anvil->data->{new}{resource}{$new_scan_drbd_resource_name}{config_file}, - new_resource_uuid => $anvil->Get->uuid(), - }); + ### This was the old way + #$scan_drbd_resource_uuid = $anvil->DRBD->resource_uuid({ + # resource => $scan_drbd_resource_name, + # 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 }}); 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_xml => $new_scan_drbd_resource_xml, }; @@ -420,7 +426,7 @@ INSERT INTO ) VALUES ( ".$anvil->Database->quote($scan_drbd_resource_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_xml).", ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})." @@ -431,7 +437,7 @@ INSERT INTO } # 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); @@ -1190,17 +1196,18 @@ sub gather_data "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. - my $scan_drbd_resource_uuid = $anvil->DRBD->resource_uuid({ - resource => $resource, - resource_file => $conf_file, - }); - $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->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}, - }}); + #my $scan_drbd_resource_uuid = $anvil->DRBD->resource_uuid({ + # resource => $resource, + # resource_file => $conf_file, + #}); + #$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->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}, + #}}); foreach my $host ($name->findnodes('./host')) { @@ -1307,24 +1314,31 @@ sub gather_data } } - local(*DIRECTORY); - opendir(DIRECTORY, $anvil->data->{'scan-drbd'}{resource_status}); - while(my $file = readdir(DIRECTORY)) + # 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}) { - next if $file eq "."; - next if $file eq ".."; - my $full_path = $anvil->data->{'scan-drbd'}{resource_status}."/".$file; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { full_path => $full_path }}); - if (-d $full_path) + local(*DIRECTORY); + opendir(DIRECTORY, $anvil->data->{'scan-drbd'}{resource_status}); + while(my $file = readdir(DIRECTORY)) { - my $resource = $file; - $anvil->data->{new}{resource}{$resource}{up} = 1; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { - "new::resource::${resource}::up" => $anvil->data->{new}{resource}{$resource}{up}, - }}); + next if $file eq "."; + next if $file eq ".."; + my $full_path = $anvil->data->{'scan-drbd'}{resource_status}."/".$file; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { full_path => $full_path }}); + if (-d $full_path) + { + my $resource = $file; + $anvil->data->{new}{resource}{$resource}{up} = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + "new::resource::${resource}::up" => $anvil->data->{new}{resource}{$resource}{up}, + }}); + } } + closedir(DIRECTORY); } - closedir(DIRECTORY); #print "Sync progress:\n"; #print " ".sprintf("%-${longest_resource}s", "Res")." ".sprintf("%-${longest_connection}s", "To")." Vol\n"; diff --git a/share/words.xml b/share/words.xml index 4f67cded..9b4e9633 100644 --- a/share/words.xml +++ b/share/words.xml @@ -270,6 +270,7 @@ The error was: Unable to get the install ISO to use for the new server: [#!variable!server_name!#] from the job UUID: [#!variable!job_uuid!#]. The install disc ISO: [#!variable!install_iso!#] to be used for the new server: [#!variable!server_name!#] wasn't found on this system. The driver disc ISO: [#!variable!install_iso!#] to be used for the new server: [#!variable!server_name!#] wasn't found on this system. + The new server's name: [#!variable!server_name!#] is already in use. Has this job already run? Current Network Interfaces and States diff --git a/tools/anvil-provision-server b/tools/anvil-provision-server index d91ebcd8..a7a09544 100755 --- a/tools/anvil-provision-server +++ b/tools/anvil-provision-server @@ -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->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) { $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); } diff --git a/tools/test.pl b/tools/test.pl index 99e1364e..ac845684 100755 --- a/tools/test.pl +++ b/tools/test.pl @@ -26,26 +26,8 @@ $anvil->Get->switches; $anvil->Database->connect({debug => 3}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0132"}); -my $anvil_uuid = "2ac4dbcb-25d2-44b2-ae07-59707b0551ca"; -my $node1_host_uuid = "92d0106c-8717-45da-a413-663d50323982"; -my $node2_host_uuid = "8da3d2fe-783a-4619-abb5-8ccae58f7bd6"; - -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"; -} +my $anvil_uuid = "a5ae5242-e9d3-46c9-9ce8-306855aa56db"; +my ($free_minor, $free_port) = $anvil->DRBD->get_next_resource({anvil_uuid => "a5ae5242-e9d3-46c9-9ce8-306855aa56db"}) +print "Next free minor: [".$free_minor."], port: [".$free_port."]\n"; $anvil->nice_exit({exit_code => 0});