From 17078347ee1c133136ea4e72b96c38812f90a20a Mon Sep 17 00:00:00 2001 From: digimer Date: Sun, 3 Sep 2023 16:02:47 -0400 Subject: [PATCH 1/5] Reworked anvil-manage-server-storage to use the translation system. Signed-off-by: digimer --- man/anvil-change-password.8 | 2 +- man/anvil-manage-server-storage.8 | 37 ++ share/words.xml | 222 +++++++++- tools/anvil-manage-server-storage | 688 ++++++++++++++++++------------ 4 files changed, 675 insertions(+), 274 deletions(-) diff --git a/man/anvil-change-password.8 b/man/anvil-change-password.8 index faaeece6..80387352 100644 --- a/man/anvil-change-password.8 +++ b/man/anvil-change-password.8 @@ -4,7 +4,7 @@ .SH NAME anvil-change-password \- Tool used to change / reset the main Anvil! password. .SH SYNOPSIS -.B alteeve-repo-setup +.B anvil-change-password \fI\, \/\fR[\fI\,options\/\fR] .SH DESCRIPTION anvil-change-password \- This is used to change / reset the password on a Striker dashboard. Alternatively, if '--anvil' is used, to change / reset the password on an Anvil! node pair. diff --git a/man/anvil-manage-server-storage.8 b/man/anvil-manage-server-storage.8 index e69de29b..58e9f888 100644 --- a/man/anvil-manage-server-storage.8 +++ b/man/anvil-manage-server-storage.8 @@ -0,0 +1,37 @@ +.\" Manpage for the Anvil! server storage manager +.\" Contact mkelly@alteeve.com to report issues, concerns or suggestions. +.TH anvil-manage-server-storage "8" "August 30 2023" "Anvil! Intelligent Availability™ Platform" +.SH NAME +anvil-manage-server-storage \- Tool used to manage the storage of a hosted server. +.SH SYNOPSIS +.B anvil-manage-server-storage +\fI\, \/\fR[\fI\,options\/\fR] +.SH DESCRIPTION +anvil-manage-server-storage \- This tool is used to add a disk, grow an existing disk, change the ISO (optical disk) in a virtual optical drive, and change boot devices. +.TP +.SH OPTIONS +.TP +\-?, \-h, \fB\-\-help\fR +Show this man page. +.TP +\fB\-\-log-secure\fR +When logging, record sensitive data, like passwords. +.TP +\-v, \-vv, \-vvv +Set the log level to 1, 2 or 3 respectively. Be aware that level 3 generates a significant amount of log data. +.SS "Commands:" + +.TP +\fB\-\-add\fR +The size can be in percent, ie: '50%' or '100%', a number in bytes, or a human-readable size. Human readable sizes must NOT have a space between the number and letter suffix. Also, base2 vs base10 notation! Ie: '1GiB' = 1,073,741,824 bytes', '1GB' == '1,000,000,000 bytes'. A single letter used to denote size will be interpreted as base2. ie: '1G == 1GiB'. +.TP +\fB\-\-anvil\fR + +.TP +\fB\-\-\fR + +.IP +.SH AUTHOR +Written by Madison Kelly, Alteeve staff and the Anvil! project contributors. +.SH "REPORTING BUGS" +Report bugs to users@clusterlabs.org diff --git a/share/words.xml b/share/words.xml index 13db2924..066c8435 100644 --- a/share/words.xml +++ b/share/words.xml @@ -204,7 +204,10 @@ The error was: Failed to start the daemon: [#!variable!daemon!#] on [#!variable!host!#], unable to boot the server. System->test_ipmi() was called with an invalid 'lanplus' parameter. It must be 'yes', 'no', 'yes-no' or 'no-yes'. Received: [#!variable!lanplus!#]. All attempts to change the IPMI user: [#!variable!user_name!#] (number: [#!variable!user_number!#] failed. The last try's output (if any) was: [#!variable!output!#] (return code: [#!variable!return code!#]). - The system call: [#!variable!shell_call!#] failed. The output (if any) was: [#!variable!output!#] (return code: [#!variable!return code!#]). + The system call: [#!variable!shell_call!#] failed with the return code: [#!variable!return code!#]. The output (if any) was; +==== +#!variable!output!# +==== The DRBD global common config file: [#!data!path::configs::global-common.conf!#] doesn't exist, unable to update it. Failed to parse the JSON string: @@ -609,6 +612,119 @@ The error was: ======== Failed to enable dual-primary for the resource: [#!variable!resource!#]! The peer: [#!variable!peer_name!#]'s connection state is: [#!variable!connection_state!#] (must be 'connected'). Failed to enable dual-primary for the server: [#!variable!server!#]! The call to enable dual-primary, necessary for the live migration, returned a non-zero return code: [#!variable!return_code!#]. + [ Error ] - Please specify the size you would like to grow this disk by. The maximum size is: [#!variable!free_space!#]. + [ Error ] - The requested size: [#!variable!add_size!#] could not be interpreted. + [ Error ] - Failed to find a new target device name. + [ Error ] - Failed to find a new DRBD volume to use. + [ Error ] - Adding a new disk requires all peers to be online. + - Peer: [#!variable!host_name!#] is: [#!variable!access!#]. + [ Error ] - It would appear that we've lost access to a peer while waiting for the answer. + Failed! +[ Error ] - The new DRBD resource config appears to be invalid, which is likely a program error. The new +[ Error ] - config was written to the test file: [#!variable!test_file!#]. +[ Error ] - The test to confirm it was valid exited with the return code: [#!variable!return_code!#], expected '0'. +[ Error ] - The output, if anything, was: +==== +#!variable!output!# +==== + + +[ Error ] - There was a problem copying the new config file! Unable to proceed. +[ Error ] - Manual intervention to complete the update is required! + + Failed! +[ Error ] - The peers did not connect in the expected period of time. + Failed! +[ Error ] - There was a problem trying to force the new volume: [#!variable!drbd_resource!#/#!variable!next_drbd_volume!#] to Primary. +[ Error ] - Attempted this using the shell call: [#!variable!shell_call!#]. +[ Error ] - Expected the return code '0' but got: [#!variable!return_code!#]. The output, if any, was: +========== +#!variable!output!# +========== +[ Error ] - Once corrected, please manually add the new volume to the server. + + +[ 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. + + +[ Error ] - The definition file read from the remote host appears to be invalid after trying to attach the +[ Error ] - disk! It is unsafe 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. + + [ Error ] - Please specify the size you would like to grow this disk by. The maximum size is: [#!variable!max_free_space!#]. + [ Error ] - The requested size: [#!variable!add_size!#] could not be interpreted. + [ Error ] - The requested size: [#!variable!add_size!#] is too small, it's less than an single extent. + [ Error ] - The requested size: [#!variable!add_size!#] is too large. The available size is: [#!variable!max_free_space!#]. + [ Error ] - Growing the storage requires all peers to be online. + [ Error ] - It would appear that we've lost access to a peer while waiting for the answer. + Error! +[ Failed ] - When trying to grow the local logical volume: [#!variable!backing_disk!#] +[ Failed ] - using the command: [#!variable!shell_call!#] +[ Failed ] - The return code: [#!variable!return_code!#] was received, expected '0'. Output, if any: +========== +#!variable!output!# +========== +The extension of the resource is incomplete, manual intervention is required! +[ Warning ] - Do NOT re-run this command! The backing devices may not have mis-matched sized! + Error! +[ Failed ] - When trying to grow the peer's logical volume: [#!variable!backing_disk!#] +[ Failed ] - using the command: [#!variable!shell_call!#] +[ Failed ] - The return code: [#!variable!return_code!#] was received, expected '0'. Output, if any: +==] STDOUT [======== +#!variable!output!# +==] STDERR [======== +#!variable!error!# +==================== +The extension of the resource is incomplete, manual intervention is required! +[ Warning ] - Do NOT re-run this command! The backing devices may not have mis-matched sized! + Error! +[ Failed ] - When trying to grow the DRBD device: [#!variable!drbd_resource!#/#!variable!drbd_volume!#] +[ Failed ] - using the command: [#!variable!shell_call!#] +[ Failed ] - The return code: [#!variable!return_code!#] was received, expected '0'. Output, if any: +========== +print $output!# +========== +The extension of the resource is incomplete, manual intervention is required!! +[ Note ] - All backing devices have been grown. Manually resolving the drbd grow +[ Note ] - error should complete the drive expansion! + '.]]> + + + + ' to replace it with a different disc image.]]> + ' to insert a disc image.]]> + + + + + + '.]]> + '.]]> + + + + @@ -2414,6 +2530,69 @@ The file: [#!variable!file!#] needs to be updated. The difference is: Adjusting the resource: [#!variable!resource!#] to ensure it's compatible with the peer's config prior to connection. The local resource: [#!variable!resource!#] is StandAlone, attempting to connect. Failed to connect to the host: [#!variable!host!#]! Unable to up the resource on it. The volume(s) backing this server are UpToDate locally, so booting should be fine. + - Creating the new local LV: [#!variable!backing_disk!#]... + - Target: [#!variable!device_target!#], boot: [#!variable!say_boot!#], path: [#!variable!device_path!#], Available space: [#!variable!max_free_space!#] + Done! + - Testing the updated DRBD resource config file to ensure the new volumes are cromulent... + Success! + - Copying the new resource file to out peers. + - Copying: [#!variable!resource_file!#] to: [#!variable!host_name!#:#!variable!destination!#] via: [#!variable!use_ip!#]. + - Creating the replicated storage metadata on the new backing devices now. + - Creating the new LV on the peer: [#!variable!host_name!#:#!variable!backing_disk!#], via: [#!variable!use_ip!# (#!variable!use_network!#)] + - Writing out the updated DRBD config file. + - Creating the meta-data on the new local volume: [#!variable!next_drbd_volume!#]... + - Creating the meta-data on the peer: [#!variable!host_name!#:#!variable!drbd_resource!#/#!variable!next_drbd_volume!#], via: [#!variable!use_ip!# (#!variable!use_network!#)] + - Registered a job with job UUID: [#!variable!job_uuid!#] to reload the resource config on the host: [#!variable!short_host_name!#]. + - Adjusting the local resource: [#!variable!drbd_resource!#] to pick up the new config. +[ NOTE ] - If this hangs, make sure 'anvil-daemon' is running on the peers. + - Waiting for all peers to connect the new volume... + - Peers are connected! Checking if the new volume requires initial sync. + - Initial sync required! + - Forcing primary locally... + - The resource is primary on the peer: [#!variable!host_name!#], forcing primary there via: [#!variable!use_ip!# (#!variable!use_network!#)]. + - Initial sync does not appear to be required. + - Ready to add the new disk. Checking if the server is running... + - The server is running on this host, we'll attach the disk here. + - The server is running on: [#!variable!server_host!#], we'll attach the disk there. + - The server isn't running anywhere, we'll attach the disk offline on this host. + - Defining the server: [#!variable!server_name!#] to prepare for 'virsh' modification of the server. + - Adding the drive to the definition now. + - Updating the stored definition and undefining the server now... + - Adding the drive to the server directly... + - Reading the updated server definition + - Validating the updated definition + - Updating the stored definition and undefining the server now... + - Adding the drivve to the server using its host: [#!variable!server_host!#] via: [#!variable!use_ip!#]... + - Updating the stored definition and undefining the server now... + - The peer: [#!variable!peer_name!#], is stuck 'Negotiating'; disconnecting... + reconnecting... + - Waiting for the disk state to be updated: + - Connected, checking volume: [#!variable!drbd_resource!#/#!variable!next_drbd_volume!#] disk state: + Not Connected yet. + Disk not ready yet. + Ready! +- Disk state is: [#!variable!peer_disk_state!#] + - Timed out waiting for the peer to connect. + [ Note ] - The size can be in percent, ie: '50%' or '100%', a number in bytes, or a human-readable size. + - Human readable sizes must NOT have a space between the number and letter suffix. Also, base2 + - vs base10 notation! Ie: '1GiB' = 1,073,741,824 bytes', '1GB' == '1,000,000,000 bytes'. A single + - letter used to denote size will be interpreted as base2. ie: '1G == 1GiB'. + - Preparing to grow the storage by: [#!variable!size!#]... + - Extending local LV: [#!variable!backing_disk!#]... + - Extending peer: [#!variable!host_name!#:#!variable!backing_disk!#], via: [#!variable!use_ip!# (#!variable!use_network!#)] + - Extending backing devices complete. Now extending DRBD resource/volume... + - Calling scancore agents to ensure the database has the new storage config recorded. + - Running scan agent: [#!variable!agent!#] locally... + - Running scan agent: [#!variable!agent!#] on: [#!variable!host_name!#] via: [#!variable!use_ip!# (#!variable!use_network!#)]... + [ Success ] - Expansion is complete! +[ Note ] - Depending on your OS, you may need to power the server off, and then power it back on +[ Note ] - for the new space to be visible. Typically, powering off the server from the guest OS +[ Note ] - and waiting for the Anvil! to boot it back up will do the job nicely. + Defining the server: [#!variable!server_name!#] to prepare for 'virsh' modification of the server. + - Inserting: [#!variable!insert!#] into the drive: [#!variable!device_target!#]. + - Ejecting: [#!variable!device_path!#] from: [#!variable!device_target!#]. + Updating the stored definition and undefining the server now: + Working with the server: [#!variable!server_name!#], UUID: [#!variable!server_uuid!#] The host name: [#!variable!target!#] does not resolve to an IP address. @@ -2933,6 +3112,28 @@ Proceed? [y/N] [ Note ] - It looks like 'anvil-version-changes' (pid(s): [#!variable!pids!#]) is running, holding off on power action until it's done (in case the system is being updated now or kernel modules are being built). [ Note ] - The DRBD (replicated storage) kernel module appears to not exist. This is normal after an OS update, will try building the kernel module now. Please be patient. [ Note ] - Deleting the old drbd fenced attribute: [#!variable!attribute!#] for the node: [#!variable!node_name!#] (ID: [#!variable!node_id!#]) from the CIB. + [ Note ] - The size can be in percent, ie: '50%' or '100%', a number in bytes, or a human-readable size. + - Human readable sizes must NOT have a space between the number and letter suffix. Also, base2 + - vs base10 notation! Ie: '1GiB' = 1,073,741,824 bytes', '1GB' == '1,000,000,000 bytes'. A single + - letter used to denote size will be interpreted as base2. ie: '1G == 1GiB'. + + up + down + - New drive target: [#!variable!new_device_target!#], size: [#!variable!hr_size!#], bus: [#!variable!disk_device_bus!#], cache: [#!variable!disk_cache!#], IO policy: [#!variable!disk_io_policy!#] +- Preparing to add a the drive: [#!variable!drbd_resource!#/#!variable!next_drbd_volume!#] using the storage group: [#!variable!storage_group_name!#]... + Disk Drives: + Optical Drives: + - Target: [#!variable!device_target!#], boot: [#!variable!say_boot!#], Replication Volume: [#!variable!drbd_resource!#/#!variable!drbd_volume!#] + |- Resource / LV / Metadata sizes: [#!variable!resource_size!# / #!variable!lv_size!# / #!variable!metadata_size!#], free space: [#!variable!max_free_space!#] + - Target: [#!variable!device_target!#], boot: [#!variable!say_boot!#], ISO: [#!variable!device_path!#] + Sub-Nodes: + DR Hosts: + |- Name: [#!variable!host_name!#], UUID: [#!ariable!host_uuid!#] + |- Volume: [#!variable!volume_number!#], backing device: [#!variable!backing_disk!#], DRBD minor: [#!variable!device_minor!#], size: [#!variable!volume_size!#] + ^- In storage group: [#!variable!storage_group_name!#], size: [#!variable!storage_group_size!#], free: [#!variable!storage_group_free_space!#] + Anvil! Node: [#!variable!anvil_name!#], UUID: [#!variable!anvil_uuid!#] - Description: [#!variable!anvil_description!#] + - No servers on this node yet + ^- Server: [#!variable!server_name!#], UUID: [#!variable!server_uuid!#] Normal Password @@ -3671,6 +3872,25 @@ We will wait: [#!variable!waiting!#] seconds and then try again. We'll give up i [ Warning ] - The file: [#!variable!file_path!#] needed to provision the server: [#!variable!server_name!#] was found, but it's not ready yet. [ Warning ] - Waiting for a bit, and then will check if files are ready. [ Warning ] - There is a duplicate storage group named: [#!variable!group_name!#]. Keeping the group with UUID: [#!variable!keep_uuid!#], and deleting the group with the UUID: [#!variable!delete_uuid!#] + Please specify a storage group to use to add the new drive to. + Warning! +[ Warning ] - When trying to create the local meta-data on: [#!variable!drbd_resource!#/#!variable!next_drbd_volume!#] +[ Warning ] - using the command: [#!variable!shell_call!#] +[ Warning ] - The return code: [#!variable!return_code!#] was received, expected '0'. Output, if any: +========== +#!variable!output!# +========== +We will try to proceed anyway. + Warning!\n"; +[ Warning ] - When trying to create the peer: [#!variable!host_name!#]'s meta-data on: [#!variable!drbd_resource!#/#!variable!next_drbd_volume!#] +[ Warning ] - using the command: [#!variable!shell_call!#] +[ Warning ] - The return code: [#!variable!return_code!#] was received, expected '0'. Output, if any: +==] STDOUT [======== +#!variable!output!# +==] STDERR [======== +#!variable!error!# +==================== +We will try to proceed anyway. diff --git a/tools/anvil-manage-server-storage b/tools/anvil-manage-server-storage index 69d7b7de..fc69bf26 100755 --- a/tools/anvil-manage-server-storage +++ b/tools/anvil-manage-server-storage @@ -46,6 +46,7 @@ $anvil->Get->switches({list => [ "confirm", "disk", "eject", + "job-uuid", "grow", "insert", "optical", @@ -86,7 +87,7 @@ if (not $anvil->data->{switches}{server}) { # Show the list of servers. show_server_list($anvil); - print "\nPlease specify which server you want to modify using '--server '.\n\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0456"}); $anvil->nice_exit({exit_code => 0}); } @@ -193,7 +194,7 @@ sub manage_disk if (not $anvil->data->{switches}{disk}) { # Can't proceed. - print "\n[ Error ] - Please indicate the disk drive to work with using '--disk --drive '.\n\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0457"}); show_server_details($anvil); $anvil->nice_exit({exit_code => 1}); } @@ -281,14 +282,16 @@ sub manage_disk { # User didn't specify a device. show_server_details($anvil); - print "\n[ Error ] - Please specify the disk drive target you want to work on.\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0458"}); $anvil->nice_exit({exit_code => 1}); } elsif (not exists $anvil->data->{server}{$short_host_name}{$server_name}{$from_source}{device}{disk}{target}{$device_target}) { # Invalid device target show_server_details($anvil); - print "\n[ Error ] - The disk drive target: [".$device_target."] wasn't found.\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0459", variables => { + device_target => $device_target, + }}); $anvil->nice_exit({exit_code => 1}); } @@ -332,8 +335,12 @@ sub manage_disk 's18:drbd_volume' => $drbd_volume, 's19:max_free_space' => $max_free_space." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $max_free_space}).")", }}); - #print "- Target: [".$device_target."], boot: [".$say_boot."], path: [".$device_path."], cache: [".$driver_cache."], driver type: [".$driver_type."]\n"; - print "- Target: [".$device_target."], boot: [".$say_boot."], path: [".$device_path."], Available space: [".$anvil->Convert->bytes_to_human_readable({'bytes' => $max_free_space})."]\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0749", variables => { + device_target => $device_target, + say_boot => $say_boot, + device_path => $device_path, + max_free_space => $anvil->Convert->bytes_to_human_readable({'bytes' => $max_free_space}), + }}); # What are we doing? if ($anvil->data->{switches}{grow}) @@ -366,17 +373,13 @@ sub manage_disk_add }}); # Are they asking for an available amount of space? - my $error_note = q| -[ Note ] - The size can be in percent, ie: '50%' or '100%', a number in bytes, or a human-readable size. - - Human readable sizes must NOT have a space between the number and letter suffix. Also, base2 - - vs base10 notation! Ie: '1GiB' = 1,073,741,824 bytes', '1GB' == '1,000,000,000 bytes'. A single - - letter used to denote size will be interpreted as base2. ie: '1G == 1GiB'. -|; + my $say_up = $anvil->Words->string({key => 'message_0331'}); + my $say_down = $anvil->Words->string({key => 'message_0332'}); # Do we have a storage group? if (not $anvil->data->{switches}{'storage-group'}) { - print "Please specify a storage group to use to add the new drive to.\n"; + print $anvil->Words->string({key => 'warning_0159'})."\n"; short_storage_groups($anvil, $anvil_uuid); $anvil->nice_exit({exit_code => 1}); } @@ -420,8 +423,10 @@ sub manage_disk_add elsif ($add_size !~ /\d/) { # No digits, probably didn't set a value at all. - print "\n[ Error ] - Please specify the size you would like to grow this disk by. The maximum size is: [".$anvil->Convert->bytes_to_human_readable({'bytes' => $free_space})."].\n"; - print $error_note."\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0423", variables => { + free_space => $anvil->Convert->bytes_to_human_readable({'bytes' => $free_space}), + }}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "message_0330"}); $anvil->nice_exit({exit_code => 1}); } elsif ($add_size !~ /^\d+$/) @@ -440,8 +445,8 @@ sub manage_disk_add else { # Not a valid size. - print "\n[ Error ] - The requested size: [".$add_size."] could not be interpreted.\n"; - print $error_note."\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0424", variables => { add_size => $add_size }}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "message_0330"}); $anvil->nice_exit({exit_code => 1}); } } @@ -504,7 +509,8 @@ sub manage_disk_add if (not $new_device_target) { - print "\n[ Error ] - Failed to find a new target device name.\n"; + # Failed to find a new target device name + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0425"}); $anvil->nice_exit({exit_code => 1}); } @@ -538,7 +544,8 @@ sub manage_disk_add if ($next_drbd_volume eq "") { - print "\n[ Error ] - Failed to find a new DRBD volume to use.\n"; + # Failed to find a new DRBD volume to use. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0426"}); $anvil->nice_exit({exit_code => 1}); } } @@ -551,26 +558,40 @@ sub manage_disk_add if (not $all_online) { - print "\n[ Error ] - Adding a new disk requires all peers to be online.\n"; + ### TODO: Sleep for 60 and then reset the job_progress to 0 and exit so that we keep trying. + # Adding a new disk requires all peers to be online. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0427"}); foreach my $short_host_name (sort {$a cmp $b} keys %{$anvil->data->{peer}}) { - my $say_access = $anvil->data->{peer}{$short_host_name}{access_ip} ? "up." : "down!"; - print " - Peer: [".$short_host_name."] is ".$say_access."\n"; + # Record the access + my $say_access = $anvil->data->{peer}{$short_host_name}{access_ip} ? $say_up : $say_down; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0428", variables => { + host_name => $short_host_name, + access => $say_access, + }}); } $anvil->nice_exit({exit_code => 1}); } # Still alive? Ask the user to confirm. - print "- New drive target: [".$new_device_target."], size: [".$hr_size."], bus: [".$disk_device_bus."], cache: [".$disk_cache."], IO policy: [".$disk_io_policy."]\n"; - print "- Preparing to add a the drive: [".$drbd_resource."/".$next_drbd_volume."] using the storage group: [".$storage_group_name."]...\n"; - if (not $anvil->data->{switches}{confirm}) + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0428", variables => { + new_device_target => $new_device_target, + hr_size => $hr_size, + disk_device_bus => $disk_device_bus, + disk_cache => $disk_cache, + disk_io_policy => $disk_io_policy, + drbd_resource => $drbd_resource, + next_drbd_volume => $next_drbd_volume, + storage_group_name => $storage_group_name, + }}); + if ((not $anvil->data->{switches}{confirm}) && (not $anvil->data->{switches}{'job-uuid'})) { print $anvil->Words->string({key => "message_0021"})." "; my $answer = ; chomp($answer); if ($answer !~ /^y/i) { - print "Aborting.\n"; + print $anvil->Words->string({key => "message_0022"})."\n"; $anvil->nice_exit({exit_code => 0}); } @@ -580,11 +601,16 @@ sub manage_disk_add if (not $all_online) { - print "\n[ Error ] - It would appear that we've lost access to a peer while waiting for the answer.\n"; + # It would appear that we've lost access to a peer while waiting for the answer. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0429"}); foreach my $short_host_name (sort {$a cmp $b} keys %{$anvil->data->{peer}}) { - my $say_access = $anvil->data->{peer}{$short_host_name}{access_ip} ? "up." : "down!"; - print " - Peer: [".$short_host_name."] is ".$say_access."\n"; + # Record the access + my $say_access = $anvil->data->{peer}{$short_host_name}{access_ip} ? $say_up : $say_down; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0428", variables => { + host_name => $short_host_name, + access => $say_access, + }}); } $anvil->nice_exit({exit_code => 1}); } @@ -634,7 +660,8 @@ sub manage_disk_add }}); if ($host_uuid eq $anvil->Get->host_uuid) { - print " - Creating the new local LV: [".$backing_disk."]..."; + # Creating the new local LV + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0748", variables => { backing_disk => $backing_disk }}); my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { output => $output, @@ -642,26 +669,30 @@ sub manage_disk_add }}); if ($return_code) { - print " Error!\n"; - print "[ FAILED ] - When trying to create the new local logical volume: [".$backing_disk."]\n"; - print "[ FAILED ] - using the command: [".$shell_call."]\n"; - print "[ FAILED ] - The return code: [".$return_code."] was received, expected '0'. Output, if any:\n"; - print "==========\n"; - print $output."\n"; - print "==========\n"; - print "The creation of the new replicatedd disk is incomplete, manual intervention is required!!\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0460", variables => { + backing_disk => $backing_disk, + shell_call => $shell_call, + return_code => $return_code, + output => $output, + }}); $anvil->nice_exit({exit_code => 1}); } else { - print " Done!\n"; + # Done! + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); } } else { my $use_ip = $anvil->data->{peer}{$short_host_name}{access}{ip}; my $use_network = $anvil->data->{peer}{$short_host_name}{access}{network}; - print " - Creating the new LV on the peer: [".$short_host_name.":".$backing_disk."], via: [".$use_ip." (".$use_network.")]"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0756", variables => { + host_name => $short_host_name, + backing_disk => $backing_disk, + use_ip => $use_ip, + network => $use_network, + }}); my ($output, $error, $return_code) = $anvil->Remote->call({ shell_call => $shell_call, target => $use_ip, @@ -673,21 +704,20 @@ sub manage_disk_add }}); if ($return_code) { - print " Error!\n"; - print "[ FAILED ] - When trying to create the peer: [".$short_host_name."]'s logical volume: [".$backing_disk."]\n"; - print "[ FAILED ] - using the command: [".$shell_call."]\n"; - print "[ FAILED ] - The return code: [".$return_code."] was received, expected '0'. Output, if any:\n"; - print "==] STDOUT [========\n"; - print $output."\n"; - print "==] STDERR [========\n"; - print $error."\n"; - print "====================\n"; - print "The creation of the new replicated disk is incomplete, manual intervention is required!!\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0461", variables => { + host_name => $short_host_name, + backing_disk => $backing_disk, + shell_call => $shell_call, + return_code => $return_code, + output => $output, + error => $error, + }}); $anvil->nice_exit({exit_code => 1}); } else { - print " Done!\n"; + # Done! + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); } } } @@ -783,7 +813,7 @@ sub manage_disk_add $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }}); # Validate. - print "- Testing the updated DRBD resource config file to ensure the new volumes are cromulent..."; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0751"}); my $shell_call = $anvil->data->{path}{exe}{drbdadm}." --config-to-test ".$test_file." --config-to-exclude ".$drbd_res_file." sh-nop"; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }}); my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call}); @@ -794,25 +824,22 @@ sub manage_disk_add if ($return_code) { # Something went wrong. - print " Failed! -[ Error ] - The new DRBD resource config appears to be invalid, which is likely a program error. The new -[ Error ] - config was written to the test file: [".$test_file."]. -[ Error ] - The test to confirm it was valid exited with the return code: [".$return_code."], expected '0'. -[ Error ] - The output, if anything, was: -==== -".$output." -==== -"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0430", variables => { + test_file => $test_file, + return_code => $return_code, + output => $output, + }}); $anvil->nice_exit({exit_code => 1}); } - print " Success!\n"; + # Success! + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0752"}); # Remove the test file. unlink $test_file; # Backup the res file so we can tell the user where the current config was backed up to in # case they need to restore it. - print "- Writing out the updated DRBD config file.\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0757"}); my ($backup_file) = $anvil->Storage->backup({file => $drbd_res_file}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { backup_file => $backup_file }}); @@ -828,9 +855,9 @@ sub manage_disk_add mode => "0644", }); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { backup_file => $backup_file }}); -# + # Copy this to our peers. - print "- Copying the new resource file to out peers.\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0753"}); foreach my $host_type ("node", "dr") { foreach my $short_host_name (sort {$a cmp $b} keys %{$anvil->data->{drbd_resource}{$drbd_resource}{host_type}{$host_type}{short_host_name}}) @@ -841,7 +868,12 @@ sub manage_disk_add my $use_ip = $anvil->data->{peer}{$short_host_name}{access}{ip}; my $destination = "root\@".$use_ip.":".$anvil->data->{path}{directories}{drbd_resources}."/"; $destination =~ s/\/\//\//g; - print " - Copying: [".$drbd_res_file."] to: [".$short_host_name.":".$destination."] via: [".$use_ip."]\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0754", variables => { + resource_file => $drbd_res_file, + host_name => $short_host_name, + destination => $destination, + use_ip => $use_ip, + }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { use_ip => $use_ip, destination => $destination, @@ -856,17 +888,15 @@ sub manage_disk_add if ($failed) { - print " -[ Error ] - There was a problem copying the new config file! Unable to proceed. -[ Error ] - Manual intervention to complete the update is required! -"; + # There was a problem copying the new config file! + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0431"}); $anvil->nice_exit({exit_code => 1}); } } } # Create the metadata. - print "- Creating the replicated storage metadata on the new backing devices now.\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0755"}); foreach my $host_type ("node", "dr") { foreach my $short_host_name (sort {$a cmp $b} keys %{$anvil->data->{drbd_resource}{$drbd_resource}{host_type}{$host_type}{short_host_name}}) @@ -883,7 +913,9 @@ sub manage_disk_add # a previous pass. if ($host_uuid eq $anvil->Get->host_uuid) { - print " - Creating the meta-data on the new local volume: [".$next_drbd_volume."]..."; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0758", variables => { + next_drbd_volume => $next_drbd_volume, + }}); my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { output => $output, @@ -896,25 +928,32 @@ sub manage_disk_add # 3 == Configuration not found. if ($return_code) { - print " Warning!\n"; - print "[ Warning ] - When trying to create the local meta-data on: [".$drbd_resource."/".$next_drbd_volume."]\n"; - print "[ Warning ] - using the command: [".$shell_call."]\n"; - print "[ Warning ] - The return code: [".$return_code."] was received, expected '0'. Output, if any:\n"; - print "==========\n"; - print $output."\n"; - print "==========\n"; - print "We will try to proceed anyway.\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "alert", key => "warning_0160", variables => { + drbd_resource => $drbd_resource, + next_drbd_volume => $next_drbd_volume, + shell_call => $shell_call, + return_code => $return_code, + output => $output, + }}); } else { - print " Done!\n"; + # Done! + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); } } else { + # Create the meta-data on the peer my $use_ip = $anvil->data->{peer}{$short_host_name}{access}{ip}; my $use_network = $anvil->data->{peer}{$short_host_name}{access}{network}; - print " - Creating the meta-data on the peer: [".$short_host_name.":".$drbd_resource."/".$next_drbd_volume."], via: [".$use_ip." (".$use_network.")]"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0759", variables => { + host_name => $short_host_name, + drbd_resource => $drbd_resource, + next_drbd_volume => $next_drbd_volume, + use_ip => $use_ip, + network => $use_network, + }}); my ($output, $error, $return_code) = $anvil->Remote->call({ shell_call => $shell_call, target => $use_ip, @@ -926,20 +965,20 @@ sub manage_disk_add }}); if ($return_code) { - print " Warning!\n"; - print "[ Warning ] - When trying to create the peer: [".$short_host_name."]'s meta-data on: [".$drbd_resource."/".$next_drbd_volume."]\n"; - print "[ Warning ] - using the command: [".$shell_call."]\n"; - print "[ Warning ] - The return code: [".$return_code."] was received, expected '0'. Output, if any:\n"; - print "==] STDOUT [========\n"; - print $output."\n"; - print "==] STDERR [========\n"; - print $error."\n"; - print "====================\n"; - print "We will try to proceed anyway.\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "alert", key => "warning_0161", variables => { + host_name => $short_host_name, + drbd_resource => $drbd_resource, + next_drbd_volume => $next_drbd_volume, + shell_call => $shell_call, + return_code => $return_code, + output => $output, + error => $error, + }}); } else { - print " Done!\n"; + # Done! + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); } } } @@ -974,12 +1013,16 @@ sub manage_disk_add }); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }}); - print "- Registered a job with job UUID: [".$job_uuid."] to reload the resource config on the host: [".$short_host_name."].\n"; + # Record that we registered the job to reload the resource + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0760", variables => { + host_name => $short_host_name, + job_uuid => $job_uuid, + }}); } } - print "- Adjusting the local resource: [".$drbd_resource."] to pick up the new config.\n"; - print "[ NOTE ] - If this hangs, make sure 'anvil-daemon' is running on the peers.\n"; + # Warn the user to check that anvil-daemon is running in case this hangs. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0761", variables => { drbd_resource => $drbd_resource }}); $shell_call = $anvil->data->{path}{exe}{drbdadm}." adjust ".$drbd_resource; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }}); ($output, $return_code) = $anvil->System->call({ @@ -993,7 +1036,7 @@ sub manage_disk_add # Find which node is currently Primary and use that host to force primary to start sync. If none, # force here. - print "- Waiting for all peers to connect the new volume...\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0762"}); my $waiting = 1; my $wait_until = time + 300; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { wait_until => $wait_until }}); @@ -1100,14 +1143,16 @@ sub manage_disk_add { if (time > $wait_until) { - print "\nFailed!\n[ Error ] - The peers did not connect in the expected period of time.\n"; + # The peers did not connect in the expected period of time. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0432"}); $anvil->nice_exit({exit_code => 1}); } sleep 2; } } - print "- Peers are connected! Checking if the new volume requires initial sync.\n"; + # Peers are connected! Checking if the new volume requires initial sync. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0763"}); my $all_inconsistent = 1; my $primary_on_host = ""; foreach my $peer_name (sort {$a cmp $b} keys %{$anvil->data->{peers}}) @@ -1134,7 +1179,7 @@ sub manage_disk_add if ($all_inconsistent) { - print "- Initial sync required!\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0764"}); my $shell_call = $anvil->data->{path}{exe}{drbdadm}." new-current-uuid --force-resync ".$drbd_resource."/".$next_drbd_volume; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }}); @@ -1156,7 +1201,8 @@ sub manage_disk_add $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { primary_on_host_uuid => $primary_on_host_uuid }}); if ($primary_on_host_uuid eq $anvil->Get->host_uuid) { - print "- Forcing primary locally... "; + # Forcing primary locally... + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0765"}); my ($output, $return_code) = $anvil->System->call({debug => 2, shell_call => $shell_call}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { output => $output, @@ -1165,15 +1211,14 @@ sub manage_disk_add # Return code of '0' is success. if ($return_code) { - print "Failed! -[ Error ] - There was a problem trying to force the new volume: [".$drbd_resource."/".$next_drbd_volume."] to Primary. -[ Error ] - Attempted this using the shell call: [".$shell_call."]. -[ Error ] - Expected the return code '0' but got: [".$return_code."]. The output, if any, was: -========== -".$output." -========== -[ Error ] - Once corrected, please manually add the new volume to the server. -"; + # There was a problem trying to force the new volume to Primary. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0430", variables => { + drbd_resource => $drbd_resource, + next_drbd_volume => $next_drbd_volume, + shell_call => $shell_call, + return_code => $return_code, + output => $output, + }}); $anvil->nice_exit({exit_code => 1}); } @@ -1186,7 +1231,8 @@ sub manage_disk_add output => $output, return_code => $return_code, }}); - print "Success!\n"; + # Success! + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0752"}); } else { @@ -1196,7 +1242,12 @@ sub manage_disk_add use_ip => $use_ip, use_network => $use_network, }}); - print " - The resource is primary on the peer: [".$short_host_name."], forcing primary there via: [".$use_ip." (".$use_network.")]"; + # The resource is primary on the peer, force Primary over there. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0766", variables => { + host_name => $short_host_name, + use_ip => $use_ip, + use_network => $use_network, + }}); my ($output, $error, $return_code) = $anvil->Remote->call({ shell_call => $shell_call, target => $use_ip, @@ -1208,15 +1259,13 @@ sub manage_disk_add }}); if ($return_code) { - print "Failed! -[ Error ] - There was a problem trying to force the new volume: [".$drbd_resource."/".$next_drbd_volume."] to Primary. -[ Error ] - Attempted this using the shell call: [".$shell_call."]. -[ Error ] - Expected the return code '0' but got: [".$return_code."]. The output, if any, was: -========== -".$output." -========== -[ Error ] - Once corrected, please manually add the new volume to the server. -"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0430", variables => { + drbd_resource => $drbd_resource, + next_drbd_volume => $next_drbd_volume, + shell_call => $shell_call, + return_code => $return_code, + output => $output, + }}); $anvil->nice_exit({exit_code => 1}); } @@ -1232,16 +1281,18 @@ sub manage_disk_add error => $error, return_code => $return_code, }}); - print "Success!\n"; + # Success! + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0752"}); } } else { - print "- Initial sync does not appear to be required.\n"; + # Initial sync does not appear to be required. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0767"}); } # Is the server running? If so, where. - print "- Ready to add the new disk. Checking if the server is running...\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0768"}); my $server_host = ""; foreach my $host_type ("node", "dr") { @@ -1281,11 +1332,15 @@ sub manage_disk_add $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { server_host => $server_host }}); if ($host_uuid eq $anvil->Get->host_uuid) { - print "- The server is running on this host, we'll attach the disk here.\n"; + # The server is running on this host, we'll attach the disk here. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0769"}); } else { - print "- The server is running on: [".$server_host."], we'll attach the disk there.\n"; + # The server is running on the peer, we'll attach the disk there. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0770", variables => { + server_host => $server_host, + }}); } last; } @@ -1296,7 +1351,8 @@ sub manage_disk_add my $offline = 0; if (not $server_host) { - print "- The server isn't running anywhere, we'll attach the disk offline on this host.\n"; + # The server isn't running anywhere, we'll attach the disk offline on this host. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0771"}); $server_host = $short_host_name; $offline = 1; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { @@ -1318,20 +1374,23 @@ sub manage_disk_add if ($offline) { # Define the VM, if needed, then add the drive, dump the config and push it out. - print "- Defining the server: [".$server_name."] to prepare for 'virsh' modification of the server.\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0772", variables => { server_name => $server_name }}); update_definition($anvil, "define", ""); # Update the definition. - print "- Adding the drive to the definition now.\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0773"}); ($output, $return_code) = $anvil->System->call({shell_call => $shell_call}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { output => $output, return_code => $return_code, }}); - print "- Updating the stored definition and undefining the server now...\n"; + # Updating the stored definition and undefining the server now... + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0774"}); update_definition($anvil, "undefine", ""); - print "Done!\n"; + + # Done! + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); $anvil->nice_exit({exit_code => 0}); } else @@ -1343,7 +1402,7 @@ sub manage_disk_add { # Do the add here. update_definition($anvil, "define", ""); - print "- Adding the drive to the server directly...\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0775"}); ($output, $return_code) = $anvil->System->call({shell_call => $shell_call}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { output => $output, @@ -1352,16 +1411,16 @@ sub manage_disk_add if ($return_code) { # Something went wrong. - print "- Failed!\n"; - print "Expected the return code '0', but got: [".$return_code."]. The command output, if anything, was:\n"; - print "========\n"; - print $output."\n"; - print "========\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0138", variables => { + shell_call => $shell_call, + return_code => $return_code, + output => $output, + }}); $anvil->nice_exit({exit_code => 1}); } # Get the new XML - print "- Reading the updated server definition\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0776"}); $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 }}); @@ -1372,7 +1431,7 @@ sub manage_disk_add }}); # Make sure the $output is valid XML. - print "- Validating the updated definition\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0777"}); my $problem = $anvil->Server->parse_definition({ server => $server_name, source => "from_virsh", @@ -1383,17 +1442,16 @@ sub manage_disk_add 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->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0434"}); $anvil->nice_exit({exit_code => 1}); } - print "- Updating the stored definition and undefining the server now...\n"; + # Update the stored definition and undefining the server + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0778"}); update_definition($anvil, "undefine", $virsh_definition); - print "Done!\n"; + + # Done! + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); $anvil->nice_exit({exit_code => 0}); } else @@ -1401,7 +1459,10 @@ sub manage_disk_add # Do the add on the target. my $use_ip = $anvil->data->{peer}{$short_host_name}{access}{ip}; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { use_ip => $use_ip }}); - print " - Adding the drivve to the server using its host: [".$server_host."] via: [".$use_ip."]...\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0779", variables => { + server_host => $server_host, + use_ip => $use_ip, + }}); my ($output, $error, $return_code) = $anvil->Remote->call({ shell_call => $shell_call, target => $use_ip, @@ -1436,12 +1497,8 @@ sub manage_disk_add if ($problem) { # Failed?! - print " -[ Error ] - The definition file read from the remote host appears to be invalid after trying to attach the -[ Error ] - disk! It is unsafe 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}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0435"}); + $anvil->nice_exit({exit_code => 1}); } $anvil->data->{server}{$short_host_name}{$server_name}{from_virsh}{xml} = $virsh_definition; @@ -1449,9 +1506,12 @@ sub manage_disk_add "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"; + # Updating the stored definition and undefining the server + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0780"}); update_definition($anvil, "undefine", $virsh_definition); - print "Done!\n"; + + # Done! + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); $anvil->nice_exit({exit_code => 0}); } } @@ -1474,7 +1534,7 @@ sub reconnect_resource # Log into the peer and disconnect, then reconnect. Then wait for the disk state to update, and # return the disk state. - print " - The peer: [".$peer_name."], is stuck 'Negotiating'; disconnecting... "; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0781", variables => { peer_name => $peer_name }}); my $use_ip = $anvil->data->{peer}{$peer_name}{access}{ip}; my $shell_call = $anvil->data->{path}{exe}{drbdadm}." disconnect ".$drbd_resource; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { @@ -1491,7 +1551,7 @@ sub reconnect_resource return_code => $return_code, }}); - print " reconnecting... "; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0782"}); sleep 1; $shell_call = $anvil->data->{path}{exe}{drbdadm}." connect ".$drbd_resource; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { @@ -1507,10 +1567,10 @@ sub reconnect_resource error => $error, return_code => $return_code, }}); - print " Done.\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); # Now wait - print "- Waiting for the disk state to be updated:\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0783"}); my $waiting = 1; my $wait_until = time + 300; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { wait_until => $wait_until }}); @@ -1519,17 +1579,14 @@ sub reconnect_resource $anvil->DRBD->get_status({debug => 2}); my $disks_ready = 1; my $connection_state = $anvil->data->{drbd}{status}{$short_host_name}{resource}{$drbd_resource}{connection}{$peer_name}{'connection-state'}; - if (not defined $connection_state) - { - print "Short host name: [".$short_host_name."], resource: [".$drbd_resource."], peer: [".$peer_name."]\n"; - print Dumper %{$anvil->data->{drbd}{status}}; - die; - } $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { connection_state => $connection_state }}); if (lc($connection_state) eq "connected") { # Connected, what's the disk state for the new volume now? - print " - Connected, checking volume: [".$drbd_resource."/".$next_drbd_volume."] disk state: "; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0784", variables => { + drbd_resource => $drbd_resource, + next_drbd_volume => $next_drbd_volume, + }}); $peer_disk_state = $anvil->data->{drbd}{status}{$short_host_name}{resource}{$drbd_resource}{connection}{$peer_name}{volume}{$next_drbd_volume}{'peer-disk-state'}; my $replication_state = $anvil->data->{drbd}{status}{$short_host_name}{resource}{$drbd_resource}{connection}{$peer_name}{volume}{$next_drbd_volume}{'replication-state'}; $role = $anvil->data->{drbd}{status}{$short_host_name}{resource}{$drbd_resource}{connection}{$peer_name}{'peer-role'}; @@ -1541,20 +1598,20 @@ sub reconnect_resource if (lc($replication_state) ne "established") { - print "Not Connected yet.\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0785"}); $disks_ready = 0; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { disks_ready => $disks_ready }}); } elsif ((not $peer_disk_state) or (lc($peer_disk_state) eq "diskless")) { - print "Disk not ready yet.\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0786"}); $disks_ready = 0; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { disks_ready => $disks_ready }}); } if ($disks_ready) { - print "Ready!\n- Disk state is: [".$peer_disk_state."]\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0787", variables => { peer_disk_state => $peer_disk_state }}); $waiting = 0; $anvil->data->{peers}{$peer_name}{disk_state} = $peer_disk_state; $anvil->data->{peers}{$peer_name}{role} = $role; @@ -1570,8 +1627,9 @@ sub reconnect_resource if (time > $wait_until) { + # Timed out waiting for the peer to connect. $waiting = 0; - print "- Timed out waiting for the peer to connect.\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0788"}); return($peer_disk_state, $role); } sleep 3; @@ -1601,13 +1659,6 @@ sub manage_disk_grow }}); # Are they asking for an available amount of space? - my $error_note = q| -[ Note ] - The size can be in percent, ie: '50%' or '100%', a number in bytes, or a human-readable size. - - Human readable sizes must NOT have a space between the number and letter suffix. Also, base2 - - vs base10 notation! Ie: '1GiB' = 1,073,741,824 bytes', '1GB' == '1,000,000,000 bytes'. A single - - letter used to denote size will be interpreted as base2. ie: '1G == 1GiB'. -|; - my $add_size = $anvil->data->{switches}{grow}; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { add_size => $add_size }}); if ($add_size =~ /^(\d+)%$/) @@ -1622,8 +1673,10 @@ sub manage_disk_grow elsif ($add_size !~ /\d/) { # No digits, probably didn't set a value at all. - print "\n[ Error ] - Please specify the size you would like to grow this disk by. The maximum size is: [".$anvil->Convert->bytes_to_human_readable({'bytes' => $max_free_space})."].\n"; - print $error_note."\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0436", variables => { + max_free_space => $anvil->Convert->bytes_to_human_readable({'bytes' => $max_free_space}), + }}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0789"}); $anvil->nice_exit({exit_code => 1}); } elsif ($add_size !~ /^\d+$/) @@ -1642,8 +1695,8 @@ sub manage_disk_grow else { # Not a valid size. - print "\n[ Error ] - The requested size: [".$add_size."] could not be interpreted.\n"; - print $error_note."\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0437"}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0789"}); $anvil->nice_exit({exit_code => 1}); } } @@ -1652,18 +1705,27 @@ sub manage_disk_grow if ($add_size < 4194304) { # Must be a typo, this is less than the size of a single extent. - print "\n[ Error ] - The requested size: [".$anvil->Convert->bytes_to_human_readable({'bytes' => $add_size})."] is too small, it's less than an single extent.\n"; - print $error_note."\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0438", variables => { + add_size => $anvil->Convert->bytes_to_human_readable({'bytes' => $add_size}), + }}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0789"}); $anvil->nice_exit({exit_code => 1}); } elsif ($add_size > $max_free_space) { # Not enough space. - print "\n[ Error ] - The requested size: [".$anvil->Convert->bytes_to_human_readable({'bytes' => $add_size})."] is too large. The available size is: [".$anvil->Convert->bytes_to_human_readable({'bytes' => $max_free_space})."]\n"; - print $error_note."\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0439", variables => { + add_size => $anvil->Convert->bytes_to_human_readable({'bytes' => $add_size}), + max_free_space => $anvil->Convert->bytes_to_human_readable({'bytes' => $max_free_space}), + }}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0789"}); $anvil->nice_exit({exit_code => 1}); } + # Are they asking for an available amount of space? + my $say_up = $anvil->Words->string({key => 'message_0331'}); + my $say_down = $anvil->Words->string({key => 'message_0332'}); + ### TODO: Make this work without the peer node being online. # The server is allowed to be running, but both nodes and any DR hosts this is replicating to # needs to be online. @@ -1672,11 +1734,15 @@ sub manage_disk_grow if (not $all_online) { - print "\n[ Error ] - Growing the storage requires all peers to be online.\n"; + # All peers have to be online. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0440"}); foreach my $short_host_name (sort {$a cmp $b} keys %{$anvil->data->{peer}}) { - my $say_access = $anvil->data->{peer}{$short_host_name}{access_ip} ? "up." : "down!"; - print " - Peer: [".$short_host_name."] is ".$say_access."\n"; + my $say_access = $anvil->data->{peer}{$short_host_name}{access_ip} ? $say_up : $say_down; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0428", variables => { + host_name => $short_host_name, + access => $say_access, + }}); } $anvil->nice_exit({exit_code => 1}); } @@ -1698,7 +1764,8 @@ sub manage_disk_grow $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { add_size => $add_size }}); } - print "- Preparing to grow the storage by: [".$hr_size."]...\n"; + # Preparing to grow the storage + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0790", variables => { size => $hr_size }}); if (not $anvil->data->{switches}{confirm}) { print $anvil->Words->string({key => "message_0021"})." "; @@ -1706,7 +1773,8 @@ sub manage_disk_grow chomp($answer); if ($answer !~ /^y/i) { - print "Aborting.\n"; + # Abort + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "message_0022"}); $anvil->nice_exit({exit_code => 0}); } @@ -1716,11 +1784,14 @@ sub manage_disk_grow if (not $all_online) { - print "\n[ Error ] - It would appear that we've lost access to a peer while waiting for the answer.\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0441"}); foreach my $short_host_name (sort {$a cmp $b} keys %{$anvil->data->{peer}}) { - my $say_access = $anvil->data->{peer}{$short_host_name}{access_ip} ? "up." : "down!"; - print " - Peer: [".$short_host_name."] is ".$say_access."\n"; + my $say_access = $anvil->data->{peer}{$short_host_name}{access_ip} ? $say_up : $say_down; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0428", variables => { + host_name => $short_host_name, + access => $say_access, + }}); } $anvil->nice_exit({exit_code => 1}); } @@ -1741,7 +1812,7 @@ sub manage_disk_grow }}); if ($host_uuid eq $anvil->Get->host_uuid) { - print " - Extending local LV: [".$backing_disk."]..."; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0791", variables => { backing_disk => $backing_disk }}); my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { output => $output, @@ -1749,27 +1820,30 @@ sub manage_disk_grow }}); if ($return_code) { - print " Error!\n"; - print "[ FAILED ] - When trying to grow the local logical volume: [".$backing_disk."]\n"; - print "[ FAILED ] - using the command: [".$shell_call."]\n"; - print "[ FAILED ] - The return code: [".$return_code."] was received, expected '0'. Output, if any:\n"; - print "==========\n"; - print $output."\n"; - print "==========\n"; - print "The extension of the resource is incomplete, manual intervention is required!!\n"; - print "[ Warning ] - Do NOT re-run this command! The backing devices may not have mis-matched sized!\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0442", variables => { + backing_disk => $backing_disk, + shell_call => $shell_call, + return_code => $return_code, + output => $output, + }}); $anvil->nice_exit({exit_code => 1}); } else { - print " Done!\n"; + # Done + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); } } else { my $use_ip = $anvil->data->{peer}{$short_host_name}{access}{ip}; my $use_network = $anvil->data->{peer}{$short_host_name}{access}{network}; - print " - Extending peer: [".$short_host_name.":".$backing_disk."], via: [".$use_ip." (".$use_network.")]"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0792", variables => { + host_name => $short_host_name, + backing_disk => $backing_disk, + use_ip => $use_ip, + use_network => $use_network, + }}); my ($output, $error, $return_code) = $anvil->Remote->call({ shell_call => $shell_call, target => $use_ip, @@ -1781,29 +1855,26 @@ sub manage_disk_grow }}); if ($return_code) { - print " Error!\n"; - print "[ FAILED ] - When trying to grow the peer's logical volume: [".$backing_disk."]\n"; - print "[ FAILED ] - using the command: [".$shell_call."]\n"; - print "[ FAILED ] - The return code: [".$return_code."] was received, expected '0'. Output, if any:\n"; - print "==] STDOUT [========\n"; - print $output."\n"; - print "==] STDERR [========\n"; - print $error."\n"; - print "====================\n"; - print "The extension of the resource is incomplete, manual intervention is required!!\n"; - print "[ Warning ] - Do NOT re-run this command! The backing devices may not have mis-matched sized!\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0443", variables => { + backing_disk => $backing_disk, + shell_call => $shell_call, + return_code => $return_code, + output => $output, + error => $error, + }}); $anvil->nice_exit({exit_code => 1}); } else { - print " Done!\n"; + # Done + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); } } } } # Locally, we'll call DRBD to resize. - print "- Extending backing devices complete. Now extending DRBD resource/volume... "; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0793"}); my $shell_call = $anvil->data->{path}{exe}{drbdadm}." resize ".$drbd_resource."/".$drbd_volume; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }}); @@ -1814,25 +1885,23 @@ sub manage_disk_grow }}); if ($return_code) { - print " Error!\n"; - print "[ FAILED ] - When trying to grow the DRBD device: [".$drbd_resource."/".$drbd_volume."]\n"; - print "[ FAILED ] - using the command: [".$shell_call."]\n"; - print "[ FAILED ] - The return code: [".$return_code."] was received, expected '0'. Output, if any:\n"; - print "==========\n"; - print $output."\n"; - print "==========\n"; - print "The extension of the resource is incomplete, manual intervention is required!!\n"; - print "[ Note ] - All backing devices have been grown. Manually resolving the drbd grow\n"; - print "[ Note ] - error should complete the drive expansion!\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0444", variables => { + drbd_resource => $drbd_resource, + drbd_volume => $drbd_volume, + shell_call => $shell_call, + return_code => $return_code, + output => $output, + }}); $anvil->nice_exit({exit_code => 1}); } else { - print " Done!\n"; + # Done + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); } # Call scan-lvm and scan-drbd to make sure the databases are updated. - print "- Calling scancore agents to ensure the database has the new storage config recorded.\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0794"}); foreach my $agent ("scan-drbd", "scan-lvm") { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0740", variables => { agent => $agent }}); @@ -1850,19 +1919,26 @@ sub manage_disk_grow }}); if ($host_uuid eq $anvil->Get->host_uuid) { - print " - Running scan agent: [".$agent."] locally..."; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0795", variables => { agent => $agent }}); my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { output => $output, return_code => $return_code, }}); - print " Done!\n"; + + # Done + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); } else { my $use_ip = $anvil->data->{peer}{$short_host_name}{access}{ip}; my $use_network = $anvil->data->{peer}{$short_host_name}{access}{network}; - print " - Running scan agent: [".$agent."] on: [".$short_host_name."] via: [".$use_ip." (".$use_network.")]..."; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0796", variables => { + agent => $agent, + host_name => $short_host_name, + use_ip => $use_ip, + use_network => $use_network, + }}); my ($output, $error, $return_code) = $anvil->Remote->call({ shell_call => $shell_call, target => $use_ip, @@ -1872,16 +1948,16 @@ sub manage_disk_grow error => $error, return_code => $return_code, }}); - print " Done!\n"; + + # Done + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); } } } } - print "[ Success ] - Expansion is complete!\n"; - print "[ Note ] - Depending on your OS, you may need to power the server off, and then power it back on\n"; - print "[ Note ] - for the new space to be visible. Typically, powering off the server from the guest OS\n"; - print "[ Note ] - and waiting for the Anvil! to boot it back up will do the job nicely.\n"; + # Success! + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0797"}); return(0); } @@ -1919,7 +1995,7 @@ sub manage_optical if (not $anvil->data->{switches}{optical}) { # Can't proceed. - print "\n[ Error ] - Please indicate the optical drive to work with using '--optical '.\n\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0445"}); show_server_details($anvil); $anvil->nice_exit({exit_code => 1}); } @@ -1931,14 +2007,16 @@ sub manage_optical { # User didn't specify a device. show_server_details($anvil); - print "\n[ Error ] - Please specify the optical disk target you want to work on.\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0446"}); $anvil->nice_exit({exit_code => 1}); } elsif (not exists $anvil->data->{server}{$short_host_name}{$server_name}{$from_source}{device}{cdrom}{target}{$device_target}) { # Invalid device target show_server_details($anvil); - print "\n[ Error ] - The optical device target: [".$device_target."] wasn't found.\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0447", variables => { + device_target => $device_target, + }}); $anvil->nice_exit({exit_code => 1}); } @@ -1982,7 +2060,9 @@ sub manage_optical my $iso = $anvil->data->{switches}{insert}; if (not -f $iso) { - print "[ Error ] - The target: [".$iso."] doesn't exist, can't insert it into the optical drive.\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0448", variables => { + iso => $iso, + }}); update_definition($anvil, "undefine", ""); $anvil->nice_exit({exit_code => 1}); } @@ -1994,31 +2074,43 @@ sub manage_optical } # If the server is running, update the on-disk and in-DB definition. - print "Defining the server: [".$server_name."] to prepare for 'virsh' modification of the server.\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0798", variables => { server_name => $server_name }}); update_definition($anvil, "define", ""); # Now we can modify the server using virsh. if ($anvil->data->{switches}{insert}) { - print "- Inserting: [".$anvil->data->{switches}{insert}."] into the drive: [".$device_target."].\n"; + # Inserting + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0799", variables => { + insert => $anvil->data->{switches}{insert}, + device_target => $device_target, + }}); } elsif ($anvil->data->{switches}{eject}) { - print "- Ejecting: [".$device_path."] from: [".$device_target."].\n"; + # Ejecting + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0800", variables => { + eject => $device_path, + device_target => $device_target, + }}); } else { # Show the ISO in the drive. if ($device_path) { - print "- Drive: [".$device_target."] has the disc image: [".$device_path."] inserted currently.\n"; - print "- Use '--eject' to eject the disc.\n"; - print "- Use '--insert /mnt/shared/files/' to replace it with a different disc image.\n"; + # Disc is already in the drive + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0449", variables => { + device_target => $device_target, + device_path => $device_path, + }}); } else { - print "- Drive: [".$device_target."] currently has no disc image inserted.\n"; - print "- Use '--insert /mnt/shared/files/' to insert a disc image.\n"; + # Drive has no disc in it. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0450", variables => { + device_target => $device_target, + }}); } $anvil->nice_exit({exit_code => 0}); } @@ -2027,11 +2119,13 @@ sub manage_optical 's1:output' => $output, 's2:return_code' => $return_code, }}); - print "'virsh' Output: [".$output."]\n"; - print "Updating the stored definition and undefining the server now:\n"; + # Updating the stored definition and undefining the server now + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0801"}); update_definition($anvil, "undefine", ""); - print "Done!\n"; + + # Done + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); return(0); } @@ -2106,11 +2200,13 @@ sub show_server_details { if ($device eq "disk") { - print "\nDisk Drives:\n"; + # Disk drives + print "\n".$anvil->Words->string({key => "message_0334"})."\n"; } else { - print "\nOptical Drives:\n"; + # Optical drives + print "\n".$anvil->Words->string({key => "message_0335"})."\n"; } $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { device => $device }}); next if $device ne "cdrom" && $device ne "disk"; @@ -2170,8 +2266,18 @@ sub show_server_details 's14:max_free_space' => $max_free_space." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $max_free_space}).")", }}); - print "- Target: [".$device_target."], boot: [".$say_boot."], Replication Volume: [".$drbd_resource."/".$drbd_volume."]\n"; - print " |- Resource / LV / Metadata sizes: [".$anvil->Convert->bytes_to_human_readable({'bytes' => $resource_size})." / ".$anvil->Convert->bytes_to_human_readable({'bytes' => $lv_size})." / ".$anvil->Convert->bytes_to_human_readable({'bytes' => $metadata_size})."], free space: [".$anvil->Convert->bytes_to_human_readable({'bytes' => $max_free_space})."]\n"; + print $anvil->Words->string({key => "message_0336", variables => { + device_target => $device_target, + say_boot => $say_boot, + drbd_resource => $drbd_resource, + drbd_volume => $drbd_volume, + }})."\n"; + print $anvil->Words->string({key => "message_0337", variables => { + resource_size => $anvil->Convert->bytes_to_human_readable({'bytes' => $resource_size}), + lv_size => $anvil->Convert->bytes_to_human_readable({'bytes' => $lv_size}), + metadata_size => $anvil->Convert->bytes_to_human_readable({'bytes' => $metadata_size}), + max_free_space => $anvil->Convert->bytes_to_human_readable({'bytes' => $max_free_space}), + }})."\n"; #print " |- Resource / LV / Metadata sizes: [".$anvil->Convert->bytes_to_human_readable({'bytes' => $resource_size})." / ".$anvil->Convert->bytes_to_human_readable({'bytes' => $lv_size})." / ".$anvil->Convert->bytes_to_human_readable({'bytes' => $metadata_size})."], free space: [".$anvil->Convert->bytes_to_human_readable({'bytes' => $max_free_space})."], cache: [".$driver_cache."], IO Policy: [".$driver_io."]\n"; } else @@ -2190,20 +2296,24 @@ sub show_server_details 's3:address_target' => $address_target, 's4:device_path' => $device_path, }}); - print "- Target: [".$device_target."], boot: [".$say_boot."], ISO: [".$device_path."]\n"; + print $anvil->Words->string({key => "message_0338", variables => { + device_target => $device_target, + say_boot => $say_boot, + device_path => $device_path, + }})."\n"; } } } print "\n"; - print "Sub-Nodes:\n"; + print $anvil->Words->string({key => "message_0339"})."\n"; show_volume($anvil, $drbd_resource, "node"); my $dr_count = keys %{$anvil->data->{drbd_resource}{$drbd_resource}{host_type}{dr}{short_host_name}}; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { dr_count => $dr_count }}); if ($dr_count) { - print "DR Hosts:\n"; + print $anvil->Words->string({key => "message_0340"})."\n"; show_volume($anvil, $drbd_resource, "dr"); } @@ -2401,7 +2511,10 @@ sub show_volume 's1:short_host_name' => $short_host_name, 's2:host_uuid' => $host_uuid, }}); - print " |- Name: [".$short_host_name."], UUID: [".$host_uuid."]\n"; + print $anvil->Words->string({key => "message_0341", variables => { + host_name => $short_host_name, + host_uuid => $host_uuid, + }})."\n"; foreach my $volume_number (sort {$a cmp $b} keys %{$anvil->data->{drbd_resource}{$drbd_resource}{host_uuid}{$host_uuid}{volume_number}}) { my $device_path = $anvil->data->{drbd_resource}{$drbd_resource}{host_uuid}{$host_uuid}{volume_number}{$volume_number}{device_path}; @@ -2432,8 +2545,16 @@ sub show_volume 's1:storage_group_size' => $storage_group_size, 's2:storage_group_free_space' => $storage_group_free_space, }}); - print " |- Volume: [".$volume_number."], backing device: [".$backing_disk."], DRBD minor: [".$device_minor."], size: [".$anvil->Convert->bytes_to_human_readable({'bytes' => $volume_size})."]\n"; - print " ^- In storage group: [".$storage_group_name."], size: [".$anvil->Convert->bytes_to_human_readable({'bytes' => $storage_group_size})."], free: [".$anvil->Convert->bytes_to_human_readable({'bytes' => $storage_group_free_space})."]\n"; + print $anvil->Words->string({key => "message_0342", variables => { + volume_number => $volume_number, + backing_disk => $backing_disk, + device_minor => $device_minor, + volume_size => $anvil->Convert->bytes_to_human_readable({'bytes' => $volume_size}), + storage_group_name => $storage_group_name, + storage_group_size => $anvil->Convert->bytes_to_human_readable({'bytes' => $storage_group_size}), + storage_group_free_space => $anvil->Convert->bytes_to_human_readable({'bytes' => $storage_group_free_space}), + + }})."\n"; # How much space is available in the storage group this volume is in? foreach my $this_scan_lvm_lv_name (sort {$a cmp $b} keys %{$anvil->data->{lvm}{host_name}{$short_host_name}{lv}}) @@ -2497,17 +2618,25 @@ sub validate_server if ($anvil->data->{switches}{anvil_uuid}) { # Not found on the requested Anvil! node. - print "\nThe server: [".$anvil->data->{switches}{server}."] was not found on the Anvil! node: [".$anvil->data->{switches}{anvil_name}."]. Valid servers are above.\n\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0451", variables => { + server => $anvil->data->{switches}{server}, + anvil => $anvil->data->{switches}{anvil_name}, + }}); } else { # Not found at all. - print "\nThe server: [".$anvil->data->{switches}{server}."] was not found. Valid servers are above.\n\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0452", variables => { + server => $anvil->data->{switches}{server}, + }}); } $anvil->nice_exit({exit_code => 1}); } - print "Working with the server: [".$anvil->data->{switches}{server_name}."], UUID: [".$anvil->data->{switches}{server_uuid}."]\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0802", variables => { + server_name => $anvil->data->{switches}{server_name}, + server_uuid => $anvil->data->{switches}{server_uuid}, + }}); my $short_host_name = $anvil->Get->short_host_name; my $server_name = $anvil->data->{switches}{server_name}; my $server_uuid = $anvil->data->{switches}{server_uuid}; @@ -2534,7 +2663,10 @@ sub validate_server if ($server_state eq "DELETED") { - print "The server: [".$server_name."] has been deleted.\n"; + # The server has been deleted + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0453", variables => { + server => $server_name, + }}); $anvil->nice_exit({exit_code => 1}); } @@ -2564,7 +2696,10 @@ sub validate_server host_uuid => $server_host_uuid, }); - print "The server: [".$server_name."] appears to be running on: [".$server_host_name."], please run this on that host.\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0454", variables => { + server => $server_name, + host_name => $server_host_name, + }}); $anvil->nice_exit({exit_code => 1}); } } @@ -2720,7 +2855,9 @@ sub update_definition if (not $use_definition) { # What?! - print "[ Error ] - Failed to find an on disk or from virsh definition for the server: [".$server_name."]. Unable to proceed.\n"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0455", variables => { + server => $server_name, + }}); $anvil->nice_exit({exit_code => 1}); } @@ -2796,7 +2933,11 @@ sub show_server_list { next; } - print "\nAnvil! Node: [".$anvil_name."], UUID: [".$anvil_uuid."] - Description: [".$anvil_description."]\n"; + print "\n".$anvil->Words->string({key => "message_0343", variables => { + anvil_name => $anvil_name, + anvil_uuid => $anvil_uuid, + anvil_description => $anvil_description, + }})."\n"; my $server_count = 0; if (exists $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}) @@ -2806,7 +2947,7 @@ sub show_server_list } if (not $server_count) { - print "- No servers on this node yet\n"; + print $anvil->Words->string({key => "message_0344"})."\n"; } else { @@ -2820,7 +2961,10 @@ sub show_server_list server_state => $server_state, }}); next if $server_state eq "DELETED"; - print "^- Server: [".$server_name."], UUID: [".$server_uuid."]\n"; + print $anvil->Words->string({key => "message_0345", variables => { + server_name => $server_name, + server_uuid => $server_uuid, + }})."\n"; } } } From e895e1f264c58d6bfc2c41de802d2c2aaeb3f06d Mon Sep 17 00:00:00 2001 From: digimer Date: Tue, 5 Sep 2023 16:53:08 -0400 Subject: [PATCH 2/5] * Finished writting the anvil-manage-server-storage. * Fixed handling --eject and --insert to work without a device target specified when only one exists, or to find the file path when only the file name is given. * Updated anvil-manage-server-storage to show files when processing an optical devices without a file being passed. Signed-off-by: digimer --- Anvil/Tools/Database.pm | 2 +- man/anvil-manage-server-storage.8 | 39 +++++++- share/words.xml | 2 + tools/anvil-manage-server-storage | 151 ++++++++++++++++++++++++++---- 4 files changed, 169 insertions(+), 25 deletions(-) diff --git a/Anvil/Tools/Database.pm b/Anvil/Tools/Database.pm index b4afa382..219aeb86 100644 --- a/Anvil/Tools/Database.pm +++ b/Anvil/Tools/Database.pm @@ -3655,7 +3655,7 @@ Parameters; =head3 include_deleted (optional, default '0') -Normalling, files with C<< file_type >> set to C<< DELETED >> are ignored. Setting this to C<< 1 >> will include them. +Normally, files with C<< file_type >> set to C<< DELETED >> are ignored. Setting this to C<< 1 >> will include them. =cut sub get_files diff --git a/man/anvil-manage-server-storage.8 b/man/anvil-manage-server-storage.8 index 58e9f888..8d8b0ab8 100644 --- a/man/anvil-manage-server-storage.8 +++ b/man/anvil-manage-server-storage.8 @@ -9,6 +9,8 @@ anvil-manage-server-storage \- Tool used to manage the storage of a hosted serve .SH DESCRIPTION anvil-manage-server-storage \- This tool is used to add a disk, grow an existing disk, change the ISO (optical disk) in a virtual optical drive, and change boot devices. .TP +When called without switches, the list of servers than can be worked on will be displayed. +.TP .SH OPTIONS .TP \-?, \-h, \fB\-\-help\fR @@ -20,16 +22,45 @@ When logging, record sensitive data, like passwords. \-v, \-vv, \-vvv Set the log level to 1, 2 or 3 respectively. Be aware that level 3 generates a significant amount of log data. .SS "Commands:" - .TP \fB\-\-add\fR +This is used to add a new disk to a server. Specifically, it adds a second volume to the replicated storage under the server, which appears as a second disk inside the server. Writes to this and existing disks are ordered during replication, including during short or long throw DR. +.TP The size can be in percent, ie: '50%' or '100%', a number in bytes, or a human-readable size. Human readable sizes must NOT have a space between the number and letter suffix. Also, base2 vs base10 notation! Ie: '1GiB' = 1,073,741,824 bytes', '1GB' == '1,000,000,000 bytes'. A single letter used to denote size will be interpreted as base2. ie: '1G == 1GiB'. .TP \fB\-\-anvil\fR - +This is the Anvil! node name or UUID to be used. If not specified, the Anvil! the command or job runs on will be used. +.TP +\fB\-\-confirm\fR +Using this prevents the prompts to confirm given actions. When using \fB\-\-job\-uuid\fR, this is ignored as all commands are considered confirmed. +.TP +\fB\-\-disk\fR job_uuid to execute. Generally this is only used by other programs. +.TP +\fB\-\-grow\fR +This is used to grow an existing disk by the specified amount. The drive to grow is specified using \fB\-\-disk\fR. +.TP +The size can be in percent, ie: '50%' or '100%', a number in bytes, or a human-readable size. Human readable sizes must NOT have a space between the number and letter suffix. Also, base2 vs base10 notation! Ie: '1GiB' = 1,073,741,824 bytes', '1GB' == '1,000,000,000 bytes'. A single letter used to denote size will be interpreted as base2. ie: '1G == 1GiB'. +.TP +\fB\-\-insert\fR +This inserts the optical disc (ISO) into the drive specified by \fB\-\-optical\fR. +.TP +\fB\-\-optical\fR +This is the device, ie: 'sda', to insert the optical disc (ISO file) into or to eject a disc from. +.TP +\fB\-\-server\fR +This is the server being worked on. If this switch is used alone, then the current state of the storage of the server is displayed, as well as the details of the Storage Groups the server is or can use. .TP -\fB\-\-\fR - +\fB\-\-storage\-group\fR +If there are two or more Storage Groups exist, and you're adding a disk, this allows you to specify which storage group to use for the new disk. .IP .SH AUTHOR Written by Madison Kelly, Alteeve staff and the Anvil! project contributors. diff --git a/share/words.xml b/share/words.xml index 066c8435..a49b3483 100644 --- a/share/words.xml +++ b/share/words.xml @@ -3134,6 +3134,8 @@ Proceed? [y/N] Anvil! Node: [#!variable!anvil_name!#], UUID: [#!variable!anvil_uuid!#] - Description: [#!variable!anvil_description!#] - No servers on this node yet ^- Server: [#!variable!server_name!#], UUID: [#!variable!server_uuid!#] + Available Disc Images (ISOs): + - #!variable!file_name!#, (#!variable!file_size!#, md5sum: #!variable!md5sum!#) Normal Password diff --git a/tools/anvil-manage-server-storage b/tools/anvil-manage-server-storage index fc69bf26..328c289e 100755 --- a/tools/anvil-manage-server-storage +++ b/tools/anvil-manage-server-storage @@ -93,7 +93,7 @@ if (not $anvil->data->{switches}{server}) validate_server($anvil); -if ($anvil->data->{switches}{optical}) +if (($anvil->data->{switches}{optical}) or ($anvil->data->{switches}{eject})) { manage_optical($anvil); } @@ -103,7 +103,7 @@ elsif ($anvil->data->{switches}{disk}) } else { - show_server_details($anvil); + show_server_details($anvil, 1); } $anvil->nice_exit({exit_code => 0}); @@ -195,7 +195,7 @@ sub manage_disk { # Can't proceed. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0457"}); - show_server_details($anvil); + show_server_details($anvil, 1); $anvil->nice_exit({exit_code => 1}); } } @@ -281,14 +281,14 @@ sub manage_disk if ($anvil->data->{switches}{disk} eq "#!SET!#") { # User didn't specify a device. - show_server_details($anvil); + show_server_details($anvil, 1); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0458"}); $anvil->nice_exit({exit_code => 1}); } elsif (not exists $anvil->data->{server}{$short_host_name}{$server_name}{$from_source}{device}{disk}{target}{$device_target}) { # Invalid device target - show_server_details($anvil); + show_server_details($anvil, 1); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0459", variables => { device_target => $device_target, }}); @@ -1968,11 +1968,15 @@ sub manage_optical my $short_host_name = $anvil->Get->short_host_name; my $server_name = $anvil->data->{switches}{server_name}; + my $server_uuid = $anvil->data->{switches}{server_uuid}; my $from_source = get_definition_source($anvil); + my $anvil_uuid = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_anvil_uuid}; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { short_host_name => $short_host_name, server_name => $server_name, + server_uuid => $server_uuid, from_source => $from_source, + anvil_uuid => $anvil_uuid, }}); if (not $anvil->data->{switches}{optical}) @@ -1996,24 +2000,85 @@ sub manage_optical { # Can't proceed. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0445"}); - show_server_details($anvil); + show_server_details($anvil, 1); $anvil->nice_exit({exit_code => 1}); } } + + # If the device target isn't specified but there's only one disc drive, select it. + if ((not $anvil->data->{switches}{optical}) or ($anvil->data->{switches}{optical} eq "#!SET!#")) + { + my $device_count = keys %{$anvil->data->{server}{$short_host_name}{$server_name}{$from_source}{device}{cdrom}{target}}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { device_count => $device_count }}); + + if ($device_count == 1) + { + foreach my $device_target (sort {$a cmp $b} keys %{$anvil->data->{server}{$short_host_name}{$server_name}{$from_source}{device}{cdrom}{target}}) + { + $anvil->data->{switches}{optical} = $device_target; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + "switches::optical" => $anvil->data->{switches}{optical}, + }}); + last; + } + } + } + + # If the user specified a disc to insert using just the file name, prepend the directory. + if ($anvil->data->{switches}{insert}) + { + my $iso = $anvil->data->{switches}{insert}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { iso => $iso }}); + if ($iso !~ /^\//) + { + foreach my $file_name (sort {$a cmp $b} keys %{$anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_name}}) + { + my $file_location_file_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_name}{$file_name}{file_uuid}; + my $file_directory = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_location_file_uuid}{file_directory}; + my $full_path = $file_directory."/".$file_name; + my $file_size = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_location_file_uuid}{file_size}; + my $file_md5sum = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_location_file_uuid}{file_md5sum}; + my $file_type = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_location_file_uuid}{file_type}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 's1:file_name' => $file_name, + 's2:file_directory' => $file_directory, + 's3:full_path' => $full_path, + 's4:file_size' => $file_size." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $file_size}).")", + 's5:file_md5sum' => $file_md5sum, + 's6:file_type' => $file_type, + }}); + next if $iso ne $file_name; + next if $file_type ne "iso"; + + if (-f $full_path) + { + # Use this. + $anvil->data->{switches}{insert} = $full_path; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + "switches::insert" => $anvil->data->{switches}{insert}, + }}); + last; + } + } + } + } + my $device_target = $anvil->data->{switches}{optical}; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { device_target => $device_target }}); - if ($anvil->data->{switches}{optical} eq "#!SET!#") + if ((not $anvil->data->{switches}{optical}) or ($anvil->data->{switches}{optical} eq "#!SET!#")) { # User didn't specify a device. - show_server_details($anvil); + show_server_details($anvil, 0); + show_files($anvil); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0446"}); $anvil->nice_exit({exit_code => 1}); } elsif (not exists $anvil->data->{server}{$short_host_name}{$server_name}{$from_source}{device}{cdrom}{target}{$device_target}) { # Invalid device target - show_server_details($anvil); + show_server_details($anvil, 0); + show_files($anvil); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0447", variables => { device_target => $device_target, }}); @@ -2090,7 +2155,7 @@ sub manage_optical { # Ejecting $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0800", variables => { - eject => $device_path, + device_path => $device_path, device_target => $device_target, }}); } @@ -2180,7 +2245,7 @@ sub get_definition_source sub show_server_details { - my ($anvil) = @_; + my ($anvil, $show_nodes) = @_; my $short_host_name = $anvil->Get->short_host_name; my $host_uuid = $anvil->Get->host_uuid; @@ -2188,7 +2253,8 @@ sub show_server_details $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 's1:short_host_name' => $short_host_name, 's2:host_uuid' => $host_uuid, - 's2:server_name' => $server_name, + 's3:server_name' => $server_name, + 's4:show_nodes' => $show_nodes, }}); # Load storage data @@ -2306,15 +2372,18 @@ sub show_server_details } print "\n"; - print $anvil->Words->string({key => "message_0339"})."\n"; - show_volume($anvil, $drbd_resource, "node"); - - my $dr_count = keys %{$anvil->data->{drbd_resource}{$drbd_resource}{host_type}{dr}{short_host_name}}; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { dr_count => $dr_count }}); - if ($dr_count) + if ($show_nodes) { - print $anvil->Words->string({key => "message_0340"})."\n"; - show_volume($anvil, $drbd_resource, "dr"); + print $anvil->Words->string({key => "message_0339"})."\n"; + show_volume($anvil, $drbd_resource, "node"); + + my $dr_count = keys %{$anvil->data->{drbd_resource}{$drbd_resource}{host_type}{dr}{short_host_name}}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { dr_count => $dr_count }}); + if ($dr_count) + { + print $anvil->Words->string({key => "message_0340"})."\n"; + show_volume($anvil, $drbd_resource, "dr"); + } } return(0); @@ -2971,3 +3040,45 @@ sub show_server_list return(0); } + +sub show_files +{ + my ($anvil) = @_; + + my $server_name = $anvil->data->{switches}{server_name}; + my $server_uuid = $anvil->data->{switches}{server_uuid}; + my $anvil_uuid = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_anvil_uuid}; + my $anvil_name = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_name}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 's1:server_name' => $server_name, + 's2:server_uuid' => $server_uuid, + 's3:anvil_uuid' => $anvil_uuid, + 's4:anvil_name' => $anvil_name, + }}); + + $anvil->Database->get_anvils; + + # Show the files available on this node. + print $anvil->Words->string({key => 'message_0346'})."\n"; + foreach my $file_name (sort {$a cmp $b} keys %{$anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_name}}) + { + my $file_location_file_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_name}{$file_name}{file_uuid}; + my $file_size = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_location_file_uuid}{file_size}; + my $file_md5sum = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_location_file_uuid}{file_md5sum}; + my $file_type = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_location_file_uuid}{file_type}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 's1:file_name' => $file_name, + 's2:file_size' => $file_size." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $file_size}).")", + 's3:file_md5sum' => $file_md5sum, + 's4:file_type' => $file_type, + }}); + next if $file_type ne "iso"; + print $anvil->Words->string({key => 'message_0347', variables => { + file_name => $file_name, + file_size => $anvil->Convert->bytes_to_human_readable({'bytes' => $file_size}), + md5sum => $file_md5sum, + }})."\n"; + } + + return(0); +} \ No newline at end of file From 2f429d2bc7bd41e3860552b72bfdae7801789f10 Mon Sep 17 00:00:00 2001 From: digimer Date: Tue, 5 Sep 2023 22:53:52 -0400 Subject: [PATCH 3/5] Fixed bugs related to adding drives and extending drives to servers. Signed-off-by: digimer --- man/anvil-manage-server-storage.8 | 12 +++++--- share/words.xml | 6 ++-- tools/anvil-manage-server-storage | 50 ++++++++++++++++++++++++++----- 3 files changed, 55 insertions(+), 13 deletions(-) diff --git a/man/anvil-manage-server-storage.8 b/man/anvil-manage-server-storage.8 index 8d8b0ab8..d7c9c79c 100644 --- a/man/anvil-manage-server-storage.8 +++ b/man/anvil-manage-server-storage.8 @@ -26,7 +26,9 @@ Set the log level to 1, 2 or 3 respectively. Be aware that level 3 generates a s \fB\-\-add\fR This is used to add a new disk to a server. Specifically, it adds a second volume to the replicated storage under the server, which appears as a second disk inside the server. Writes to this and existing disks are ordered during replication, including during short or long throw DR. .TP -The size can be in percent, ie: '50%' or '100%', a number in bytes, or a human-readable size. Human readable sizes must NOT have a space between the number and letter suffix. Also, base2 vs base10 notation! Ie: '1GiB' = 1,073,741,824 bytes', '1GB' == '1,000,000,000 bytes'. A single letter used to denote size will be interpreted as base2. ie: '1G == 1GiB'. +The size can be in percent, ie: '50%' or '100%', a number in bytes, or a human-readable size. Human readable sizes must NOT have a space between the number and letter suffix. +.TP +Also, base2 vs base10 notation! Ie: '1GiB' = 1,073,741,824 bytes', '1GB' = '1,000,000,000 bytes'. A single letter used to denote size will be interpreted as base2. ie: '1G' is the same as '1GiB'. .TP \fB\-\-anvil\fR This is the Anvil! node name or UUID to be used. If not specified, the Anvil! the command or job runs on will be used. @@ -34,7 +36,7 @@ This is the Anvil! node name or UUID to be used. If not specified, the Anvil! th \fB\-\-confirm\fR Using this prevents the prompts to confirm given actions. When using \fB\-\-job\-uuid\fR, this is ignored as all commands are considered confirmed. .TP -\fB\-\-disk\fR This is the disk being worked on. For optical disks, it's the drive that an optical disc (ISO) is being inserted into or ejected from. For disks, it's the disk being added, grown or deleted. .TP When not specified, if only one disk exists, it will be chosen automatically. @@ -48,7 +50,9 @@ This is the jobs -> job_uuid to execute. Generally this is only used by other pr \fB\-\-grow\fR This is used to grow an existing disk by the specified amount. The drive to grow is specified using \fB\-\-disk\fR. .TP -The size can be in percent, ie: '50%' or '100%', a number in bytes, or a human-readable size. Human readable sizes must NOT have a space between the number and letter suffix. Also, base2 vs base10 notation! Ie: '1GiB' = 1,073,741,824 bytes', '1GB' == '1,000,000,000 bytes'. A single letter used to denote size will be interpreted as base2. ie: '1G == 1GiB'. +The size can be in percent, ie: '50%' or '100%', a number in bytes, or a human-readable size. Human readable sizes must NOT have a space between the number and letter suffix. +.TP +Also, base2 vs base10 notation! Ie: '1GiB' = 1,073,741,824 bytes', '1GB' = '1,000,000,000 bytes'. A single letter used to denote size will be interpreted as base2. ie: '1G' is the same as '1GiB'. .TP \fB\-\-insert\fR This inserts the optical disc (ISO) into the drive specified by \fB\-\-optical\fR. @@ -59,7 +63,7 @@ This is the device, ie: 'sda', to insert the optical disc (ISO file) into or to \fB\-\-server\fR This is the server being worked on. If this switch is used alone, then the current state of the storage of the server is displayed, as well as the details of the Storage Groups the server is or can use. .TP -\fB\-\-storage\-group\fR +\fB\-\-storage\-group\fR If there are two or more Storage Groups exist, and you're adding a disk, this allows you to specify which storage group to use for the new disk. .IP .SH AUTHOR diff --git a/share/words.xml b/share/words.xml index a49b3483..aaa98e68 100644 --- a/share/words.xml +++ b/share/words.xml @@ -716,7 +716,7 @@ The extension of the resource is incomplete, manual intervention is required!! ========== The creation of the new replicatedd disk is incomplete, manual intervention is required!]]> - Writing out the updated DRBD config file. - Creating the meta-data on the new local volume: [#!variable!next_drbd_volume!#]... - Creating the meta-data on the peer: [#!variable!host_name!#:#!variable!drbd_resource!#/#!variable!next_drbd_volume!#], via: [#!variable!use_ip!# (#!variable!use_network!#)] - - Registered a job with job UUID: [#!variable!job_uuid!#] to reload the resource config on the host: [#!variable!short_host_name!#]. + - Registered a job with job UUID: [#!variable!job_uuid!#] to reload the resource config on the host: [#!variable!host_name!#]. - Adjusting the local resource: [#!variable!drbd_resource!#] to pick up the new config. [ NOTE ] - If this hangs, make sure 'anvil-daemon' is running on the peers. - Waiting for all peers to connect the new volume... @@ -3136,6 +3136,8 @@ Proceed? [y/N] ^- Server: [#!variable!server_name!#], UUID: [#!variable!server_uuid!#] Available Disc Images (ISOs): - #!variable!file_name!#, (#!variable!file_size!#, md5sum: #!variable!md5sum!#) + Available Storage Groups; + - #!variable!storage_group_name!#, free space: #!variable!free_space!#, UUID: #!variable!storage_group_uuid!# Normal Password diff --git a/tools/anvil-manage-server-storage b/tools/anvil-manage-server-storage index 328c289e..49329368 100755 --- a/tools/anvil-manage-server-storage +++ b/tools/anvil-manage-server-storage @@ -17,6 +17,7 @@ # - anvil-manage-server-storage --server srv01-fs37 --optical sda --eject # - Disk # - anvil-manage-server-storage --server srv01-fs37 --disk vdb --grow {+10GiB,150GiB} +# - anvil-manage-server-storage --server srv01-fs37 --disk vdb --grow {+10GiB,150GiB} # use strict; @@ -97,7 +98,7 @@ if (($anvil->data->{switches}{optical}) or ($anvil->data->{switches}{eject})) { manage_optical($anvil); } -elsif ($anvil->data->{switches}{disk}) +elsif (($anvil->data->{switches}{disk}) or ($anvil->data->{switches}{add})) { manage_disk($anvil); } @@ -176,7 +177,7 @@ sub manage_disk }}); if (not $anvil->data->{switches}{disk}) { - # If there's only one optical drive, select it automatically + # If there's only one disk drive, select it automatically my $count = keys %{$anvil->data->{server}{$short_host_name}{$server_name}{$from_source}{device}{disk}{target}}; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }}); if ($count == 1) @@ -380,7 +381,7 @@ sub manage_disk_add if (not $anvil->data->{switches}{'storage-group'}) { print $anvil->Words->string({key => 'warning_0159'})."\n"; - short_storage_groups($anvil, $anvil_uuid); + show_storage_groups($anvil); $anvil->nice_exit({exit_code => 1}); } @@ -574,7 +575,7 @@ sub manage_disk_add } # Still alive? Ask the user to confirm. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0428", variables => { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "message_0333", variables => { new_device_target => $new_device_target, hr_size => $hr_size, disk_device_bus => $disk_device_bus, @@ -691,7 +692,7 @@ sub manage_disk_add host_name => $short_host_name, backing_disk => $backing_disk, use_ip => $use_ip, - network => $use_network, + use_network => $use_network, }}); my ($output, $error, $return_code) = $anvil->Remote->call({ shell_call => $shell_call, @@ -952,7 +953,7 @@ sub manage_disk_add drbd_resource => $drbd_resource, next_drbd_volume => $next_drbd_volume, use_ip => $use_ip, - network => $use_network, + use_network => $use_network, }}); my ($output, $error, $return_code) = $anvil->Remote->call({ shell_call => $shell_call, @@ -3081,4 +3082,39 @@ sub show_files } return(0); -} \ No newline at end of file +} + +sub show_storage_groups +{ + my ($anvil) = @_; + + my $server_name = $anvil->data->{switches}{server_name}; + my $server_uuid = $anvil->data->{switches}{server_uuid}; + my $anvil_uuid = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_anvil_uuid}; + my $anvil_name = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_name}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 's1:server_name' => $server_name, + 's2:server_uuid' => $server_uuid, + 's3:anvil_uuid' => $anvil_uuid, + 's4:anvil_name' => $anvil_name, + }}); + + print $anvil->Words->string({key => 'message_0348'})."\n"; + foreach my $storage_group_name (sort {$a cmp $b} keys %{$anvil->data->{storage_groups}{anvil_uuid}{$anvil_uuid}{storage_group_name}}) + { + my $storage_group_uuid = $anvil->data->{storage_groups}{anvil_uuid}{$anvil_uuid}{storage_group_name}{$storage_group_name}{storage_group_uuid}; + my $free_space = $anvil->data->{storage_groups}{anvil_uuid}{$anvil_uuid}{storage_group_uuid}{$storage_group_uuid}{free_space}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 's1:storage_group_name' => $storage_group_name, + 's2:storage_group_uuid' => $storage_group_uuid, + 's3:free_space' => $free_space." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $free_space}).")", + }}); + print $anvil->Words->string({key => 'message_0349', variables => { + storage_group_name => $storage_group_name, + storage_group_uuid => $storage_group_uuid, + free_space => $anvil->Convert->bytes_to_human_readable({'bytes' => $free_space}), + }})."\n"; + } + + return(0); +} From e8a84e1c977eeecb33c961eab19265b8ae66f811 Mon Sep 17 00:00:00 2001 From: digimer Date: Thu, 7 Sep 2023 15:37:31 -0400 Subject: [PATCH 4/5] Added job handling to anvil-manage-server-storage (needs more testing though). Signed-off-by: digimer --- share/words.xml | 2 + tools/anvil-manage-server-storage | 908 ++++++++++++++++++++++++++---- 2 files changed, 789 insertions(+), 121 deletions(-) diff --git a/share/words.xml b/share/words.xml index aaa98e68..0b165f6f 100644 --- a/share/words.xml +++ b/share/words.xml @@ -1681,6 +1681,7 @@ Note: This is a permanent action! If you protect this server again later, a full This uses 'dnf' to do an OS update on the host. If this is run on a node, 'anvil-safe-stop' will be called to withdraw the subnode from the node's cluster. If the peer subnode is also offline, hosted servers will be shut down. Update beginning. Verifying all known machines are accessible... This is a DR host, no migration possible. + Exiting. Starting: [#!variable!program!#]. @@ -3138,6 +3139,7 @@ Proceed? [y/N] - #!variable!file_name!#, (#!variable!file_size!#, md5sum: #!variable!md5sum!#) Available Storage Groups; - #!variable!storage_group_name!#, free space: #!variable!free_space!#, UUID: #!variable!storage_group_uuid!# + Preparing to managing storage for a server. Normal Password diff --git a/tools/anvil-manage-server-storage b/tools/anvil-manage-server-storage index 49329368..6c2bbc40 100755 --- a/tools/anvil-manage-server-storage +++ b/tools/anvil-manage-server-storage @@ -70,6 +70,11 @@ if (not $anvil->data->{sys}{database}{connections}) $anvil->nice_exit({exit_code => 1}); } +if ($anvil->data->{switches}{'job-uuid'}) +{ + load_job($anvil); +} + $anvil->Database->get_hosts(); $anvil->Database->get_anvils(); $anvil->Database->get_servers(); @@ -89,6 +94,10 @@ if (not $anvil->data->{switches}{server}) # Show the list of servers. show_server_list($anvil); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0456"}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0456", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 0}); } @@ -107,6 +116,10 @@ else show_server_details($anvil, 1); } +$anvil->Job->update_progress({ + progress => 100, + message => "job_0281", +}) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 0}); @@ -197,6 +210,10 @@ sub manage_disk # Can't proceed. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0457"}); show_server_details($anvil, 1); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0457", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } } @@ -284,15 +301,25 @@ sub manage_disk # User didn't specify a device. show_server_details($anvil, 1); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0458"}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0458", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } elsif (not exists $anvil->data->{server}{$short_host_name}{$server_name}{$from_source}{device}{disk}{target}{$device_target}) { # Invalid device target show_server_details($anvil, 1); - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0459", variables => { + my $variables = { device_target => $device_target, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0459", variables => $variables}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0459", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } @@ -336,12 +363,18 @@ sub manage_disk 's18:drbd_volume' => $drbd_volume, 's19:max_free_space' => $max_free_space." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $max_free_space}).")", }}); - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0749", variables => { + my $variables = { device_target => $device_target, say_boot => $say_boot, device_path => $device_path, max_free_space => $anvil->Convert->bytes_to_human_readable({'bytes' => $max_free_space}), - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0749", variables => $variables}); + $anvil->Job->update_progress({ + progress => 10, + message => "log_0749", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; # What are we doing? if ($anvil->data->{switches}{grow}) @@ -382,6 +415,10 @@ sub manage_disk_add { print $anvil->Words->string({key => 'warning_0159'})."\n"; show_storage_groups($anvil); + $anvil->Job->update_progress({ + progress => 100, + message => "warning_0159", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } @@ -424,10 +461,20 @@ sub manage_disk_add elsif ($add_size !~ /\d/) { # No digits, probably didn't set a value at all. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0423", variables => { + my $variables = { free_space => $anvil->Convert->bytes_to_human_readable({'bytes' => $free_space}), - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0423", variables => $variables}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "message_0330"}); + $anvil->Job->update_progress({ + progress => 99, + message => "error_0423", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; + $anvil->Job->update_progress({ + progress => 100, + message => "message_0330", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } elsif ($add_size !~ /^\d+$/) @@ -446,8 +493,18 @@ sub manage_disk_add else { # Not a valid size. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0424", variables => { add_size => $add_size }}); + my $variables = { add_size => $add_size }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0424", variables => $variables}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "message_0330"}); + $anvil->Job->update_progress({ + progress => 99, + message => "error_0424", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; + $anvil->Job->update_progress({ + progress => 100, + message => "message_0330", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } } @@ -512,6 +569,10 @@ sub manage_disk_add { # Failed to find a new target device name $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0425"}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0425", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } @@ -547,6 +608,10 @@ sub manage_disk_add { # Failed to find a new DRBD volume to use. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0426"}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0426", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } } @@ -559,23 +624,35 @@ sub manage_disk_add if (not $all_online) { - ### TODO: Sleep for 60 and then reset the job_progress to 0 and exit so that we keep trying. - # Adding a new disk requires all peers to be online. + # Adding a new disk requires all peers to be online. We'll exit with the progress under 100, + # so anvil-daemon will kick it back off in a minute. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0427"}); + $anvil->Job->update_progress({ + progress => 90, + message => "error_0427", + }) if $anvil->data->{switches}{'job-uuid'}; + my $progress = 80; foreach my $short_host_name (sort {$a cmp $b} keys %{$anvil->data->{peer}}) { # Record the access my $say_access = $anvil->data->{peer}{$short_host_name}{access_ip} ? $say_up : $say_down; - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0428", variables => { + my $variables = { host_name => $short_host_name, access => $say_access, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0428", variables => $variables}); + $anvil->Job->update_progress({ + progress => ++$progress, + message => "error_0428", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; } $anvil->nice_exit({exit_code => 1}); } # Still alive? Ask the user to confirm. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "message_0333", variables => { + my $progress = 20; + my $variables = { new_device_target => $new_device_target, hr_size => $hr_size, disk_device_bus => $disk_device_bus, @@ -584,7 +661,13 @@ sub manage_disk_add drbd_resource => $drbd_resource, next_drbd_volume => $next_drbd_volume, storage_group_name => $storage_group_name, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "message_0333", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "message_0333", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; if ((not $anvil->data->{switches}{confirm}) && (not $anvil->data->{switches}{'job-uuid'})) { print $anvil->Words->string({key => "message_0021"})." "; @@ -604,15 +687,30 @@ sub manage_disk_add { # It would appear that we've lost access to a peer while waiting for the answer. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0429"}); + $anvil->Job->update_progress({ + progress => 90, + message => "error_0429", + }) if $anvil->data->{switches}{'job-uuid'}; + my $progress = 90; foreach my $short_host_name (sort {$a cmp $b} keys %{$anvil->data->{peer}}) { # Record the access my $say_access = $anvil->data->{peer}{$short_host_name}{access_ip} ? $say_up : $say_down; - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0428", variables => { + my $variables = { host_name => $short_host_name, access => $say_access, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0428", variables => $variables}); + $anvil->Job->update_progress({ + progress => ++$progress, + message => "error_0428", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; } + $anvil->Job->update_progress({ + progress => 100, + message => "job_0471", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } } @@ -662,7 +760,13 @@ sub manage_disk_add if ($host_uuid eq $anvil->Get->host_uuid) { # Creating the new local LV - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0748", variables => { backing_disk => $backing_disk }}); + my $variables = { backing_disk => $backing_disk }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0748", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0748", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { output => $output, @@ -670,30 +774,46 @@ sub manage_disk_add }}); if ($return_code) { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0460", variables => { + my $variables = { backing_disk => $backing_disk, shell_call => $shell_call, return_code => $return_code, output => $output, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0460", variables => $variables}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0460", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } else { # Done! $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0750", + }) if $anvil->data->{switches}{'job-uuid'}; } } else { my $use_ip = $anvil->data->{peer}{$short_host_name}{access}{ip}; my $use_network = $anvil->data->{peer}{$short_host_name}{access}{network}; - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0756", variables => { + my $variables = { host_name => $short_host_name, backing_disk => $backing_disk, use_ip => $use_ip, use_network => $use_network, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0756", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0756", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; my ($output, $error, $return_code) = $anvil->Remote->call({ shell_call => $shell_call, target => $use_ip, @@ -705,20 +825,30 @@ sub manage_disk_add }}); if ($return_code) { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0461", variables => { + my $variables = { host_name => $short_host_name, backing_disk => $backing_disk, shell_call => $shell_call, return_code => $return_code, output => $output, error => $error, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0461", variables => $variables}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0461", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } else { # Done! $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0750", + }) if $anvil->data->{switches}{'job-uuid'}; } } } @@ -815,6 +945,10 @@ sub manage_disk_add # Validate. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0751"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0751", + }) if $anvil->data->{switches}{'job-uuid'}; my $shell_call = $anvil->data->{path}{exe}{drbdadm}." --config-to-test ".$test_file." --config-to-exclude ".$drbd_res_file." sh-nop"; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }}); my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call}); @@ -825,15 +959,25 @@ sub manage_disk_add if ($return_code) { # Something went wrong. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0430", variables => { + my $variables = { test_file => $test_file, return_code => $return_code, output => $output, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0430", variables => $variables}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0430", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } # Success! $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0752"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0752", + }) if $anvil->data->{switches}{'job-uuid'}; # Remove the test file. unlink $test_file; @@ -841,6 +985,10 @@ sub manage_disk_add # Backup the res file so we can tell the user where the current config was backed up to in # case they need to restore it. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0757"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0757", + }) if $anvil->data->{switches}{'job-uuid'}; my ($backup_file) = $anvil->Storage->backup({file => $drbd_res_file}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { backup_file => $backup_file }}); @@ -859,6 +1007,10 @@ sub manage_disk_add # Copy this to our peers. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0753"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0753", + }) if $anvil->data->{switches}{'job-uuid'}; foreach my $host_type ("node", "dr") { foreach my $short_host_name (sort {$a cmp $b} keys %{$anvil->data->{drbd_resource}{$drbd_resource}{host_type}{$host_type}{short_host_name}}) @@ -869,12 +1021,18 @@ sub manage_disk_add my $use_ip = $anvil->data->{peer}{$short_host_name}{access}{ip}; my $destination = "root\@".$use_ip.":".$anvil->data->{path}{directories}{drbd_resources}."/"; $destination =~ s/\/\//\//g; - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0754", variables => { + my $variables = { resource_file => $drbd_res_file, host_name => $short_host_name, destination => $destination, use_ip => $use_ip, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0754", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0754", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { use_ip => $use_ip, destination => $destination, @@ -891,6 +1049,10 @@ sub manage_disk_add { # There was a problem copying the new config file! $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0431"}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0431", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } } @@ -898,6 +1060,10 @@ sub manage_disk_add # Create the metadata. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0755"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0755", + }) if $anvil->data->{switches}{'job-uuid'}; foreach my $host_type ("node", "dr") { foreach my $short_host_name (sort {$a cmp $b} keys %{$anvil->data->{drbd_resource}{$drbd_resource}{host_type}{$host_type}{short_host_name}}) @@ -914,9 +1080,13 @@ sub manage_disk_add # a previous pass. if ($host_uuid eq $anvil->Get->host_uuid) { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0758", variables => { - next_drbd_volume => $next_drbd_volume, - }}); + my $variables => { next_drbd_volume => $next_drbd_volume }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0758", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0758", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { output => $output, @@ -929,18 +1099,28 @@ sub manage_disk_add # 3 == Configuration not found. if ($return_code) { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "alert", key => "warning_0160", variables => { + my $variables = { drbd_resource => $drbd_resource, next_drbd_volume => $next_drbd_volume, shell_call => $shell_call, return_code => $return_code, output => $output, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "alert", key => "warning_0160", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "warning_0160", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; } else { # Done! $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0750", + }) if $anvil->data->{switches}{'job-uuid'}; } } else @@ -948,13 +1128,19 @@ sub manage_disk_add # Create the meta-data on the peer my $use_ip = $anvil->data->{peer}{$short_host_name}{access}{ip}; my $use_network = $anvil->data->{peer}{$short_host_name}{access}{network}; - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0759", variables => { + my $variables = { host_name => $short_host_name, drbd_resource => $drbd_resource, next_drbd_volume => $next_drbd_volume, use_ip => $use_ip, use_network => $use_network, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0759", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0759", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; my ($output, $error, $return_code) = $anvil->Remote->call({ shell_call => $shell_call, target => $use_ip, @@ -966,7 +1152,7 @@ sub manage_disk_add }}); if ($return_code) { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "alert", key => "warning_0161", variables => { + my $variables = { host_name => $short_host_name, drbd_resource => $drbd_resource, next_drbd_volume => $next_drbd_volume, @@ -974,12 +1160,22 @@ sub manage_disk_add return_code => $return_code, output => $output, error => $error, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "alert", key => "warning_0161", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "warning_0161", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; } else { # Done! $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0750", + }) if $anvil->data->{switches}{'job-uuid'}; } } } @@ -1015,15 +1211,27 @@ sub manage_disk_add $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }}); # Record that we registered the job to reload the resource - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0760", variables => { + my $variables = { host_name => $short_host_name, job_uuid => $job_uuid, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0760", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0760", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; } } # Warn the user to check that anvil-daemon is running in case this hangs. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0761", variables => { drbd_resource => $drbd_resource }}); + my $variables = { drbd_resource => $drbd_resource }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0761", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0761", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; $shell_call = $anvil->data->{path}{exe}{drbdadm}." adjust ".$drbd_resource; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }}); ($output, $return_code) = $anvil->System->call({ @@ -1038,6 +1246,10 @@ sub manage_disk_add # Find which node is currently Primary and use that host to force primary to start sync. If none, # force here. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0762"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0762", + }) if $anvil->data->{switches}{'job-uuid'}; my $waiting = 1; my $wait_until = time + 300; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { wait_until => $wait_until }}); @@ -1104,7 +1316,7 @@ sub manage_disk_add if (lc($peer_disk_state) eq "negotiating") { print "- Problem!\n"; - ($peer_disk_state, $role) = reconnect_resource($anvil, $short_host_name, $peer_name, $drbd_resource, $next_drbd_volume); + ($peer_disk_state, $role, $progress) = reconnect_resource($anvil, $short_host_name, $peer_name, $drbd_resource, $next_drbd_volume, $progress); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { peer_disk_state => $peer_disk_state, role => $role, @@ -1146,6 +1358,10 @@ sub manage_disk_add { # The peers did not connect in the expected period of time. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0432"}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0432", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } sleep 2; @@ -1154,6 +1370,10 @@ sub manage_disk_add # Peers are connected! Checking if the new volume requires initial sync. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0763"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0763", + }) if $anvil->data->{switches}{'job-uuid'}; my $all_inconsistent = 1; my $primary_on_host = ""; foreach my $peer_name (sort {$a cmp $b} keys %{$anvil->data->{peers}}) @@ -1181,6 +1401,10 @@ sub manage_disk_add if ($all_inconsistent) { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0764"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0764", + }) if $anvil->data->{switches}{'job-uuid'}; my $shell_call = $anvil->data->{path}{exe}{drbdadm}." new-current-uuid --force-resync ".$drbd_resource."/".$next_drbd_volume; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }}); @@ -1204,6 +1428,10 @@ sub manage_disk_add { # Forcing primary locally... $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0765"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0765", + }) if $anvil->data->{switches}{'job-uuid'}; my ($output, $return_code) = $anvil->System->call({debug => 2, shell_call => $shell_call}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { output => $output, @@ -1213,13 +1441,19 @@ sub manage_disk_add if ($return_code) { # There was a problem trying to force the new volume to Primary. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0430", variables => { + my $variables = { drbd_resource => $drbd_resource, next_drbd_volume => $next_drbd_volume, shell_call => $shell_call, return_code => $return_code, output => $output, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0430", variables => $variables}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0430", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } @@ -1234,6 +1468,10 @@ sub manage_disk_add }}); # Success! $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0752"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0752", + }) if $anvil->data->{switches}{'job-uuid'}; } else { @@ -1244,11 +1482,17 @@ sub manage_disk_add use_network => $use_network, }}); # The resource is primary on the peer, force Primary over there. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0766", variables => { + my $variables = { host_name => $short_host_name, use_ip => $use_ip, use_network => $use_network, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0766", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0766", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; my ($output, $error, $return_code) = $anvil->Remote->call({ shell_call => $shell_call, target => $use_ip, @@ -1260,13 +1504,19 @@ sub manage_disk_add }}); if ($return_code) { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0430", variables => { + my $variables = { drbd_resource => $drbd_resource, next_drbd_volume => $next_drbd_volume, shell_call => $shell_call, return_code => $return_code, output => $output, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0430", variables => $variables}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0430", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } @@ -1284,16 +1534,28 @@ sub manage_disk_add }}); # Success! $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0752"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0752", + }) if $anvil->data->{switches}{'job-uuid'}; } } else { # Initial sync does not appear to be required. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0767"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0767", + }) if $anvil->data->{switches}{'job-uuid'}; } # Is the server running? If so, where. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0768"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0768", + }) if $anvil->data->{switches}{'job-uuid'}; my $server_host = ""; foreach my $host_type ("node", "dr") { @@ -1335,13 +1597,21 @@ sub manage_disk_add { # The server is running on this host, we'll attach the disk here. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0769"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0769", + }) if $anvil->data->{switches}{'job-uuid'}; } else { # The server is running on the peer, we'll attach the disk there. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0770", variables => { - server_host => $server_host, - }}); + my $variables = { server_host => $server_host }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0770", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0770", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; } last; } @@ -1354,6 +1624,10 @@ sub manage_disk_add { # The server isn't running anywhere, we'll attach the disk offline on this host. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0771"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0771", + }) if $anvil->data->{switches}{'job-uuid'}; $server_host = $short_host_name; $offline = 1; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { @@ -1375,11 +1649,21 @@ sub manage_disk_add if ($offline) { # Define the VM, if needed, then add the drive, dump the config and push it out. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0772", variables => { server_name => $server_name }}); + my $variables = { server_name => $server_name }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0772", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0772", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; update_definition($anvil, "define", ""); # Update the definition. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0773"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0773", + }) if $anvil->data->{switches}{'job-uuid'}; ($output, $return_code) = $anvil->System->call({shell_call => $shell_call}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { output => $output, @@ -1388,10 +1672,18 @@ sub manage_disk_add # Updating the stored definition and undefining the server now... $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0774"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0774", + }) if $anvil->data->{switches}{'job-uuid'}; update_definition($anvil, "undefine", ""); # Done! $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); + $anvil->Job->update_progress({ + progress => 100, + message => "log_0750", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 0}); } else @@ -1404,6 +1696,10 @@ sub manage_disk_add # Do the add here. update_definition($anvil, "define", ""); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0775"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0775", + }) if $anvil->data->{switches}{'job-uuid'}; ($output, $return_code) = $anvil->System->call({shell_call => $shell_call}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { output => $output, @@ -1412,16 +1708,26 @@ sub manage_disk_add if ($return_code) { # Something went wrong. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0138", variables => { + my $variables = { shell_call => $shell_call, return_code => $return_code, output => $output, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0138", variables => $variables}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0138", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } # Get the new XML $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0776"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0776", + }) if $anvil->data->{switches}{'job-uuid'}; $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 }}); @@ -1433,6 +1739,10 @@ sub manage_disk_add # Make sure the $output is valid XML. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0777"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0777", + }) if $anvil->data->{switches}{'job-uuid'}; my $problem = $anvil->Server->parse_definition({ server => $server_name, source => "from_virsh", @@ -1444,26 +1754,43 @@ sub manage_disk_add { # Failed?! $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0434"}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0434", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } # Update the stored definition and undefining the server $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0778"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0778", + }) if $anvil->data->{switches}{'job-uuid'}; update_definition($anvil, "undefine", $virsh_definition); # Done! $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); + $anvil->Job->update_progress({ + progress => 100, + message => "log_0750", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 0}); } else { # Do the add on the target. - my $use_ip = $anvil->data->{peer}{$short_host_name}{access}{ip}; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { use_ip => $use_ip }}); - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0779", variables => { + my $use_ip = $anvil->data->{peer}{$short_host_name}{access}{ip}; + my $variables = { server_host => $server_host, use_ip => $use_ip, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0779", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0779", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; my ($output, $error, $return_code) = $anvil->Remote->call({ shell_call => $shell_call, target => $use_ip, @@ -1499,6 +1826,10 @@ sub manage_disk_add { # Failed?! $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0435"}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0435", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } @@ -1509,10 +1840,18 @@ sub manage_disk_add # Updating the stored definition and undefining the server $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0780"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0780", + }) if $anvil->data->{switches}{'job-uuid'}; update_definition($anvil, "undefine", $virsh_definition); # Done! $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); + $anvil->Job->update_progress({ + progress => 100, + message => "log_0750", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 0}); } } @@ -1522,12 +1861,13 @@ sub manage_disk_add sub reconnect_resource { - my ($anvil, $short_host_name, $peer_name, $drbd_resource, $next_drbd_volume) = @_; + my ($anvil, $short_host_name, $peer_name, $drbd_resource, $next_drbd_volume, $progress) = @_; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { short_host_name => $short_host_name, peer_name => $peer_name, drbd_resource => $drbd_resource, next_drbd_volume => $next_drbd_volume, + progress => $progress, }}); my $peer_disk_state = ""; @@ -1535,7 +1875,14 @@ sub reconnect_resource # Log into the peer and disconnect, then reconnect. Then wait for the disk state to update, and # return the disk state. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0781", variables => { peer_name => $peer_name }}); + my $variables = { peer_name => $peer_name }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0781", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0781", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; + my $use_ip = $anvil->data->{peer}{$peer_name}{access}{ip}; my $shell_call = $anvil->data->{path}{exe}{drbdadm}." disconnect ".$drbd_resource; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { @@ -1553,6 +1900,10 @@ sub reconnect_resource }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0782"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0782", + }) if $anvil->data->{switches}{'job-uuid'}; sleep 1; $shell_call = $anvil->data->{path}{exe}{drbdadm}." connect ".$drbd_resource; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { @@ -1569,9 +1920,17 @@ sub reconnect_resource return_code => $return_code, }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0750", + }) if $anvil->data->{switches}{'job-uuid'}; # Now wait $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0783"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0783", + }) if $anvil->data->{switches}{'job-uuid'}; my $waiting = 1; my $wait_until = time + 300; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { wait_until => $wait_until }}); @@ -1584,10 +1943,16 @@ sub reconnect_resource if (lc($connection_state) eq "connected") { # Connected, what's the disk state for the new volume now? - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0784", variables => { + my $variables = { drbd_resource => $drbd_resource, next_drbd_volume => $next_drbd_volume, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0784", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0784", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; $peer_disk_state = $anvil->data->{drbd}{status}{$short_host_name}{resource}{$drbd_resource}{connection}{$peer_name}{volume}{$next_drbd_volume}{'peer-disk-state'}; my $replication_state = $anvil->data->{drbd}{status}{$short_host_name}{resource}{$drbd_resource}{connection}{$peer_name}{volume}{$next_drbd_volume}{'replication-state'}; $role = $anvil->data->{drbd}{status}{$short_host_name}{resource}{$drbd_resource}{connection}{$peer_name}{'peer-role'}; @@ -1600,19 +1965,33 @@ sub reconnect_resource if (lc($replication_state) ne "established") { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0785"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0785", + }) if $anvil->data->{switches}{'job-uuid'}; $disks_ready = 0; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { disks_ready => $disks_ready }}); } elsif ((not $peer_disk_state) or (lc($peer_disk_state) eq "diskless")) { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0786"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0786", + }) if $anvil->data->{switches}{'job-uuid'}; $disks_ready = 0; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { disks_ready => $disks_ready }}); } if ($disks_ready) { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0787", variables => { peer_disk_state => $peer_disk_state }}); + my $variables = { peer_disk_state => $peer_disk_state }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0787", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0787", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; $waiting = 0; $anvil->data->{peers}{$peer_name}{disk_state} = $peer_disk_state; $anvil->data->{peers}{$peer_name}{role} = $role; @@ -1631,12 +2010,16 @@ sub reconnect_resource # Timed out waiting for the peer to connect. $waiting = 0; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0788"}); - return($peer_disk_state, $role); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0788", + }) if $anvil->data->{switches}{'job-uuid'}; + return($peer_disk_state, $role, $progress); } sleep 3; } - return($peer_disk_state, $role); + return($peer_disk_state, $role, $progress); } sub manage_disk_grow @@ -1674,10 +2057,20 @@ sub manage_disk_grow elsif ($add_size !~ /\d/) { # No digits, probably didn't set a value at all. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0436", variables => { + my $variables = { max_free_space => $anvil->Convert->bytes_to_human_readable({'bytes' => $max_free_space}), - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0436", variables => $variables}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0789"}); + $anvil->Job->update_progress({ + progress => 99, + message => "error_0436", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; + $anvil->Job->update_progress({ + progress => 100, + message => "log_0789", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } elsif ($add_size !~ /^\d+$/) @@ -1698,6 +2091,14 @@ sub manage_disk_grow # Not a valid size. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0437"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0789"}); + $anvil->Job->update_progress({ + progress => 99, + message => "error_0437", + }) if $anvil->data->{switches}{'job-uuid'}; + $anvil->Job->update_progress({ + progress => 100, + message => "log_0789", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } } @@ -1706,26 +2107,46 @@ sub manage_disk_grow if ($add_size < 4194304) { # Must be a typo, this is less than the size of a single extent. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0438", variables => { + my $variables = { add_size => $anvil->Convert->bytes_to_human_readable({'bytes' => $add_size}), - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0438", variables => $variables}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0789"}); + $anvil->Job->update_progress({ + progress => 99, + message => "error_0438", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; + $anvil->Job->update_progress({ + progress => 100, + message => "log_0789", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } elsif ($add_size > $max_free_space) { # Not enough space. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0439", variables => { + my $variables = { add_size => $anvil->Convert->bytes_to_human_readable({'bytes' => $add_size}), max_free_space => $anvil->Convert->bytes_to_human_readable({'bytes' => $max_free_space}), - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0439", variables => $variables}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0789"}); + $anvil->Job->update_progress({ + progress => 99, + message => "error_0439", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; + $anvil->Job->update_progress({ + progress => 100, + message => "log_0789", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } # Are they asking for an available amount of space? - my $say_up = $anvil->Words->string({key => 'message_0331'}); - my $say_down = $anvil->Words->string({key => 'message_0332'}); + my $say_up = $anvil->Words->string({key => 'message_0331'}); + my $say_down = $anvil->Words->string({key => 'message_0332'}); ### TODO: Make this work without the peer node being online. # The server is allowed to be running, but both nodes and any DR hosts this is replicating to @@ -1737,14 +2158,29 @@ sub manage_disk_grow { # All peers have to be online. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0440"}); + $anvil->Job->update_progress({ + progress => 90, + message => "error_0440", + }) if $anvil->data->{switches}{'job-uuid'}; + my $progress = 90; foreach my $short_host_name (sort {$a cmp $b} keys %{$anvil->data->{peer}}) { my $say_access = $anvil->data->{peer}{$short_host_name}{access_ip} ? $say_up : $say_down; - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0428", variables => { + my $variables = { host_name => $short_host_name, access => $say_access, - }}); - } + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0428", variables => $variables}); + $anvil->Job->update_progress({ + progress => ++$progress, + message => "error_0428", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; + } + $anvil->Job->update_progress({ + progress => 100, + message => "job_0471", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } @@ -1766,7 +2202,13 @@ sub manage_disk_grow } # Preparing to grow the storage - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0790", variables => { size => $hr_size }}); + my $variables = { size => $hr_size }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0790", variables => $variables}); + $anvil->Job->update_progress({ + progress => 15, + message => "log_0790", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; if (not $anvil->data->{switches}{confirm}) { print $anvil->Words->string({key => "message_0021"})." "; @@ -1776,6 +2218,10 @@ sub manage_disk_grow { # Abort $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "message_0022"}); + $anvil->Job->update_progress({ + progress => 100, + message => "message_0022", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 0}); } @@ -1786,18 +2232,34 @@ sub manage_disk_grow if (not $all_online) { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0441"}); + $anvil->Job->update_progress({ + progress => 90, + message => "error_0441", + }) if $anvil->data->{switches}{'job-uuid'}; + my $progress = 90; foreach my $short_host_name (sort {$a cmp $b} keys %{$anvil->data->{peer}}) { my $say_access = $anvil->data->{peer}{$short_host_name}{access_ip} ? $say_up : $say_down; - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0428", variables => { + my $variables = { host_name => $short_host_name, access => $say_access, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0428", variables => $variables}); + $anvil->Job->update_progress({ + progress => ++$progress, + message => "error_0428", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; } + $anvil->Job->update_progress({ + progress => 100, + message => "job_0471", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } } + my $progress = 16; foreach my $host_type ("node", "dr") { foreach my $short_host_name (sort {$a cmp $b} keys %{$anvil->data->{drbd_resource}{$drbd_resource}{host_type}{$host_type}{short_host_name}}) @@ -1813,7 +2275,13 @@ sub manage_disk_grow }}); if ($host_uuid eq $anvil->Get->host_uuid) { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0791", variables => { backing_disk => $backing_disk }}); + my $variables = { backing_disk => $backing_disk }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0791", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0791", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { output => $output, @@ -1821,30 +2289,46 @@ sub manage_disk_grow }}); if ($return_code) { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0442", variables => { + my $variables = { backing_disk => $backing_disk, shell_call => $shell_call, return_code => $return_code, output => $output, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0442", variables => $variables}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0442", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } else { # Done $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0750", + }) if $anvil->data->{switches}{'job-uuid'}; } } else { my $use_ip = $anvil->data->{peer}{$short_host_name}{access}{ip}; my $use_network = $anvil->data->{peer}{$short_host_name}{access}{network}; - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0792", variables => { + my $variables = { host_name => $short_host_name, backing_disk => $backing_disk, use_ip => $use_ip, use_network => $use_network, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0792", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0792", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; my ($output, $error, $return_code) = $anvil->Remote->call({ shell_call => $shell_call, target => $use_ip, @@ -1856,19 +2340,29 @@ sub manage_disk_grow }}); if ($return_code) { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0443", variables => { + my $variables = { backing_disk => $backing_disk, shell_call => $shell_call, return_code => $return_code, output => $output, error => $error, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0443", variables => $variables}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0443", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } else { # Done $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0750", + }) if $anvil->data->{switches}{'job-uuid'}; } } } @@ -1876,6 +2370,10 @@ sub manage_disk_grow # Locally, we'll call DRBD to resize. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0793"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0793", + }) if $anvil->data->{switches}{'job-uuid'}; my $shell_call = $anvil->data->{path}{exe}{drbdadm}." resize ".$drbd_resource."/".$drbd_volume; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }}); @@ -1886,26 +2384,46 @@ sub manage_disk_grow }}); if ($return_code) { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0444", variables => { + my $variables = { drbd_resource => $drbd_resource, drbd_volume => $drbd_volume, shell_call => $shell_call, return_code => $return_code, output => $output, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0444", variables => $variables}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0444", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } else { # Done $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0750", + }) if $anvil->data->{switches}{'job-uuid'}; } # Call scan-lvm and scan-drbd to make sure the databases are updated. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0794"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0794", + }) if $anvil->data->{switches}{'job-uuid'}; foreach my $agent ("scan-drbd", "scan-lvm") { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0740", variables => { agent => $agent }}); + my $variables => { agent => $agent }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0740", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0740", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; my $shell_call = $anvil->data->{path}{directories}{scan_agents}."/".$agent."/".$agent.$anvil->Log->switches(); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }}); @@ -1920,7 +2438,13 @@ sub manage_disk_grow }}); if ($host_uuid eq $anvil->Get->host_uuid) { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0795", variables => { agent => $agent }}); + my $variables = { agent => $agent }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0795", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0795", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { output => $output, @@ -1929,17 +2453,27 @@ sub manage_disk_grow # Done $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0750", + }) if $anvil->data->{switches}{'job-uuid'}; } else { my $use_ip = $anvil->data->{peer}{$short_host_name}{access}{ip}; my $use_network = $anvil->data->{peer}{$short_host_name}{access}{network}; - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0796", variables => { + my $variables = { agent => $agent, host_name => $short_host_name, use_ip => $use_ip, use_network => $use_network, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0796", variables => $variables}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0796", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; my ($output, $error, $return_code) = $anvil->Remote->call({ shell_call => $shell_call, target => $use_ip, @@ -1952,6 +2486,10 @@ sub manage_disk_grow # Done $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); + $anvil->Job->update_progress({ + progress => ($progress += 2), + message => "log_0750", + }) if $anvil->data->{switches}{'job-uuid'}; } } } @@ -1959,6 +2497,10 @@ sub manage_disk_grow # Success! $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0797"}); + $anvil->Job->update_progress({ + progress => 100, + message => "log_0797", + }) if $anvil->data->{switches}{'job-uuid'}; return(0); } @@ -2002,6 +2544,10 @@ sub manage_optical # Can't proceed. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0445"}); show_server_details($anvil, 1); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0445", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } } @@ -2073,6 +2619,10 @@ sub manage_optical show_server_details($anvil, 0); show_files($anvil); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0446"}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0446", + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } elsif (not exists $anvil->data->{server}{$short_host_name}{$server_name}{$from_source}{device}{cdrom}{target}{$device_target}) @@ -2080,9 +2630,13 @@ sub manage_optical # Invalid device target show_server_details($anvil, 0); show_files($anvil); - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0447", variables => { - device_target => $device_target, - }}); + my $variables = { device_target => $device_target }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0447", variables => $variables}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0447", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } @@ -2126,10 +2680,14 @@ sub manage_optical my $iso = $anvil->data->{switches}{insert}; if (not -f $iso) { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0448", variables => { - iso => $iso, - }}); + my $variables = { iso => $iso }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0448", variables => $variables}); update_definition($anvil, "undefine", ""); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0448", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } else @@ -2140,25 +2698,43 @@ sub manage_optical } # If the server is running, update the on-disk and in-DB definition. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0798", variables => { server_name => $server_name }}); + my $variables = { server_name => $server_name }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0798", variables => $variables}); + $anvil->Job->update_progress({ + progress => 25, + message => "log_0798", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; update_definition($anvil, "define", ""); # Now we can modify the server using virsh. if ($anvil->data->{switches}{insert}) { # Inserting - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0799", variables => { + my $variables = { insert => $anvil->data->{switches}{insert}, device_target => $device_target, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0799", variables => $variables}); + $anvil->Job->update_progress({ + progress => 50, + message => "log_0799", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; } elsif ($anvil->data->{switches}{eject}) { # Ejecting - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0800", variables => { + my $variables = { device_path => $device_path, device_target => $device_target, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0800", variables => $variables}); + $anvil->Job->update_progress({ + progress => 50, + message => "log_0800", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; } else { @@ -2166,17 +2742,27 @@ sub manage_optical if ($device_path) { # Disc is already in the drive - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0449", variables => { + my $variables = { device_target => $device_target, device_path => $device_path, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0449", variables => $variables}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0449", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; } else { # Drive has no disc in it. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0450", variables => { - device_target => $device_target, - }}); + my $variables = { device_target => $device_target }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0450", variables => $variables}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0450", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; } $anvil->nice_exit({exit_code => 0}); } @@ -2188,10 +2774,18 @@ sub manage_optical # Updating the stored definition and undefining the server now $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0801"}); + $anvil->Job->update_progress({ + progress => 75, + message => "log_0801", + }) if $anvil->data->{switches}{'job-uuid'}; update_definition($anvil, "undefine", ""); # Done $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0750"}); + $anvil->Job->update_progress({ + progress => 100, + message => "log_0750", + }) if $anvil->data->{switches}{'job-uuid'}; return(0); } @@ -2685,28 +3279,43 @@ sub validate_server if (not $anvil->data->{switches}{server_uuid}) { show_server_list($anvil); + my $variables = { + server => $anvil->data->{switches}{server}, + anvil => $anvil->data->{switches}{anvil_name}, + }; if ($anvil->data->{switches}{anvil_uuid}) { # Not found on the requested Anvil! node. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0451", variables => { - server => $anvil->data->{switches}{server}, - anvil => $anvil->data->{switches}{anvil_name}, - }}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0451", variables => $variables}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0451", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; } else { # Not found at all. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0452", variables => { - server => $anvil->data->{switches}{server}, - }}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0452", variables => $variables}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0452", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; } $anvil->nice_exit({exit_code => 1}); } - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0802", variables => { + my $variables = { server_name => $anvil->data->{switches}{server_name}, server_uuid => $anvil->data->{switches}{server_uuid}, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0802", variables => $variables}); + $anvil->Job->update_progress({ + progress => 2, + message => "log_0802", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; my $short_host_name = $anvil->Get->short_host_name; my $server_name = $anvil->data->{switches}{server_name}; my $server_uuid = $anvil->data->{switches}{server_uuid}; @@ -2734,9 +3343,15 @@ sub validate_server if ($server_state eq "DELETED") { # The server has been deleted - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0453", variables => { + my $variables = { server => $server_name, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0453", variables => $variables}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0453", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } @@ -2766,10 +3381,16 @@ sub validate_server host_uuid => $server_host_uuid, }); - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0454", variables => { + my $variables = { server => $server_name, host_name => $server_host_name, - }}); + }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0454", variables => $variables}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0454", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } } @@ -2925,9 +3546,13 @@ sub update_definition if (not $use_definition) { # What?! - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0455", variables => { - server => $server_name, - }}); + my $variables = { server => $server_name }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0455", variables => $variables}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0455", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; $anvil->nice_exit({exit_code => 1}); } @@ -3118,3 +3743,44 @@ sub show_storage_groups return(0); } + +sub load_job +{ + my ($anvil) = @_; + + $anvil->Job->clear({ + debug => 2, + job_uuid => $anvil->data->{switches}{'job-uuid'}, + }); + $anvil->Job->get_job_details({ + debug => 2, + job_uuid => $anvil->data->{switches}{'job-uuid'}, + }); + + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 'jobs::job_data' => $anvil->data->{jobs}{job_data}, + }}); + foreach my $line (split/\n/, $anvil->data->{jobs}{job_data}) + { + my ($variable, $value) = ($line =~ /^(.*)=(.*?)/); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 's1:line' => $line, + 's2:variable' => $variable, + 's3:value' => $value, + }}); + + $anvil->data->{switches}{$variable} = $value; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + "switches::${variable}" => $anvil->data->{switches}{$variable}, + }}); + } + + $anvil->Job->update_progress({ + progress => 1, + job_picked_up_by => $$, + job_picked_up_at => time, + message => "message_0350", + }); + + return(0); +} From 3c9086d1f3019889f77f19fd5fddfb2f2819aeb9 Mon Sep 17 00:00:00 2001 From: digimer Date: Thu, 7 Sep 2023 20:06:00 -0400 Subject: [PATCH 5/5] Fixed bugs related to running jobs. Signed-off-by: digimer --- Anvil/Tools.pm | 1 + share/words.xml | 4 ++- tools/anvil-manage-server-storage | 57 ++++++++++++++++++++++++------- 3 files changed, 48 insertions(+), 14 deletions(-) diff --git a/Anvil/Tools.pm b/Anvil/Tools.pm index c2f0b067..f77bea0d 100644 --- a/Anvil/Tools.pm +++ b/Anvil/Tools.pm @@ -1154,6 +1154,7 @@ sub _set_paths 'anvil-manage-files' => "/usr/sbin/anvil-manage-files", 'anvil-manage-firewall' => "/usr/sbin/anvil-manage-firewall", 'anvil-manage-keys' => "/usr/sbin/anvil-manage-keys", + 'anvil-manage-server-storage' => "/usr/sbin/anvil-manage-server-storage", 'anvil-manage-power' => "/usr/sbin/anvil-manage-power", 'anvil-manage-vnc-pipe' => "/usr/sbin/anvil-manage-vnc-pipe", 'anvil-migrate-server' => "/usr/sbin/anvil-migrate-server", diff --git a/share/words.xml b/share/words.xml index 0b165f6f..34313d23 100644 --- a/share/words.xml +++ b/share/words.xml @@ -654,7 +654,7 @@ The error was: [ Error ] - Manual update to the server is likely required now. [ Error ] - Please specify the size you would like to grow this disk by. The maximum size is: [#!variable!max_free_space!#]. - [ Error ] - The requested size: [#!variable!add_size!#] could not be interpreted. + [ Error ] - The storage group: [#!variable!storage_group!#] was not found. [ Error ] - The requested size: [#!variable!add_size!#] is too small, it's less than an single extent. [ Error ] - The requested size: [#!variable!add_size!#] is too large. The available size is: [#!variable!max_free_space!#]. [ Error ] - Growing the storage requires all peers to be online. @@ -1682,6 +1682,8 @@ Note: This is a permanent action! If you protect this server again later, a full Update beginning. Verifying all known machines are accessible... This is a DR host, no migration possible. Exiting. + Server Storage Management + This job manages the storage on a given hosted server. It can grow an existing disk, add a new disk, insert an ISO into an optical disc, or eject a disc. Starting: [#!variable!program!#]. diff --git a/tools/anvil-manage-server-storage b/tools/anvil-manage-server-storage index 6c2bbc40..f7dadfbc 100755 --- a/tools/anvil-manage-server-storage +++ b/tools/anvil-manage-server-storage @@ -16,8 +16,8 @@ # - anvil-manage-server-storage --server srv01-fs37 --optical sda --insert /mnt/shared/files/CentOS-5.11-x86_64-bin-DVD-1of2.iso # - anvil-manage-server-storage --server srv01-fs37 --optical sda --eject # - Disk -# - anvil-manage-server-storage --server srv01-fs37 --disk vdb --grow {+10GiB,150GiB} -# - anvil-manage-server-storage --server srv01-fs37 --disk vdb --grow {+10GiB,150GiB} +# - anvil-manage-server-storage --server srv01-fs37 --disk vdb --grow {+10%,150GiB} +# - anvil-manage-server-storage --server srv01-fs37 --add 50G --storage-group "Storage group 1" # use strict; @@ -296,7 +296,7 @@ sub manage_disk my $device_target = $anvil->data->{switches}{disk}; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { device_target => $device_target }}); - if ($anvil->data->{switches}{disk} eq "#!SET!#") + if (($anvil->data->{switches}{disk} eq "#!SET!#") or ($anvil->data->{switches}{disk} eq "1")) { # User didn't specify a device. show_server_details($anvil, 1); @@ -411,6 +411,9 @@ sub manage_disk_add my $say_down = $anvil->Words->string({key => 'message_0332'}); # Do we have a storage group? + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 'switches::storage-group' => $anvil->data->{switches}{'storage-group'}, + }}); if (not $anvil->data->{switches}{'storage-group'}) { print $anvil->Words->string({key => 'warning_0159'})."\n"; @@ -424,8 +427,10 @@ sub manage_disk_add # Make sure that the passed my $storage_group_switch = $anvil->data->{switches}{'storage-group'}; - my $storage_group_uuid = ""; - my $storage_group_name = ""; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { storage_group_switch => $storage_group_switch }}); + + my $storage_group_uuid = ""; + my $storage_group_name = ""; if (exists $anvil->data->{storage_groups}{anvil_uuid}{$anvil_uuid}{storage_group_name}{$storage_group_switch}) { $storage_group_uuid = $anvil->data->{storage_groups}{anvil_uuid}{$anvil_uuid}{storage_group_name}{$storage_group_switch}{storage_group_uuid}; @@ -444,6 +449,18 @@ sub manage_disk_add storage_group_name => $storage_group_name, }}); } + else + { + # Bad storage group. + my $variables = { storage_group => $storage_group_switch }; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0437", variables => $variables}); + $anvil->Job->update_progress({ + progress => 100, + message => "error_0437", + variables => $variables, + }) if $anvil->data->{switches}{'job-uuid'}; + $anvil->nice_exit({exit_code => 1}); + } # Did we get a valid disk size? my $free_space = $anvil->data->{storage_groups}{anvil_uuid}{$anvil_uuid}{storage_group_uuid}{$storage_group_uuid}{free_space}; @@ -1080,7 +1097,7 @@ sub manage_disk_add # a previous pass. if ($host_uuid eq $anvil->Get->host_uuid) { - my $variables => { next_drbd_volume => $next_drbd_volume }; + my $variables = { next_drbd_volume => $next_drbd_volume }; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0758", variables => $variables}); $anvil->Job->update_progress({ progress => ($progress += 2), @@ -1225,7 +1242,7 @@ sub manage_disk_add } # Warn the user to check that anvil-daemon is running in case this hangs. - my $variables = { drbd_resource => $drbd_resource }; + $variables = { drbd_resource => $drbd_resource }; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0761", variables => $variables}); $anvil->Job->update_progress({ progress => ($progress += 2), @@ -2043,7 +2060,8 @@ sub manage_disk_grow }}); # Are they asking for an available amount of space? - my $add_size = $anvil->data->{switches}{grow}; + my $add_size = $anvil->data->{switches}{grow}; + $add_size =~ s/^\+//; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { add_size => $add_size }}); if ($add_size =~ /^(\d+)%$/) { @@ -2089,11 +2107,11 @@ sub manage_disk_grow else { # Not a valid size. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0437"}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0424"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0789"}); $anvil->Job->update_progress({ progress => 99, - message => "error_0437", + message => "error_0424", }) if $anvil->data->{switches}{'job-uuid'}; $anvil->Job->update_progress({ progress => 100, @@ -2209,7 +2227,7 @@ sub manage_disk_grow message => "log_0790", variables => $variables, }) if $anvil->data->{switches}{'job-uuid'}; - if (not $anvil->data->{switches}{confirm}) + if ((not $anvil->data->{switches}{confirm}) && (not $anvil->data->{switches}{'job-uuid'})) { print $anvil->Words->string({key => "message_0021"})." "; my $answer = ; @@ -2417,7 +2435,7 @@ sub manage_disk_grow }) if $anvil->data->{switches}{'job-uuid'}; foreach my $agent ("scan-drbd", "scan-lvm") { - my $variables => { agent => $agent }; + my $variables = { agent => $agent }; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0740", variables => $variables}); $anvil->Job->update_progress({ progress => ($progress += 2), @@ -2538,6 +2556,17 @@ sub manage_optical last; } } + else + { + foreach my $device_target (sort {$a cmp $b} keys %{$anvil->data->{server}{$short_host_name}{$server_name}{$from_source}{device}{cdrom}{target}}) + { + my $device_path = $anvil->data->{server}{$short_host_name}{$server_name}{$from_source}{device}{cdrom}{target}{$device_target}{path}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + device_target => $device_target, + device_path => $device_path, + }}); + } + } if (not $anvil->data->{switches}{optical}) { @@ -3762,7 +3791,9 @@ sub load_job }}); foreach my $line (split/\n/, $anvil->data->{jobs}{job_data}) { - my ($variable, $value) = ($line =~ /^(.*)=(.*?)/); + my ($variable, $value) = ($line =~ /^(.*)=(.*)$/); + $value =~ s/^"(.*)\"/$1/; + $value =~ s/^'(.*)\'/$1/; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 's1:line' => $line, 's2:variable' => $variable,