* Finished getting anvil-manage-server-storage to add new volumes to running servers.

Signed-off-by: digimer <mkelly@alteeve.ca>
main
digimer 1 year ago
parent afaf129733
commit 541381e317
  1. 68
      tools/anvil-manage-server-storage

@ -998,7 +998,7 @@ sub manage_disk_add
# Find which node is currently Primary and use that host to force primary to start sync. If none, # Find which node is currently Primary and use that host to force primary to start sync. If none,
# force here. # force here.
print "- Waiting for all peers to connect the new volume..."; print "- Waiting for all peers to connect the new volume...\n";
my $waiting = 1; my $waiting = 1;
my $wait_until = time + 300; my $wait_until = time + 300;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { wait_until => $wait_until }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { wait_until => $wait_until }});
@ -1064,7 +1064,7 @@ sub manage_disk_add
# If the volume is 'Negotiating', disconnect and reconnect the peer. # If the volume is 'Negotiating', disconnect and reconnect the peer.
if (lc($peer_disk_state) eq "negotiating") if (lc($peer_disk_state) eq "negotiating")
{ {
print "\n- Problem!\n"; print "- Problem!\n";
($peer_disk_state, $role) = reconnect_resource($anvil, $short_host_name, $peer_name, $drbd_resource, $next_drbd_volume); ($peer_disk_state, $role) = reconnect_resource($anvil, $short_host_name, $peer_name, $drbd_resource, $next_drbd_volume);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
peer_disk_state => $peer_disk_state, peer_disk_state => $peer_disk_state,
@ -1105,13 +1105,12 @@ sub manage_disk_add
{ {
if (time > $wait_until) if (time > $wait_until)
{ {
print " Failed!\n[ Error ] - The peers did not connect in the expected period of time.\n"; print "\nFailed!\n[ Error ] - The peers did not connect in the expected period of time.\n";
$anvil->nice_exit({exit_code => 1}); $anvil->nice_exit({exit_code => 1});
} }
sleep 2; sleep 2;
} }
} }
print " Done!\n";
print "- Peers are connected! Checking if the new volume requires initial sync.\n"; print "- Peers are connected! Checking if the new volume requires initial sync.\n";
my $all_inconsistent = 1; my $all_inconsistent = 1;
@ -1313,7 +1312,7 @@ sub manage_disk_add
$shell_call = $anvil->data->{path}{exe}{setsid}." --wait ".$anvil->data->{path}{exe}{virsh}." attach-disk ".$server_name." "; $shell_call = $anvil->data->{path}{exe}{setsid}." --wait ".$anvil->data->{path}{exe}{virsh}." attach-disk ".$server_name." ";
$shell_call .= "/dev/drbd/by-res/".$drbd_resource."/".$next_drbd_volume." ".$new_device_target." "; $shell_call .= "/dev/drbd/by-res/".$drbd_resource."/".$next_drbd_volume." ".$new_device_target." ";
$shell_call .= "--targetbus ".$disk_device_bus." "; $shell_call .= "--persistent --targetbus ".$disk_device_bus." ";
$shell_call .= "--cache ".$disk_cache." "; $shell_call .= "--cache ".$disk_cache." ";
$shell_call .= "--io ".$disk_io_policy." "; $shell_call .= "--io ".$disk_io_policy." ";
$shell_call .= "--sourcetype block --subdriver raw"; $shell_call .= "--sourcetype block --subdriver raw";
@ -1348,6 +1347,7 @@ sub manage_disk_add
if ($host_uuid eq $anvil->Get->host_uuid) if ($host_uuid eq $anvil->Get->host_uuid)
{ {
# Do the add here. # Do the add here.
update_definition($anvil, "define", "");
print "- Adding the drive to the server directly...\n"; print "- Adding the drive to the server directly...\n";
($output, $return_code) = $anvil->System->call({shell_call => $shell_call}); ($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
@ -1365,8 +1365,39 @@ sub manage_disk_add
$anvil->nice_exit({exit_code => 1}); $anvil->nice_exit({exit_code => 1});
} }
# Get the new XML
print "- Reading the updated server definition\n";
$shell_call = $anvil->data->{path}{exe}{setsid}." --wait ".$anvil->data->{path}{exe}{virsh}." dumpxml --inactive ".$server_name;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
(my $virsh_definition, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
virsh_definition => $virsh_definition,
return_code => $return_code,
}});
# Make sure the $output is valid XML.
print "- Validating the updated definition\n";
my $problem = $anvil->Server->parse_definition({
server => $server_name,
source => "from_virsh",
definition => $virsh_definition,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }});
if ($problem)
{
# Failed?!
print "
[ Error ] - The definition file read hear appears to be invalid after trying to attach the disk! It is unsafe
[ Error ] - to update the on disk and in DB definition. It's likely the attach has failed.
[ Error ] - Manual update to the server is likely required now.
";
$anvil->nice_exit({exit_code => 1});
}
print "- Updating the stored definition and undefining the server now...\n"; print "- Updating the stored definition and undefining the server now...\n";
update_definition($anvil, "define", ""); update_definition($anvil, "undefine", $virsh_definition);
print "Done!\n"; print "Done!\n";
$anvil->nice_exit({exit_code => 0}); $anvil->nice_exit({exit_code => 0});
} }
@ -1418,6 +1449,11 @@ sub manage_disk_add
$anvil->nice_exit({exit_code => 1}); $anvil->nice_exit({exit_code => 1});
} }
$anvil->data->{server}{$short_host_name}{$server_name}{from_virsh}{xml} = $virsh_definition;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"server::${short_host_name}::${server_name}::from_virsh::xml" => $anvil->data->{server}{$short_host_name}{$server_name}{from_virsh}{xml},
}});
print "- Updating the stored definition and undefining the server now...\n"; print "- Updating the stored definition and undefining the server now...\n";
update_definition($anvil, "undefine", $virsh_definition); update_definition($anvil, "undefine", $virsh_definition);
print "Done!\n"; print "Done!\n";
@ -2550,7 +2586,6 @@ sub update_definition
my $short_host_name = $anvil->Get->short_host_name; my $short_host_name = $anvil->Get->short_host_name;
my $server_name = $anvil->data->{switches}{server_name}; my $server_name = $anvil->data->{switches}{server_name};
my $server_uuid = $anvil->data->{switches}{server_uuid}; my $server_uuid = $anvil->data->{switches}{server_uuid};
my $server_definition = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_definition_xml};
my $server_host_uuid = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_host_uuid}; my $server_host_uuid = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_host_uuid};
my $server_state = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state}; my $server_state = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state};
my $definition_file = $anvil->data->{path}{directories}{shared}{definitions}."/".$server_name.".xml"; my $definition_file = $anvil->data->{path}{directories}{shared}{definitions}."/".$server_name.".xml";
@ -2559,7 +2594,6 @@ sub update_definition
's1:short_host_name' => $short_host_name, 's1:short_host_name' => $short_host_name,
's2:server_name' => $server_name, 's2:server_name' => $server_name,
's3:server_uuid' => $server_uuid, 's3:server_uuid' => $server_uuid,
's4:server_definition' => $server_definition,
's5:server_host_uuid' => $server_host_uuid, 's5:server_host_uuid' => $server_host_uuid,
's6:server_state' => $server_state, 's6:server_state' => $server_state,
's7:definition_file' => $definition_file, 's7:definition_file' => $definition_file,
@ -2590,7 +2624,23 @@ sub update_definition
my $disk_definition = $anvil->data->{server}{$short_host_name}{$server_name}{from_disk}{xml} ? $anvil->data->{server}{$short_host_name}{$server_name}{from_disk}{xml} : ""; my $disk_definition = $anvil->data->{server}{$short_host_name}{$server_name}{from_disk}{xml} ? $anvil->data->{server}{$short_host_name}{$server_name}{from_disk}{xml} : "";
my $virsh_definition = $anvil->data->{server}{$short_host_name}{$server_name}{from_virsh}{xml} ? $anvil->data->{server}{$short_host_name}{$server_name}{from_virsh}{xml} : ""; my $virsh_definition = $anvil->data->{server}{$short_host_name}{$server_name}{from_virsh}{xml} ? $anvil->data->{server}{$short_host_name}{$server_name}{from_virsh}{xml} : "";
my $use_definition = $virsh_definition; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:disk_definition' => $disk_definition,
's2:virsh_definition' => $virsh_definition,
}});
my $use_definition = "";
if ($definition)
{
# Use the passed in definition.
$use_definition = $definition;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { use_definition => $use_definition }});
}
else
{
$use_definition = $virsh_definition;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { use_definition => $use_definition }});
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { use_definition => $use_definition }});
if (not $use_definition) if (not $use_definition)
{ {
if (($server_running_here) or (($server_state eq "running") && ($virsh_definition))) if (($server_running_here) or (($server_state eq "running") && ($virsh_definition)))

Loading…
Cancel
Save