From 69b2e5e0c145d53ddf80cab335af945a1f52213a Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 5 Feb 2021 15:57:28 +0100 Subject: [PATCH] enhance vserver for netapp volumes --- .../netapp/ontap/restapi/mode/listvolumes.pm | 12 ++++++---- storage/netapp/ontap/restapi/mode/volumes.pm | 23 +++++++++++++++---- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/storage/netapp/ontap/restapi/mode/listvolumes.pm b/storage/netapp/ontap/restapi/mode/listvolumes.pm index 05e740e51..11aee8748 100644 --- a/storage/netapp/ontap/restapi/mode/listvolumes.pm +++ b/storage/netapp/ontap/restapi/mode/listvolumes.pm @@ -52,10 +52,12 @@ sub run { my $volumes = $self->manage_selection(%options); foreach (@{$volumes->{records}}) { + my $vserver_name = defined($_->{svm}) && $_->{svm}->{name} ne '' ? $_->{svm}->{name} : '-'; $self->{output}->output_add(long_msg => sprintf( - '[name = %s][state = %s]', + '[name = %s][state = %s][vserver = %s]', $_->{name}, - $_->{state} + $_->{state}, + $vserver_name )); } @@ -70,7 +72,7 @@ sub run { sub disco_format { my ($self, %options) = @_; - $self->{output}->add_disco_format(elements => ['name', 'state']); + $self->{output}->add_disco_format(elements => ['name', 'state', 'vserver_name']); } sub disco_show { @@ -78,9 +80,11 @@ sub disco_show { my $volumes = $self->manage_selection(%options); foreach (@{$volumes->{records}}) { + my $vserver_name = defined($_->{svm}) && $_->{svm}->{name} ne '' ? $_->{svm}->{name} : '-'; $self->{output}->add_disco_entry( name => $_->{name}, - state => $_->{state} + state => $_->{state}, + vserver_name => $_->{svm}->{name} ); } } diff --git a/storage/netapp/ontap/restapi/mode/volumes.pm b/storage/netapp/ontap/restapi/mode/volumes.pm index d35257e63..4823f6aed 100644 --- a/storage/netapp/ontap/restapi/mode/volumes.pm +++ b/storage/netapp/ontap/restapi/mode/volumes.pm @@ -153,7 +153,8 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'filter-name:s' => { name => 'filter_name' } + 'filter-name:s' => { name => 'filter_name' }, + 'filter-vserver-name:s' => { name => 'filter_vserver_name' } }); return $self; @@ -166,14 +167,22 @@ sub manage_selection { $self->{volumes} = {}; foreach (@{$volumes->{records}}) { + my $name = defined($_->{svm}) && $_->{svm}->{name} ne '' ? + $_->{svm}->{name} . ':' . $_->{name} : + $_->{name}; + if (defined($self->{option_results}->{filter_vserver_name}) && $self->{option_results}->{filter_vserver_name} ne '' && + defined($_->{svm}) && $_->{svm}->{name} ne '' && $_->{svm}->{name} !~ /$self->{option_results}->{filter_vserver_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $_->{svm}->{name} . "': no matching filter.", debug => 1); + next; + } if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $_->{name} !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "skipping volume '" . $_->{name} . "': no matching filter.", debug => 1); + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping volume '" . $name . "': no matching filter.", debug => 1); next; } - $self->{volumes}->{ $_->{name} } = { - display => $_->{name}, + $self->{volumes}->{$name} = { + display => $name, state => $_->{state}, total_space => $_->{space}->{size}, @@ -216,6 +225,10 @@ Example: --filter-counters='^usage$' Filter volume name (can be a regexp). +=item B<--filter-vserver-name> + +Filter volumes by vserver name (can be a regexp). + =item B<--unknown-status> Set unknown threshold for status.