# # Copyright (c) 2001-2017 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary VolumeQtree ComponentState Module ## @author Dheeraj.K@netapp.com, pragyan@netapp.com, dl-nacl-dev@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::VolumeQtree =head1 DESCRIPTION C is a derived class of L. It represents the state of VolumeQtree in an ONTAP VolumeQtree. A related class is L, which represents access to an ONTAP VolumeQtree. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the VolumeQtree element are the attributes of the VolumeQtree ComponentState. =over =item C<< vserver >> Filled in for CMode CLI/ZAPI/SNMP. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< volume >> Filled in for CMode CLI/ZAPI/SNMP, 7Mode CLI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value 7Mode CLI: For "filter": Applicable, Filtering will be done by Components. For "requested_fields", Not applicable, but the field will be populated in the CS object. =item C<< qtree >> Filled in for CMode CLI/ZAPI/SNMP, 7Mode CLI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value 7Mode CLI: For "filter": Applicable, Filtering will be done by Components. For "requested_fields", Not applicable, but the field will be populated in the CS object. =item C<< security_style >> Filled in for CMode CLI/ZAPI/SNMP, 7Mode CLI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value 7Mode CLI: For "filter": Applicable, Filtering will be done by Components. For "requested_fields", Not applicable, but the field will be populated in the CS object. =item C<< oplock_mode >> Filled in for CMode CLI/ZAPI/SNMP, 7Mode CLI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value 7Mode CLI: For "filter": Applicable, Filtering will be done by Components. For "requested_fields", Not applicable, but the field will be populated in the CS object. =item C<< unix_permissions >> Filled in for CMode CLI/ZAPI/SNMP. =item C<< qtree_id >> Filled in for CMode CLI/ZAPI/SNMP, 7Mode CLI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value 7Mode CLI: For "filter": Applicable, Filtering will be done by Components. For "requested_fields", Not applicable, but the field will be populated in the CS object. =item C<< status >> Filled in for CMode CLI/ZAPI/SNMP, 7Mode CLI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value 7Mode CLI: For "filter": Applicable, Filtering will be done by Components. For "requested_fields", Not applicable, but the field will be populated in the CS object. =item C<< owning_vfiler >> Filled in for CMode CLI, 7Mode CLI. Maps to: 7Mode CLI: For "filter": Applicable, Filtering will be done by Components. For "requested_fields", Not applicable, but the field will be populated in the CS object. =item C<< nfs_ops >> Filled in for CMode CLI. =item C<< cifs_ops >> Filled in for CMode CLI. =item C<< no_reset_internal_ops >> Filled in for CMode CLI. =item C<< qtree_path >> Filled in for CMode CLI/ZAPI/SNMP, 7Mode CLI. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value 7Mode CLI: For "filter": Applicable, Filtering will be done by Components. For "requested_fields", Not applicable, but the field will be populated in the CS object. =item C<< no_reset_cifs_ops >> Filled in for CMode CLI. =item C<< no_reset_nfs_ops >> Filled in for CMode CLI. =item C<< rootfileid >> Filled in for CMode CLI. =item C<< rootgeneration >> Filled in for CMode CLI. =item C<< internal_ops >> Filled in for CMode CLI. =item C<< oplock_mode_zapi >> Filled in for CMode CLI. =item C<< is_root_volume >> Containing Volume is Vserver Root? possible value(s) are, true,false Filled in for CMode CLI. =item C<< export_policy >> Export Policy Filled in for CMode CLI/ZAPI/SNMP. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< export_policy_id >> Export Policy ID Filled in for CMode CLI. =item C<< is_export_policy_inherited >> Is Export Policy Inherited possible value(s) are, true,false Filled in for CMode CLI/ZAPI/SNMP. Maps to: CMode ZAPI: For "requested_fields", "filter" and Output mapping: $value =back =cut package NACL::CS::VolumeQtree; use strict; use warnings; use Params::Validate qw(validate SCALAR); use NATE::Log qw(log_global); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); use NACL::ComponentUtils qw(_dump_one Dumper); use NACL::APISet::Exceptions::InvalidParamValueException qw(:try); use NACL::C::_Mixins::VolumeQtree qw(:all); use NACL::Util::QuotaLibSingleton; use base 'NACL::CS::ComponentState::ONTAP'; use Class::MethodMaker [ scalar => 'vserver', scalar => 'volume', scalar => 'qtree', scalar => 'security_style', scalar => 'oplock_mode', scalar => 'unix_permissions', scalar => 'qtree_id', scalar => 'status', # specific to 7Mode scalar => 'owning_vfiler', scalar => 'nfs_ops', scalar => 'cifs_ops', scalar => 'no_reset_internal_ops', scalar => [ { -default_ctor => sub { if (ref $_[0]) { _construct_qtree_path_from_vol_qtree( volume => $_[0]->volume(), qtree => $_[0]->qtree() ); } } }, 'qtree_path' ], scalar => 'no_reset_cifs_ops', scalar => 'no_reset_nfs_ops', scalar => 'rootfileid', scalar => 'rootgeneration', scalar => 'internal_ops', scalar => 'oplock_mode_zapi', scalar => 'is_root_volume', scalar => 'export_policy', scalar => 'export_policy_id', scalar => 'is_export_policy_inherited', ]; sub isa { $Log->enter() if $may_enter; my ($pkg_or_obj, $kind) = @_; my $isa = $pkg_or_obj->_build_isa( kind => $kind, alias => 'NACL::CS::Qtree' ); $Log->exit() if $may_exit; return $isa; } =head1 METHODS =head2 fetch my $VolumeQtree_state = NACL::CS::VolumeQtree->fetch(command_interface => $ci, ...); my @VolumeQtree_states = NACL::CS::VolumeQtree->fetch(command_interface => $ci, ...); (Class method) Discovers which elements are present and returns their state in ComponentState objects. Called in scalar context it returns only one state object, in list context it returns all state objects. See L for a more detailed description along with a complete explanation of the options it accepts. Supports CMode CLI/ZAPI/SNMP, 7Mode CLI. Invokes "qtree-list-iter" API for CMode ZAPI. Walks "qtreeTable" for CMode SNMP. Invokes "qtree status" command for 7Mode CLI. =over =item Exceptions =over =item C When there are no elements matching the query specified or elements of that type doesn't exist, then this exception will be thrown. =back =back =cut sub fetch { $Log->enter() if $may_enter; my ($pkg, %opts) = @_; my $quota_singleton = NACL::Util::QuotaLibSingleton->get(); $opts{apiset_must} = $quota_singleton->apiset_must(%opts); $opts{apiset_should} = $quota_singleton->apiset_should(%opts); my @state_objs = $pkg->SUPER::fetch( %opts, choices => [ { method => '_fetch_cmode_cli', interface => 'CLI', set => 'CMode', }, { method => '_fetch_7mode_cli', interface => 'CLI', set => '7Mode', }, { method => '_fetch_cmode_zapi', interface => 'ZAPI', set => 'CMode', }, { method => '_fetch_cmode_snmp', interface => 'SNMP', set => 'CMode', }, ], show_cmd => 'volume qtree show', exception_text => 'No matching volume qtree(s) found' ); $Log->exit() if $may_exit; return wantarray ? @state_objs : $state_objs[0]; } ## end sub fetch sub _fetch_cmode_cli { $Log->enter() if $may_enter; my $pkg = shift; my %opts = validate @_, $pkg->_fetch_backend_validate_spec(); my @state_objs; @state_objs = $pkg->SUPER::_fetch_cmode_cli(%opts, api => 'volume_qtree_show'); $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_cmode_cli sub _fetch_7mode_cli { $Log->enter() if $may_enter; my $pkg = shift; my %opts = validate @_, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my ($response, $caught_exception); try { $response = $apiset->qtree_status( 'id' => 1, # -i option 'owning-vfiler' => 1, # -v option 'connectrec-timeout' => 1200, ); } ## end try catch NACL::APISet::Exceptions::InvalidParamValueException with { # A caught exception indicates that the qtree being looked for # does not exist. We catch the exception and return immediately. The # 'fetch' frontend decides whether to throw a NoElementsFound # exception based on the value of 'allow_empty' $caught_exception = 1; }; if ($caught_exception) { $Log->exit() if $may_exit; return; } my $output = $response->get_parsed_output(); my @state_objs; foreach my $row (@$output) { my $final_attributes = $pkg->_hash_copy( source => $row, copy => [qw( volume status owning_vfiler )], map => { 'id' => 'qtree_id', 'tree' => 'qtree', 'oplocks' => 'oplock_mode', 'style' => 'security_style', }, ); my $obj = $pkg->new(command_interface => $opts{command_interface}); $obj->_set_fields(row => $final_attributes); push @state_objs, $obj; } ## end foreach my $row (@$output) $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_7mode_cli sub _fetch_cmode_zapi { $Log->enter() if $may_enter; my ($pkg, %opts) = @_; my $requested_fields = []; if (defined($opts{requested_fields})) { my %requested_fields_hash = map { $_ => 1 } @{$opts{requested_fields}}; if (exists($requested_fields_hash{'qtree-path'})) { $requested_fields_hash{volume} = 1; $requested_fields_hash{qtree} = 1; } $requested_fields = [keys(%requested_fields_hash)]; } delete $opts{requested_fields}; my $filter = {%{$opts{filter}}}; NACL::C::_Mixins::VolumeQtree->_convert_path_to_volume_qtree( command_interface => $opts{command_interface}, args_ptr => $opts{filter} ); my @states = $pkg->SUPER::_fetch_cmode_zapi( %opts, api => 'qtree_list_iter', requested_fields => $requested_fields, copy => [ qw(vserver volume qtree security-style status is-export-policy-inherited export-policy) ], map => { 'oplock-mode' => 'oplocks', 'qtree-id' => 'id', 'unix-permissions' => 'mode', }, ); $Log->exit() if $may_exit; return @states; } ## end sub _fetch_cmode_zapi sub _fetch_cmode_snmp { $Log->enter() if $may_enter; my ($pkg, %opts) = @_; my $requested_fields = []; if (defined($opts{requested_fields})) { my %requested_fields_hash = map { $_ => 1 } @{$opts{requested_fields}}; if (exists($requested_fields_hash{'qtree-path'})) { $requested_fields_hash{volume} = 1; $requested_fields_hash{qtree} = 1; } $requested_fields = [keys(%requested_fields_hash)]; } delete $opts{requested_fields}; my $orig_filter = delete $opts{filter}; my $filter = defined($orig_filter) ? {%$orig_filter} : {}; NACL::C::_Mixins::VolumeQtree->_convert_path_to_volume_qtree( command_interface => $opts{command_interface}, args_ptr => $filter, ); if (defined($filter->{qtree}) && ($filter->{qtree} =~ /""/)) { if ($filter->{qtree} eq '""') { $filter->{qtree} = "."; } elsif ($pkg->_check_relational_regex_filter( filter_value => $filter->{qtree})) { # Don't even try translating the root qtree if it's in a regex delete $filter->{qtree}; } } # Even though other fields with inconsistencies between CLI and SNMP # have relatively simple transformations, there's not too much value # in having SUPER::_fetch_snmp() do the filtering for non-key fields. # So clear them out, and apply the original filter after translating # the fetched state objects. foreach my $field (qw(oplock-mode is-export-policy-inherited)) { delete $filter->{$field}; } my $apiset = $opts{apiset}; my %orig_session_attributes = %{$apiset->get_session_attributes()}; $apiset->set_session_attributes(retries => 3, timeout => 10); my @states; try { @states = $pkg->SUPER::_fetch_snmp( %opts, baseoid => 'netapp1_filesys_qtreeTable', requested_fields => $requested_fields, filter => $filter, map => { vserver => 'qtreeVserver', volume => 'qtreeVolumeName', qtree => 'qtreeName', 'security-style' => 'qtreeStyle', 'oplock-mode' => 'qtreeOplock', 'unix-permissions' => 'qtreeMode', 'qtree-id' => 'qtreeId', status => 'qtreeStatus', 'export-policy' => 'qtreeExportPolicy', 'is-export-policy-inherited' => 'qtreeIsExportPolicyInherited', }, ); } catch NACL::APISet::Exceptions::NoMatchingEntriesException with { $Log->debug("Caught NoMatchingEntriesException, returning empty " . "state object list to the frontend"); } finally { $apiset->set_session_attributes(%orig_session_attributes); }; # We need the same perm-stringification fixup as ZAPI $pkg->_update_state_objs_cmode_zapi( state_objs => \@states, command_interface => $opts{command_interface}, ); foreach my $state (@states) { if ($state->qtree_isset() && ($state->qtree() eq '.')) { # Convert root qtree from '.' to '""', for CLI compatibility $state->qtree('""'); } if ($state->oplock_mode_isset()) { # Convert enabled/disabled => enable/disable, for CLI compatibility my $mode = $state->oplock_mode(); $mode =~ s/^(enable|disable)d$/$1/; $state->oplock_mode($mode); } if ($state->is_export_policy_inherited_isset()) { # Convert numeric 0/1 to string true/false, for CLI compatibility my $old_val = $state->is_export_policy_inherited(); my $new_val; if ($old_val eq '0') { $new_val = 'false'; } elsif ($old_val eq '1') { $new_val = 'true'; } if (defined($new_val)) { $state->is_export_policy_inherited($new_val); } } } local $Data::Dumper::Maxdepth = 2; $Log->debug("Before _apply_filter: " . Dumper(\@states)); $pkg->SUPER::_apply_filter( state_objs => \@states, filter => $orig_filter, return_on_mismatch => 1, ); $Log->exit() if $may_exit; return @states; } ## end sub _fetch_cmode_snmp sub _update_state_objs_cmode_zapi { $Log->enter() if $may_enter; my ($pkg, %opts) = @_; $pkg->SUPER::_update_state_objs_cmode_zapi( %opts, zapi_field_translations => { unix_perm_to_str => [qw(unix-permissions)], }, hash_map_translations => { oplock_mode => { fields_to_translate => [qw(oplock-mode)], hash_map => { 'enabled' => 'enable', 'disabled' => 'disable', }, }, }, ); $Log->exit() if $may_exit; } sub _construct_qtree_path_from_vol_qtree { my %opts = validate( @_, { volume => {type => SCALAR}, qtree => {type => SCALAR} } ); my $qtree_path = "/vol/$opts{volume}"; if ($opts{qtree} ne '""') { $qtree_path .= "/$opts{qtree}"; } return $qtree_path; } 1;