#$Id: //depot/prod/test/nacldev/lib/NACL/CS/Switch/Vsan.pm#1 $ # # Copyright (c) 2001-2012 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary Vsan ComponentState Module ## @author veerap@netapp.com, dl-nacl-dev@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::Switch::Vsan =head1 DESCRIPTION C is a derived class of L. It represents the state of Vsan element. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the Vsan element are the individual attributes of the Vsan ComponentState =over =item C<< state >> Filled in for CiscoFC Switch. =item C<< name >> Filled in for CiscoFC Switch. =item C<< loadbalancing >> Filled in for CiscoFC Switch. =item C<< interoperability_mode >> Filled in for CiscoFC Switch. =item C<< operational_state >> Filled in for CiscoFC Switch. =item C<< type >> Filled in for CiscoFC Switch. =item C<< interfaces >> Filled in for CiscoFC Switch. (array) Interfaces Possible Values: fc1/1, fc1/2, fc1/3, fc1/4, ... =item C<< vsan_id >> Filled in for CiscoFC/BrocadeFC Switch. Maps to : BrocadeFC : fid =item C<< attributes >> Filled in for BrocadeFC Switch. =item C<< switchtype >> Filled in for BrocadeFC Switch. =item C<< switchdomain >> Filled in for BrocadeFC Switch. =item C<< switchid >> Filled in for BrocadeFC Switch. =item C<< switchstate >> Filled in for BrocadeFC Switch. =item C<< switchmode >> Filled in for BrocadeFC Switch. =item C<< switchwwn >> Filled in for BrocadeFC Switch. =item C<< switchname >> Filled in for BrocadeFC Switch. =item C<< zoning >> Filled in for BrocadeFC Switch. =item C<< router >> Filled in for BrocadeFC Switch. =item C<< switchrole >> Filled in for BrocadeFC Switch. =item C<< switchbeacon >> Filled in for BrocadeFC Switch. =item C<< ports_information >> Filled in for BrocadeFC Switch. (array) Ports Information Possible Values: index, media, speed, porttype, address,... =item C<< port >> Filled in for BrocadeFC Switch. (array) Port numbers Possible Values: 1, 2, 3, 4, ... =item C<< created_switches >> Filled in for BrocadeFC Switch. (array) Created Switches Possible Values: 128, 127, 126, ... =back =cut package NACL::CS::Switch::Vsan; use strict; use warnings; use Params::Validate qw(validate); use NACL::Exceptions::NoElementsFound qw(:try); use base 'NACL::CS::ComponentState::Switch'; use Class::MethodMaker [ new => [ '-hash', 'new' ], scalar => 'state', scalar => 'vsan_id', scalar => 'attributes', array => 'interfaces', scalar => 'name', scalar => 'loadbalancing', scalar => 'interoperability_mode', scalar => 'operational_state', scalar => 'type', scalar => 'switchtype', scalar => 'switchdomain', scalar => 'switchid', scalar => 'switchstate', scalar => 'switchmode', scalar => 'switchwwn', scalar => 'switchname', scalar => 'zoning', scalar => 'router', scalar => 'switchrole', scalar => 'switchbeacon', array => 'ports_information', array => 'port', array => 'created_switches', ]; =head1 METHODS =head2 fetch my $state_obj = NACL::CS::Vsan->fetch(command_interface => $ci, ...); my @state_obj = NACL::CS::Vsan->fetch(command_interface => $ci, ...); see L =cut sub fetch { my $pkg = shift; my @state_objs = $pkg->SUPER::fetch( @_, choices => [ { method => "_fetch_ciscofc_cli", interface => "CLI", set => "CiscoFC" }, { method => "_fetch_brocadefc_cli", interface => "CLI", set => "BrocadeFC" }, ], exception_text => 'No matching elements found' ); return wantarray ? @state_objs : $state_objs[0]; } sub _fetch_ciscofc_cli { my $pkg = shift; my %opts = validate @_, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my @state_objs; my %cmd_opts; my ( $output, $response ); 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; my $req_field_filter; $req_field_filter->{'requested_fields'} = $requested_fields; $req_field_filter->{'filter'} = \%copy_filter; #vsan show command if ( $pkg->_want_any_field_of( %{$req_field_filter}, fields_filled_by_api => [ qw( state vsan_id name loadbalancing interoperability_mode operational_state type ) ] ) ) { $response = $apiset->show_vsan(); $output = $response->get_parsed_output(); foreach my $row (@$output) { my $obj = $pkg->new( command_interface => $command_interface ); $obj->_set_fields( row => $row ); push @state_objs, $obj; } } #vsan show membership command if ( $pkg->_want_any_field_of( %{$req_field_filter}, fields_filled_by_api => [qw(vsan_id interfaces)] ) ) { $cmd_opts{'membership'} = "1"; $response = $apiset->show_vsan(%cmd_opts); $opts{'membership'} = "1"; my $output = $response->get_parsed_output(); foreach my $row (@$output) { my $obj = $pkg->new( command_interface => $command_interface ); $obj->_set_fields( row => $row ); push @state_objs, $obj; } } return @state_objs; } sub _fetch_brocadefc_cli { my ( $pkg, @args ) = @_; my %opts = validate @args, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my @state_objs; my ( $output, $response ); 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; my $req_field_filter; $req_field_filter->{'requested_fields'} = $requested_fields; $req_field_filter->{'filter'} = \%copy_filter; my ( %new_hash, $vsan_id ); if ( $pkg->_want_any_field_of( %{$req_field_filter}, fields_filled_by_api => [ qw(attributes switchtype switchdomain switchid switchstate switchmode switchwwn switchname zoning router switchrole switchbeacon ports_information port ) ] ) ) { $response = $apiset->switchshow(); $output = $response->get_parsed_output(); foreach my $row (@$output) { $vsan_id = $row->{fid}; $new_hash{$vsan_id} = $row; } } if ( $pkg->_want_any_field_of( %{$req_field_filter}, fields_filled_by_api => [ qw( port vsan_id created_switches ) ] ) ) { $response = $apiset->lscfg_show(); $output = $response->get_parsed_output(); foreach my $row (@$output) { my $fid = $row->{fabrics_info}->[0]->{fid}; if ( exists( $new_hash{$fid} ) ) { $new_hash{$vsan_id}{port} = $row->{fabrics_info}->[0]->{port}; $new_hash{$vsan_id}{created_switches} = $row->{created_switches}; } else { $new_hash{$vsan_id} = $row->{fabrics_info}[0]; $new_hash{$vsan_id}{created_switches} = $row->{created_switches}; } } } foreach my $row ( values %new_hash ) { my $obj = $pkg->new( command_interface => $command_interface ); my $row_modified = $pkg->_hash_copy( source => $row, target => $row, map => { 'fid' => 'vsan_id', }, ); $obj->_set_fields( row => $row_modified ); push @state_objs, $obj; } return @state_objs; } 1;