From ab1eb7d3f53addc1c504a6737a03750c961fe8e4 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 21 Sep 2012 18:23:21 -0700 Subject: [PATCH] support "mogadm device (list|summary) --hostname=..." 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. --- mogadm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mogadm b/mogadm index c1406db..169f9d3 100755 --- a/mogadm +++ b/mogadm @@ -84,6 +84,7 @@ my $usage = { args => "[opts]", opts => { "--all" => "Include dead devices in list.", + "--hostname=s" => "Limit results to a given host.", }, }, summary => { @@ -91,6 +92,7 @@ my $usage = { args => "[opts]", opts => { "--status=s" => "Devices of status A. Defaults to 'alive,readonly'", + "--hostname=s" => "Limit results to a given host.", }, }, add => { @@ -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)'; @@ -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")); @@ -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} || {}}) {