#$Id: //depot/prod/test/nacldev/lib/NACL/CS/Switch/Zone.pm#1 $ # # Copyright (c) 2012 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # # ## @summary Zone ComponentState Module ## @author skotagir@netapp.com, dl-nacl-dev@netapp.com ## @status shared ## @pod here ################################################################################ =head1 NAME NACL::CS::Switch::Zone =head1 DESCRIPTION C is a derived class of L. It represents the state of Zone element. A related class is L, which represents access to a Zone element. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the Zone element are the individual attributes of the Zone ComponentState =over =item C<< 'zone-name'=>$string >> (Represents name of the zone) #Filled in for CiscoFC and BrocadeFC =item C<< vsan_id =>$string >> (Represents name of the vsan in which zone is present) #Filled in for CiscoFC =back =cut ################### # Package package NACL::CS::Switch::Zone; ################### # Everytime use strict; use warnings; ################### # Module includes use Params::Validate qw (validate); 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 (_optional_scalars _dump_one); use NATE::BaseException; use NACL::Exceptions::NoElementsFound qw(:try); use NACL::APISet::Exceptions::InvalidParamValueException qw(:try); use base 'NACL::CS::ComponentState::Switch'; use Class::MethodMaker [ new => [ '-hash', 'new' ], scalar => "zone_name", scalar => "vsan_id", array => "members", ]; =head1 METHODS =head2 fetch my $zone = NACL::CS::Switch::Zone->fetch(command_interface=>$ci,...); my @zone = NACL::CS::Switch::Zone->fetch(command_interface=>$ci,...); see L =cut sub fetch { $Log->enter() if $may_enter; my( $pkg, %opts ) = @_; my @state_objs = $pkg->SUPER::fetch( %opts, choices => [ { method => "_fetch_brocadefc_cli", interface => "CLI", set => "BrocadeFC" }, { method => "_fetch_ciscofc_cli", interface => "CLI", set => "CiscoFC" }, ], exception_text => 'No matching elements found' ); $Log->enter() if $may_enter; return wantarray ? @state_objs : $state_objs[0]; } sub _fetch_brocadefc_cli { $Log->enter() if $may_enter; my ($pkg , @args) = @_; my %opts = validate @args, $pkg->_fetch_backend_validate_spec(); my %api_opts; my @state_objs; my $apiset = delete $opts{apiset}; my $command_interface = delete $opts{command_interface}; my %copy_filter = %{ $opts{filter} }; my @copy_requested_fields = @{ $opts{requested_fields} }; my $deleted_filter = $pkg->_remove_relational_regex_filters( filter => \%copy_filter, requested_fields => \@copy_requested_fields ); my $filter = \%copy_filter; my $requested_fields = \@copy_requested_fields; $api_opts{'pattern'} = '*'; if ( defined( $filter->{'zone-name'} ) ) { $api_opts{'pattern'} = $filter->{'zone-name'}; } my $response = $apiset->zoneshow( %api_opts ); my $output = $response->get_parsed_output(); my $zones = @$output[0]->{zones}; foreach my $list_output ( @{$zones} ) { my $target = $pkg->_hash_copy( source => $list_output, copy => [qw(members)], map => { 'name'=>'zone-name', }, ); my $obj = $pkg->new( command_interface => $command_interface, ); $obj->_set_fields( row => $target ); push @state_objs, $obj; } ## end foreach my $list_output (@$output) $Log->exit() if $may_exit; return @state_objs; } #end sub _fetch_brocadefc_cli sub _fetch_ciscofc_cli { $Log->enter() if $may_enter; my ($pkg , @args) = @_; my %opts = validate @args, $pkg->_fetch_backend_validate_spec(); my %api_args; my %api_opts; my @state_objs; my $apiset = delete $opts{apiset}; my $command_interface = delete $opts{command_interface}; my %copy_filter = %{ $opts{filter} }; my @copy_requested_fields = @{ $opts{requested_fields} }; my $deleted_filter = $pkg->_remove_relational_regex_filters( filter => \%copy_filter, requested_fields => \@copy_requested_fields ); my $filter = \%copy_filter; my $requested_fields = \@copy_requested_fields; if ( exists $filter->{'zone-name'} ) { $api_args{'name'} = $filter->{'zone-name'}; } if ( exists $filter->{'vsan-id'} ) { $api_args{'vsan-id'} = $filter->{'vsan-id'}; } my $response = $apiset->show_zone(%api_args ); my $zones = $response->get_parsed_output(); foreach my $list_output ( @{$zones} ) { my $target = $pkg->_hash_copy( source => $list_output, copy => [qw( members )], map => { 'zone_name' => 'zone-name', 'vsan' => 'vsan-id' }, ); my $obj = $pkg->new( command_interface => $command_interface, ); $obj->_set_fields( row => $target ); push @state_objs, $obj; } ## end foreach my $list_output (@$output) $Log->exit() if $may_exit; return @state_objs; } #end sub _fetch_brocadefc_cli 1;