Skip to content

Commit

Permalink
support "mogadm device (list|summary) --hostname=..."
Browse files Browse the repository at this point in the history
For large clusters with many hosts/devices, it is often helpful
to only show the devices for a given host.

This functionality is useful for me since "mogadm device list"
output is not grep-friendly.
  • Loading branch information
Eric Wong committed Jan 9, 2013
1 parent b14bc2a commit ab1eb7d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions mogadm
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ my $usage = {
args => "[opts]",
opts => {
"--all" => "Include dead devices in list.",
"--hostname=s" => "Limit results to a given host.",
},
},
summary => {
des => "List the summary of devices, for each host.",
args => "[opts]",
opts => {
"--status=s" => "Devices of status A. Defaults to 'alive,readonly'",
"--hostname=s" => "Limit results to a given host.",
},
},
add => {
Expand Down Expand Up @@ -806,9 +808,13 @@ sub cmd_device_list {

my $devs = devices();
fail_text('no_devices') unless $devs;
my $hostname = $args->{hostname};

foreach my $hostid (sort keys %$hosts) {
my $host = $hosts->{$hostid};
if (defined $hostname && $hostname ne $host->{hostname}) {
next;
}
print "$host->{hostname} [$hostid]: $host->{status}\n";

printf "%6s %-10s %7s %7s %7s\n", '', '', 'used(G)', 'free(G)', 'total(G)';
Expand All @@ -830,6 +836,7 @@ sub cmd_device_list {

sub cmd_device_summary {
my $args = shift;
my $hostname = $args->{hostname};
my %show_state;
$show_state{$_} = 1 foreach split(/,/, ($args->{status} || "alive,readonly"));

Expand All @@ -842,6 +849,9 @@ sub cmd_device_summary {
printf "%-15s %6s %7s %8s %8s %8s %8s\n", 'Hostname', 'HostID', 'Status', 'used(G)', 'free(G)', 'total(G)', '%Used';
foreach my $hostid (sort keys %$hosts) {
my $host = $hosts->{$hostid};
if (defined $hostname && $hostname ne $host->{hostname}) {
next;
}
my ($total,$used) = (0, 0);

foreach my $devid (sort keys %{$devs->{$hostid} || {}}) {
Expand Down

0 comments on commit ab1eb7d

Please sign in to comment.