* Added strings for making size suffixes translatable and updated Convert->bytes_to_human_readable to use them.

* Fixed a bug in tools/anvil-update-states where the MAC of an interface that is the backup in an active-backup bond would be the MAC of the active member instead of its real MAC.
* Fixed a bug in Convert->add_commas() where a passed in value of '0' returned an empty string.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 5 years ago
parent b9e8d2a971
commit 7cf1db3b37
  1. 75
      Anvil/Tools/Convert.pm
  2. 11
      Anvil/Tools/Database.pm
  3. 20
      Anvil/Tools/Network.pm
  4. 17
      share/words.xml
  5. 6
      tools/anvil-update-states

@ -125,7 +125,7 @@ sub add_commas
return ($number);
}
local($_) = $whole ? $whole : "";
local($_) = defined $whole ? $whole : "";
1 while s/^(-?\d+)(\d{3})/$1,$2/;
$whole = $_;
@ -249,53 +249,53 @@ sub bytes_to_human_readable
{
# Yebibyte
$human_readable_size = sprintf("%.3f", ($human_readable_size /= (2 ** 80)));
$suffix = "YiB";
$suffix = $anvil->Words->string({key => "suffix_0030"});
}
elsif ($unit =~ /Z/i)
{
# Zebibyte
$human_readable_size = sprintf("%.3f", ($human_readable_size /= (2 ** 70)));
$suffix = "ZiB";
$suffix = $anvil->Words->string({key => "suffix_0029"});
}
elsif ($unit =~ /E/i)
{
# Exbibyte
$human_readable_size = sprintf("%.3f", ($human_readable_size /= (2 ** 60)));
$suffix = "EiB";
$suffix = $anvil->Words->string({key => "suffix_0028"});
}
elsif ($unit =~ /P/i)
{
# Pebibyte
$human_readable_size = sprintf("%.3f", ($human_readable_size /= (2 ** 50)));
$suffix = "PiB";
$suffix = $anvil->Words->string({key => "suffix_0027"});
}
elsif ($unit =~ /T/i)
{
# Tebibyte
$human_readable_size = sprintf("%.2f", ($human_readable_size /= (2 ** 40)));
$suffix = "TiB";
$suffix = $anvil->Words->string({key => "suffix_0026"});
}
elsif ($unit =~ /G/i)
{
# Gibibyte
$human_readable_size = sprintf("%.2f", ($human_readable_size /= (2 ** 30)));
$suffix = "GiB";
$suffix = $anvil->Words->string({key => "suffix_0025"});
}
elsif ($unit =~ /M/i)
{
# Mebibyte
$human_readable_size = sprintf("%.2f", ($human_readable_size /= (2 ** 20)));
$suffix = "MiB";
$suffix = $anvil->Words->string({key => "suffix_0024"});
}
elsif ($unit =~ /K/i)
{
# Kibibyte
$human_readable_size = sprintf("%.1f", ($human_readable_size /= (2 ** 10)));
$suffix = "KiB";
$suffix = $anvil->Words->string({key => "suffix_0023"});
}
else
{
$suffix = "B";
$suffix = $anvil->Words->string({key => "suffix_0014"});
}
}
else
@ -305,53 +305,53 @@ sub bytes_to_human_readable
{
# Yebibyte
$human_readable_size = sprintf("%.3f", ($human_readable_size /= (2 ** 80)));
$suffix = "YiB";
$suffix = $anvil->Words->string({key => "suffix_0030"});
}
elsif ($human_readable_size >= (2 ** 70))
{
# Zebibyte
$human_readable_size = sprintf("%.3f", ($human_readable_size /= (2 ** 70)));
$suffix = "ZiB";
$suffix = $anvil->Words->string({key => "suffix_0029"});
}
elsif ($human_readable_size >= (2 ** 60))
{
# Exbibyte
$human_readable_size = sprintf("%.3f", ($human_readable_size /= (2 ** 60)));
$suffix = "EiB";
$suffix = $anvil->Words->string({key => "suffix_0028"});
}
elsif ($human_readable_size >= (2 ** 50))
{
# Pebibyte
$human_readable_size = sprintf("%.3f", ($human_readable_size /= (2 ** 50)));
$suffix = "PiB";
$suffix = $anvil->Words->string({key => "suffix_0027"});
}
elsif ($human_readable_size >= (2 ** 40))
{
# Tebibyte
$human_readable_size = sprintf("%.2f", ($human_readable_size /= (2 ** 40)));
$suffix = "TiB";
$suffix = $anvil->Words->string({key => "suffix_0026"});
}
elsif ($human_readable_size >= (2 ** 30))
{
# Gibibyte
$human_readable_size = sprintf("%.2f", ($human_readable_size /= (2 ** 30)));
$suffix = "GiB";
$suffix = $anvil->Words->string({key => "suffix_0025"});
}
elsif ($human_readable_size >= (2 ** 20))
{
# Mebibyte
$human_readable_size = sprintf("%.2f", ($human_readable_size /= (2 ** 20)));
$suffix = "MiB";
$suffix = $anvil->Words->string({key => "suffix_0024"});
}
elsif ($human_readable_size >= (2 ** 10))
{
# Kibibyte
$human_readable_size = sprintf("%.1f", ($human_readable_size /= (2 ** 10)));
$suffix = "KiB";
$suffix = $anvil->Words->string({key => "suffix_0023"});
}
else
{
$suffix = "B";
$suffix = $anvil->Words->string({key => "suffix_0014"});
}
}
}
@ -365,53 +365,53 @@ sub bytes_to_human_readable
{
# Yottabyte
$human_readable_size = sprintf("%.3f", ($human_readable_size /= (10 ** 24)));
$suffix = "YB";
$suffix = $anvil->Words->string({key => "suffix_0022"});
}
elsif ($unit =~ /Z/i)
{
# Zettabyte
$human_readable_size = sprintf("%.3f", ($human_readable_size /= (10 ** 21)));
$suffix = "ZB";
$suffix = $anvil->Words->string({key => "suffix_0021"});
}
elsif ($unit =~ /E/i)
{
# Exabyte
$human_readable_size = sprintf("%.3f", ($human_readable_size /= (10 ** 18)));
$suffix = "EB";
$suffix = $anvil->Words->string({key => "suffix_0020"});
}
elsif ($unit =~ /P/i)
{
# Petabyte
$human_readable_size = sprintf("%.3f", ($human_readable_size /= (10 ** 15)));
$suffix = "PB";
$suffix = $anvil->Words->string({key => "suffix_0019"});
}
elsif ($unit =~ /T/i)
{
# Terabyte
$human_readable_size = sprintf("%.2f", ($human_readable_size /= (10 ** 12)));
$suffix = "TB";
$suffix = $anvil->Words->string({key => "suffix_0018"});
}
elsif ($unit =~ /G/i)
{
# Gigabyte
$human_readable_size = sprintf("%.2f", ($human_readable_size /= (10 ** 9)));
$suffix = "GB";
$suffix = $anvil->Words->string({key => "suffix_0017"});
}
elsif ($unit =~ /M/i)
{
# Megabyte
$human_readable_size = sprintf("%.2f", ($human_readable_size /= (10 ** 6)));
$suffix = "MB";
$suffix = $anvil->Words->string({key => "suffix_0016"});
}
elsif ($unit =~ /K/i)
{
# Kilobyte
$human_readable_size = sprintf("%.1f", ($human_readable_size /= (10 ** 3)));
$suffix = "KB";
$suffix = $anvil->Words->string({key => "suffix_0015"});
}
else
{
$suffix = "b";
$suffix = $anvil->Words->string({key => "suffix_0014"});
}
}
else
@ -421,53 +421,54 @@ sub bytes_to_human_readable
{
# Yottabyte
$human_readable_size = sprintf("%.3f", ($human_readable_size /= (10 ** 24)));
$suffix = "YB";
$suffix = $anvil->Words->string({key => "suffix_0022"});
}
elsif ($human_readable_size >= (10 ** 21))
{
# Zettabyte
$human_readable_size = sprintf("%.3f", ($human_readable_size /= (10 ** 21)));
$suffix = "ZB";
$suffix = $anvil->Words->string({key => "suffix_0021"});
}
elsif ($human_readable_size >= (10 ** 18))
{
# Exabyte
$human_readable_size = sprintf("%.3f", ($human_readable_size /= (10 ** 18)));
$suffix = "EB";
$suffix = $anvil->Words->string({key => "suffix_0020"});
}
elsif ($human_readable_size >= (10 ** 15))
{
# Petabyte
$human_readable_size = sprintf("%.3f", ($human_readable_size /= (10 ** 15)));
$suffix = "PB";
$suffix = $anvil->Words->string({key => "suffix_0019"});
}
elsif ($human_readable_size >= (10 ** 12))
{
# Terabyte
$human_readable_size = sprintf("%.2f", ($human_readable_size /= (10 ** 12)));
$suffix = "TB";
$suffix = $anvil->Words->string({key => "suffix_0018"});
}
elsif ($human_readable_size >= (10 ** 9))
{
# Gigabyte
$human_readable_size = sprintf("%.2f", ($human_readable_size /= (10 ** 9)));
$suffix = "GB";
$suffix = $anvil->Words->string({key => "suffix_0017"});
}
elsif ($human_readable_size >= (10 ** 6))
{
# Megabyte
$human_readable_size = sprintf("%.2f", ($human_readable_size /= (10 ** 6)));
$suffix = "MB";
$suffix = $anvil->Words->string({key => "suffix_0016"});
}
elsif ($human_readable_size >= (10 ** 3))
{
# Kilobyte
$human_readable_size = sprintf("%.1f", ($human_readable_size /= (10 ** 3)));
$suffix = "KB";
$suffix = $anvil->Words->string({key => "suffix_0015"});
}
else
{
$suffix = "b";
# Bytes
$suffix = $anvil->Words->string({key => "suffix_0014"});
}
}
}

@ -4437,7 +4437,16 @@ sub insert_or_update_network_interfaces
{
# See if I know this NIC by referencing it's MAC and name. The name is needed because virtual
# devices can share the MAC with the real interface.
my $query = "SELECT network_interface_uuid FROM network_interfaces WHERE network_interface_mac_address = ".$anvil->Database->quote($network_interface_mac_address)." AND network_interface_name = ".$anvil->Database->quote($network_interface_name).";";
my $query = "
SELECT
network_interface_uuid
FROM
network_interfaces
WHERE
network_interface_mac_address = ".$anvil->Database->quote($network_interface_mac_address)."
AND
network_interface_name = ".$anvil->Database->quote($network_interface_name)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$network_interface_uuid = $anvil->Database->query({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__})->[0]->[0];

@ -805,10 +805,10 @@ FROM
AND
bond_host_uuid = ".$anvil->Database->quote($host_uuid)."
;";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0124", variables => { query => $query }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0124", variables => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
results => $results,
count => $count,
}});
@ -893,10 +893,10 @@ WHERE
AND
bridge_host_uuid = ".$anvil->Database->quote($host_uuid)."
;";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0124", variables => { query => $query }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0124", variables => { query => $query }});
$results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
$count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
results => $results,
count => $count,
}});
@ -966,10 +966,10 @@ AND
ORDER BY
modified_date DESC
;";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0124", variables => { query => $query }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0124", variables => { query => $query }});
$results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
$count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
results => $results,
count => $count,
}});
@ -991,11 +991,19 @@ ORDER BY
if (($network_interface_bond_uuid) && (defined $anvil->data->{network}{$host}{bond_uuid}{$network_interface_bond_uuid}{name}))
{
$bond_name = $anvil->data->{network}{$host}{bond_uuid}{$network_interface_bond_uuid}{name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
network_interface_name => $network_interface_name,
bond_name => $bond_name,
}});
push @{$anvil->data->{network}{$host}{interface}{$bond_name}{interfaces}}, $network_interface_name;
}
if (($network_interface_bridge_uuid) && (defined $anvil->data->{network}{$host}{bridge_uuid}{$network_interface_bridge_uuid}{name}))
{
$bridge_name = $anvil->data->{network}{$host}{bridge_uuid}{$network_interface_bridge_uuid}{name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
network_interface_name => $network_interface_name,
bridge_name => $bridge_name,
}});
push @{$anvil->data->{network}{$host}{interface}{$bridge_name}{interfaces}}, $network_interface_name;
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {

@ -1029,6 +1029,15 @@ If you are comfortable that the target has changed for a known reason, you can s
<key name="suffix_0045">Exbibytes</key> <!-- Long suffix for 'exbibyte' (1,152,921,504,606,846,976 bytes). -->
<key name="suffix_0046">Zebibytes</key> <!-- Long suffix for 'zebibyte' (1,180,591,620,717,411,303,424 bytes). -->
<key name="suffix_0047">Yobibytes</key> <!-- Long suffix for 'yobibyte' (1,208,925,819,614,629,174,706,176 bytes). -->
<key name="suffix_0048">bps</key> <!-- Short suffix for 'bits per second'. -->
<key name="suffix_0049">Kbps</key> <!-- Short suffix for 'kilobits per second' (1,000 bits per second). -->
<key name="suffix_0050">Mbps</key> <!-- Short suffix for 'megabits per second' (1,000,000 bits per second). -->
<key name="suffix_0051">Gbps</key> <!-- Short suffix for 'gigabits per second' (1,000,000,000 bits per second). -->
<key name="suffix_0052">Tbps</key> <!-- Short suffix for 'terabits per second' (1,000,000,000,000 bits per second). -->
<key name="suffix_0053">Pbps</key> <!-- Short suffix for 'petabits per second' (1,000,000,000,000,000 bits per second). -->
<key name="suffix_0054">Ebps</key> <!-- Short suffix for 'exabits per second' (1,000,000,000,000,000,000 bits per second). -->
<key name="suffix_0055">Zbps</key> <!-- Short suffix for 'zettabits per second' (1,000,000,000,000,000,000,000 bits per second). -->
<key name="suffix_0056">Ybps</key> <!-- Short suffix for 'yotabits per second' (1,000,000,000,000,000,000,000,000 bits per second). -->
<key name="prefix_0001">[ Error ] - </key>
<key name="prefix_0002">[ Warning ] - </key>
@ -1250,6 +1259,14 @@ Failed to generate an RSA public key for the user: [#!variable!user!#]. The outp
<key name="unit_0002">No</key>
<key name="unit_0003">None</key>
<key name="unit_0004">Unknown</key>
<key name="unit_0005"><![CDATA[<none>]]></key>
<key name="unit_0006">Balance Round-Robin</key> <!-- Bonding mode 0 (balance-rr) - See: /usr/share/doc/iputils/README.bonding -->
<key name="unit_0007">Active/Backup</key> <!-- Bonding mode 1 (active-backup) -->
<key name="unit_0008">Balanced Exclusive OR</key> <!-- Bonding mode 2 (balanced-xor) -->
<key name="unit_0009">Broadcast</key> <!-- Bonding mode 3 (broadcast) -->
<key name="unit_0010">Dynamic Link Aggregation (802.3ad)</key> <!-- Bonding mode 4 (802.3ad) -->
<key name="unit_0011">Balanced Transmit Load balancing</key> <!-- Bonding mode 5 (balanced-tlb) -->
<key name="unit_0012">Balanced Adaptive Load balancing</key> <!-- Bonding mode 6 (balanced-alb) -->
<!-- TODO: Merge these into 'unit' -->
<!-- These are works and strings used by javascript/jqery -->

@ -87,6 +87,12 @@ sub update_network
my $media = "unknown";
my $type = "interface";
# If the NIC is a bond member, the MAC address could be virtual.
if (-e $full_path."/bonding_slave/perm_hwaddr")
{
$mac_address = $anvil->Storage->read_file({file => $full_path."/bonding_slave/perm_hwaddr"});
}
# Clean up some newlines.
$mac_address =~ s/\n$//;
$link_state =~ s/\n$//;

Loading…
Cancel
Save