# $Id$ # # Copyright (c) 2017 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary ComponentState Module for the method NACL::C::Application->show_detail() ## @author dl-nacl-dev@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::ApplicationShowDetail =head1 DESCRIPTION C is a derived class of L. Object(s) of this type are returned when NACL::C::Application->show_detail() is invoked. (This module does not represent the state of any element, but is an object repesentation of the output obtained when NACL::C::Application->show_detail() is invoked.) =head1 ATTRIBUTES The fields of the output are fields of the ComponentState object. =over =item C<< element_name >> Name of Object Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< application_component >> Application Component Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< igroup >> B. The field C should be used instead. Igroup Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< lun >> LUN Name Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< element_type >> Type of Object possible value(s) are, lun,lun-clone,nas,igroup Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< nfs_access_tos >> NFS Clients (Array) Note that for array fields, the accessor method can be invoked in either scalar or list context. my $nfs_access_tos = $obj->nfs_access_tos(); # $nfs_access_tos contains a reference to the array of values my @nfs_access_tos = $obj->nfs_access_tos(); # @nfs_access_tos contains the array of values If this field needs to be passed to the filter hash, the value for this field should be passed in as an arrayref # filter => { nfs_access_tos = [ value1, value2...] } Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< aux_lun_header >> Auxiliary LUN Header Flag Filled in for CMode CLI =item C<< nas_protocol_header >> Protocol Info Header Filled in for CMode CLI =item C<< cifs_permissions >> CIFS User Permissions (Array) Note that for array fields, the accessor method can be invoked in either scalar or list context. my $cifs_permissions = $obj->cifs_permissions(); # $cifs_permissions contains a reference to the array of values my @cifs_permissions = $obj->cifs_permissions(); # @cifs_permissions contains the array of values If this field needs to be passed to the filter hash, the value for this field should be passed in as an arrayref # filter => { cifs_permissions = [ value1, value2...] } Filled in for CMode CLI/ZAPI iter =item C<< generic_san_header >> Generic SAN Header Flag Filled in for CMode CLI =item C<< serial >> LUN Serial Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< nas_element_name >> Volume Filled in for CMode CLI =item C<< application_template >> Application Template Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< nas_header >> NAS Header Flag Filled in for CMode CLI =item C<< cifs_access_ips >> CIFS LIFs (Array) Note that for array fields, the accessor method can be invoked in either scalar or list context. my $cifs_access_ips = $obj->cifs_access_ips(); # $cifs_access_ips contains a reference to the array of values my @cifs_access_ips = $obj->cifs_access_ips(); # @cifs_access_ips contains the array of values If this field needs to be passed to the filter hash, the value for this field should be passed in as an arrayref # filter => { cifs_access_ips = [ value1, value2...] } Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< nas_element_size >> Volume Size Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< igroup_protocol >> Igroup Protocol Filled in for CMode CLI =item C<< cifs_server_fqdn >> CIFS Server Name Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< lun_id >> B. The field C should be used instead. LUN ID ranges from 0 to 4095 Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< nfs_permissions >> NFS Permissions (Array) Note that for array fields, the accessor method can be invoked in either scalar or list context. my $nfs_permissions = $obj->nfs_permissions(); # $nfs_permissions contains a reference to the array of values my @nfs_permissions = $obj->nfs_permissions(); # @nfs_permissions contains the array of values If this field needs to be passed to the filter hash, the value for this field should be passed in as an arrayref # filter => { nfs_permissions = [ value1, value2...] } Filled in for CMode CLI/ZAPI iter =item C<< cifs_access_levels >> CIFS Permissions Granted (Array) Note that for array fields, the accessor method can be invoked in either scalar or list context. my $cifs_access_levels = $obj->cifs_access_levels(); # $cifs_access_levels contains a reference to the array of values my @cifs_access_levels = $obj->cifs_access_levels(); # @cifs_access_levels contains the array of values If this field needs to be passed to the filter hash, the value for this field should be passed in as an arrayref # filter => { cifs_access_levels = [ value1, value2...] } Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< lun_path >> LUN Path Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< app_header >> Application Header Filled in for CMode CLI/ZAPI iter =item C<< size >> Element Size Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< application_component_storage_service >> Storage Service Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< nfs_access_ips >> NFS LIFs (Array) Note that for array fields, the accessor method can be invoked in either scalar or list context. my $nfs_access_ips = $obj->nfs_access_ips(); # $nfs_access_ips contains a reference to the array of values my @nfs_access_ips = $obj->nfs_access_ips(); # @nfs_access_ips contains the array of values If this field needs to be passed to the filter hash, the value for this field should be passed in as an arrayref # filter => { nfs_access_ips = [ value1, value2...] } Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< lun_ids >> LUN IDs (Array) Note that for array fields, the accessor method can be invoked in either scalar or list context. my $lun_ids = $obj->lun_ids(); # $lun_ids contains a reference to the array of values my @lun_ids = $obj->lun_ids(); # @lun_ids contains the array of values If this field needs to be passed to the filter hash, the value for this field should be passed in as an arrayref # filter => { lun_ids = [ value1, value2...] } Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< igroups >> IGROUPS (Array) Note that for array fields, the accessor method can be invoked in either scalar or list context. my $igroups = $obj->igroups(); # $igroups contains a reference to the array of values my @igroups = $obj->igroups(); # @igroups contains the array of values If this field needs to be passed to the filter hash, the value for this field should be passed in as an arrayref # filter => { igroups = [ value1, value2...] } Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< application_uuid >> Application UUID Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< nas_element_path >> Volume Path Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< application_template_protocol >> Application Template Protocol Filled in for CMode CLI/ZAPI iter =item C<< cifs_access_tos >> CIFS Users/Groups (Array) Note that for array fields, the accessor method can be invoked in either scalar or list context. my $cifs_access_tos = $obj->cifs_access_tos(); # $cifs_access_tos contains a reference to the array of values my @cifs_access_tos = $obj->cifs_access_tos(); # @cifs_access_tos contains the array of values If this field needs to be passed to the filter hash, the value for this field should be passed in as an arrayref # filter => { cifs_access_tos = [ value1, value2...] } Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< vserver >> Vserver Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< application >> Application Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< nfs_export_policy_name >> Export Policy Name Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< initiator >> Initiators (Array) Note that for array fields, the accessor method can be invoked in either scalar or list context. my $initiator = $obj->initiator(); # $initiator contains a reference to the array of values my @initiator = $obj->initiator(); # @initiator contains the array of values If this field needs to be passed to the filter hash, the value for this field should be passed in as an arrayref # filter => { initiator = [ value1, value2...] } Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< application_template_version >> Application Template Version Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< application_component_uuid >> Application Component UUID Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< nfs_access_levels >> Permission Granted to Clients (Array) Note that for array fields, the accessor method can be invoked in either scalar or list context. my $nfs_access_levels = $obj->nfs_access_levels(); # $nfs_access_levels contains a reference to the array of values my @nfs_access_levels = $obj->nfs_access_levels(); # @nfs_access_levels contains the array of values If this field needs to be passed to the filter hash, the value for this field should be passed in as an arrayref # filter => { nfs_access_levels = [ value1, value2...] } Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< cifs_share_name >> CIFS Share Name Filled in for CMode CLI/ZAPI iter Mapping for CMode ZAPI iter: =item C<< san_protocol_header >> Protocol Info Header Filled in for CMode CLI/ZAPI iter =back =cut package NACL::CS::ApplicationShowDetail; use strict; use warnings; use Params::Validate qw(validate); use NATE::Log qw(log_global); use NACL::Exceptions::NoElementsFound qw(:try); use NACL::CS::ComponentState::ZapiSkip qw(make_zapi_skip); use NACL::CS::ComponentState::ZapiArray qw(make_zapi_array); use base 'NACL::CS::ComponentState::ONTAP'; use Class::MethodMaker [ scalar => 'element_name', scalar => 'application_component', scalar => 'igroup', array => 'igroups', scalar => 'lun', scalar => 'element_type', array => 'nfs_access_tos', scalar => 'aux_lun_header', scalar => 'nas_protocol_header', array => 'cifs_permissions', scalar => 'generic_san_header', scalar => 'serial', scalar => 'nas_element_name', scalar => 'application_template', scalar => 'nas_header', array => 'cifs_access_ips', scalar => 'nas_element_size', scalar => 'igroup_protocol', scalar => 'cifs_server_fqdn', scalar => 'lun_id', array => 'lun_ids', array => 'nfs_permissions', array => 'cifs_access_levels', scalar => 'lun_path', scalar => 'app_header', scalar => 'size', scalar => 'application_component_storage_service', array => 'nfs_access_ips', scalar => 'application_uuid', scalar => 'nas_element_path', scalar => 'application_template_protocol', array => 'cifs_access_tos', scalar => 'vserver', scalar => 'application', scalar => 'nfs_export_policy_name', array => 'initiator', scalar => 'application_template_version', scalar => 'application_component_uuid', array => 'nfs_access_levels', scalar => 'cifs_share_name', scalar => 'san_protocol_header', ]; my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); sub _extra_filter_fields { $Log->enter() if $may_enter; $Log->exit() if $may_exit; return [qw( protocol config )]; } sub _check_fetch_cmode_zapi_iter { $Log->enter() if $may_enter; my ($pkg, %opts) = @_; my @invalid_fields = $pkg->_invalid_fields_check( filter => $opts{filter}, requested_fields => $opts{requested_fields}, _fields => [ qw(aux-lun-header nas-protocol-header cifs-permissions generic-san-header nas-element-name nas-header igroup-protocol nfs-permissions app-header application-template-protocol san-protocol-header) ] ); if (@invalid_fields) { my $msg = 'The following fields provided ' . 'in the call to ' . $pkg . ' are not supported by the ' . 'iter ZAPI, so the ZAPI back-end is being ' . "skipped:" . join(', ', @invalid_fields); $Log->comment($msg); $Log->exit() if $may_exit; NACL::Exceptions::InvalidChoice->throw($msg); } $Log->exit() if $may_exit; } =head1 METHODS =head2 fetch my $ApplicationShowDetail_state = NACL::CS::ApplicationShowDetail->fetch(command_interface => $ci, ...); my @ApplicationShowDetail_states = NACL::CS::ApplicationShowDetail->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. Uses CMode CLI/ZAPI. Invokes application-details-get-iter API for CMode ZAPI iter. =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, @args) = @_; my @state_objs = $pkg->SUPER::fetch( @args, show_cmd => 'application show-detail', choices => [ { method => '_fetch_cmode_cli', interface => 'CLI', set => 'CMode', zapi_type => 'none', }, { method => '_fetch_cmode_zapi', interface => 'ZAPI', set => 'CMode', zapi_type => 'iter', check => '_check_fetch_cmode_zapi_iter', }, ], exception_text => 'No matching ApplicationShowDetail(s) found', frontend => 'NACL::CS::ApplicationShowDetail::fetch', ); $Log->exit() if $may_exit; return wantarray ? @state_objs : $state_objs[0]; } sub _update_state_objs_cmode_zapi { $Log->enter() if $may_enter; my ($pkg, @args) = @_; $pkg->SUPER::_update_state_objs_cmode_zapi(@args, zapi_field_translations => {hyphenate_value => [qw(element-type)],},); $Log->exit() if $may_exit; } sub _fetch_cmode_cli { $Log->enter() if $may_enter; my ($pkg, @args) = @_; my @state_objs = $pkg->SUPER::_fetch_cmode_cli(@args, api => 'application_show_detail',); $Log->exit() if $may_exit; return @state_objs; } sub _fetch_cmode_zapi { $Log->enter() if $may_enter; my ($pkg, %opts) = @_; my $requested_fields = $opts{requested_fields}; my $filter = $opts{filter}; my @state_objs = $pkg->SUPER::_fetch_cmode_zapi( %opts, api => "application-details-get-iter", inapplicable_for_help_xml => [qw(initiator cifs-access-ips nfs-access-ips)], suppress_type_warning => 1, copy => [ qw(application-template application-uuid vserver application application-template-version ) ], map => { 'element-name' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('element-detail-info'), make_zapi_skip('application-element-detail-info'), make_zapi_array('element-name') ], 'application-component' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('component'), ], 'igroup' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('element-detail-info'), make_zapi_skip('application-element-detail-info'), make_zapi_array('igroup') ], 'lun' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('element-detail-info'), make_zapi_skip('application-element-detail-info'), make_zapi_array('lun'), ], 'element-type' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('element-type'), ], 'nfs-access-tos' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('element-detail-info'), make_zapi_skip('application-element-detail-info'), make_zapi_array('nfs-permissions'), make_zapi_array('nfs-access-to'), ], 'serial' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('element-detail-info'), make_zapi_skip('application-element-detail-info'), make_zapi_array('serial') ], 'nas-element-size' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('element-detail-info'), make_zapi_skip('application-element-detail-info'), make_zapi_array('nas-element-size'), ], 'cifs-server-fqdn' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('element-detail-info'), make_zapi_skip('application-element-detail-info'), make_zapi_array('cifs-server-fqdn') ], 'lun-id' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('element-detail-info'), make_zapi_skip('application-element-detail-info'), make_zapi_array('lun-id'), ], 'cifs-access-levels' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('element-detail-info'), make_zapi_skip('application-element-detail-info'), make_zapi_array('cifs-permissions'), make_zapi_array('cifs-access-level'), ], 'lun-path' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('element-detail-info'), make_zapi_skip('application-element-detail-info'), make_zapi_array('lun-path') ], 'size' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('element-detail-info'), make_zapi_skip('application-element-detail-info'), make_zapi_array('size') ], 'application-component-storage-service' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('component-storage-service'), ], 'nas-element-path' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('element-detail-info'), make_zapi_skip('application-element-detail-info'), make_zapi_array('nas-element-path') ], 'cifs-access-tos' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('element-detail-info'), make_zapi_skip('application-element-detail-info'), make_zapi_array('cifs-permissions'), make_zapi_array('cifs-access-to'), ], 'nfs-export-policy-name' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('element-detail-info'), make_zapi_skip('application-element-detail-info'), make_zapi_array('nfs-export-policy-name') ], 'application-component-uuid' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('component-uuid'), ], 'nfs-access-levels' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('element-detail-info'), make_zapi_skip('application-element-detail-info'), make_zapi_array('nfs-permissions'), make_zapi_array('nfs-access-level'), ], 'cifs-share-name' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('element-detail-info'), make_zapi_skip('application-element-detail-info'), make_zapi_array('cifs-share-name') ], 'igroups' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('element-detail-info'), make_zapi_skip('application-element-detail-info'), make_zapi_array('lun-mapping-entry'), make_zapi_array('igroup'), ], 'lun-ids' => [ make_zapi_array('application-components'), make_zapi_skip('application-component-info'), make_zapi_array('element-detail-info'), make_zapi_skip('application-element-detail-info'), make_zapi_array('lun-mapping-entry'), make_zapi_array('lun-id'), ], }, # Handle input mapping fix_api_opts => sub { my %fix_api_args = @_; my $api_opts = $fix_api_args{api_opts}; my %req_field_hash = map {$_ => 1} @$requested_fields; if (exists $req_field_hash{'initiator'}) { $api_opts->{'desired-attributes'}{'application-components'} [0]{'element-detail-info'}[0]->{initiator} = ['']; } if (exists $req_field_hash{'cifs-access-ips'}) { $api_opts->{'desired-attributes'}{'application-components'} [0]{'element-detail-info'}[0]->{'cifs-access-ips'} = ['']; } if (exists $req_field_hash{'nfs-access-ips'}) { $api_opts->{'desired-attributes'}{'application-components'} [0]{'element-detail-info'}[0]->{'nfs-access-ips'} = ['']; } if (exists $filter->{initiator}) { $api_opts->{'query'}{'application-components'} [0]{'element-detail-info'}[0]->{initiator} = $filter->{initiator}; } if (exists $filter->{'cifs-access-ips'}) { $api_opts->{'query'}{'application-components'} [0]{'element-detail-info'}[0]->{'cifs-access-ips'} = $filter->{'cifs-access-ips'}; } if (exists $filter->{'nfs-access-ips'}) { $api_opts->{'query'}{'application-components'} [0]{'element-detail-info'}[0]->{'nfs-access-ips'} = $filter->{'nfs-access-ips'}; } }, # Handle output mapping fix_response => sub { my %opts = @_; my $zapi = $opts{zapi}; my $cli = $opts{cli}; my @all_initiator; my $application_comp = $zapi->{'application-components'}[0]->{'application-component-info'}; foreach my $application (@$application_comp){ my $element_info = $application->{'element-detail-info'}[0]->{'application-element-detail-info'}; foreach my $element (@$element_info ) { if (exists $element->{initiator} ) { my $initiator = $element->{initiator}[0]->{string}; $cli->{initiator} = $initiator; } if (exists $element->{'cifs-access-ips'}) { my $cifs_access = $element->{'cifs-access-ips'}[0]->{'ip-address'}; $cli->{'cifs-access-ips'} = $cifs_access; } if (exists $element->{'nfs-access-ips'}) { my $nfs_access = $element->{'nfs-access-ips'}[0]->{'ip-address'}; $cli->{'nfs-access-ips'} = $nfs_access; } } } }, fix_records => sub { my %opts = @_; my $records = $opts{records}; my @new_records; foreach my $record (@$records) { my $application_component = delete($record->{'application-components'}); my %record_deep_copy = %$record; foreach my $application_comp (@$application_component) { my $application_comp_info = ($application_comp->{'application-component-info'}); foreach my $application_comp(@$application_comp_info) { my $element_info = ($application_comp->{'element-detail-info'}); my $component_name = $application_comp->{'component-name'}; foreach my $ele_info (@$element_info) { my $application_element_info = ($ele_info->{'application-element-detail-info'}); foreach my $val (@$application_element_info) { my %new_record = %record_deep_copy; my %app_comp = %$application_comp; my %element_in = %$ele_info; $new_record{'application-components'}[0]{'application-component-info'} = [\%app_comp] ; $new_record{'application-components'}[0]{'application-component-info'}[0]{'element-detail-info'} = [\%element_in]; $new_record{'application-components'}[0]{'application-component-info'}[0]{'element-detail-info'}[0]{'application-element-detail-info'} = [$val]; push @new_records, \%new_record; } } } } } return \@new_records; }, ); #single object is returned, normalize it similar to CLI returned object foreach my $obj(@state_objs) { my @array = keys %{$obj}; @array = grep { $_ !~ /initiator/ } @array; @array = grep { $_ !~ /cifs_access_ips|cifs_access_levels|cifs_access_tos/ } @array; @array = grep { $_ !~ /nfs_access_ips|nfs_access_tos|nfs_access_levels/ } @array; @array = grep { $_ !~ /application_uuid/ } @array; foreach my $field(@array) { if( ref($obj->{$field}) eq 'ARRAY'){ if(defined($obj->{$field}->[0])){ my $tmp = $obj->{$field}; $obj->{$field} = join(',',@{$tmp}); } else { $obj->{$field} = "-"; } } } } $Log->exit() if $may_exit; return @state_objs; } 1;