# # Copyright (c) 2014 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # # ## @summary Ifconfig ComponentState Module ## @author kathar@netapp.com, dl-nacl-dev@netapp.com ## @status shared ## @pod here ################################################################################ =head1 NAME NACL::CS::Client::Ifconfig =head1 DESCRIPTION C is a derived class of L. It represents the state of Interface. A related class is L, which represents access to an interface. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the Ifconfig element are the attributes of the Ifconfig ComponentState. =over =item C<< interface >> Filled in for Linux CLI, Solaris CLI. Maps to: Linux CLI: For 'filter': Interface name (Programmatic name: interface) For 'requested_fields', Not applicable, but the field will be populated in the CS object. Solaris CLI: For 'filter': Interface name (Programmatic name: interface) For 'requested_fields', Not applicable, but the field will be populated in the CS object. =item C<< rx_dropped >> Filled in for Linux CLI. Maps to: Linux 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<< rx_packets >> Filled in for Linux CLI. Maps to: Linux 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 Linux CLI. Maps to: Linux 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<< collisions >> Filled in for Linux CLI. Maps to: Linux 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<< metric >> Filled in for Linux CLI. Maps to: Linux 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<< inet_addr >> Filled in for Linux/Solaris CLI. Linux 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. Solaris 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<< hwaddr >> Filled in for Linux/Solaris CLI. Maps to: Linux 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. Solaris 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<< link_encap >> Filled in for Linux CLI. Maps to: Linux 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<< rx_frame >> Filled in for Linux CLI. Maps to: Linux 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<< tx_bytes >> Filled in for Linux CLI. Maps to: Linux 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<< txqueuelen >> Filled in for Linux CLI. Maps to: Linux 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<< property >> Filled in for Linux CLI. Maps to: Linux 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<< mask >> Filled in for Linux/Solaris CLI. Maps to: Linux 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. Solaris 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<< mtu >> Filled in for Linux/Solaris CLI. Maps to: Linux 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. Solaris 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<< tx_carrier >> =item C<< bcast >> Filled in for Linux CLI. Maps to: Linux 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<< tx_packets >> Filled in for Linux CLI. Maps to: Linux 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<< rx_overruns >> Filled in for Linux CLI. Maps to: Linux 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<< tx_dropped >> Filled in for Linux CLI. Maps to: Linux 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<< rx_bytes >> Filled in for Linux CLI. Maps to: Linux 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<< rx_errors >> Filled in for Linux CLI. Maps to: Linux 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<< tx_overruns >> Filled in for Linux CLI. Maps to: Linux 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<< tx_errors >> Filled in for Linux CLI. Maps to: Linux 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<< inet6_info >> (Array) Filled in for Linux/Solaris CLI. Maps to: Linux 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<< flags >> Filled in for Linux CLI. Maps to: Linux 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<< tx_collisions >> Filled in for Linux CLI. Maps to: Linux 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 =back =head2 command_interface See L =cut ################### # Package package NACL::CS::Client::Ifconfig; ################### use strict; use warnings; ################### # Module includes use NACL::ComponentUtils qw (_optional_scalars Dumper); use base 'NACL::CS::ComponentState::Client'; use Params::Validate qw(validate validate_with SCALAR BOOLEAN); use NACL::APISet::Exceptions::ResponseException qw/:try/; use NATE::Log qw(log_global); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); use Class::MethodMaker [ scalar => 'interface', scalar => 'rx_dropped', scalar => 'rx_packets', scalar => 'status', scalar => 'collisions', scalar => 'metric', scalar => 'inet_addr', scalar => 'hwaddr', scalar => 'link_encap', scalar => 'rx_frame', scalar => 'tx_bytes', scalar => 'txqueuelen', scalar => 'property', scalar => 'mask', scalar => 'mtu', scalar => 'tx_carrier', scalar => 'bcast', scalar => 'tx_packets', scalar => 'rx_overruns', scalar => 'tx_dropped', scalar => 'rx_bytes', scalar => 'rx_errors', array => 'inet6_info', scalar => 'tx_overruns', scalar => 'tx_errors', scalar => 'addr', scalar => 'scope', scalar => 'inet6', scalar => 'interrupt', scalar => 'memory', scalar => 'flags', scalar => 'tx_collisions', ]; =head1 METHODS =head2 fetch my $interface_state = NACL::CS::Client::Ifconfig->fetch(command_interface=>$ci,...); my @interface_states = NACL::CS::Client::Ifconfig->fetch(command_interface=>$ci,...); see L Supports Linux/Solaris CLI. Invokes "ifconfig" command for Linux/Solaris 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 = shift; my @state_objs = $pkg->SUPER::fetch( @_, choices => [ { method => "_fetch_solaris_cli", interface => "CLI", set => "Solaris" }, { method => "_fetch_linux_cli", interface => "CLI", set => 'Linux' } ], exception_text => 'No matching storage disk(s) found' ); $Log->exit() if $may_exit; return wantarray ? @state_objs : $state_objs[0]; } ## end sub fetch sub _fetch_linux_cli { $Log->enter() if $may_enter; my $pkg = shift; my %opts = validate @_, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my $filter = $opts{filter}; my ( @state_objs, $output, $response ); my %api_args; $apiset->set_privilege( 'privilege-level' => "root" ); if ( defined $filter->{interface} ) { $api_args{interface} = $filter->{interface}; $response = $apiset->ifconfig(%api_args); } else { $response = $apiset->ifconfig( all => 1 ); } $output = $response->get_parsed_output(); foreach my $row (@$output) { my $obj = $pkg->new( command_interface => $opts{command_interface} ); $obj->_set_fields( row => $row ); push @state_objs, $obj; } ## end foreach my $row (@$output) $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_linux_cli sub _fetch_solaris_cli { $Log->enter() if $may_enter; my $pkg = shift; my %opts = validate @_, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my $filter = $opts{filter}; my ( @state_objs, $output, $response, $obj ); my %api_args; $apiset->set_privilege( 'privilege-level' => "root" ); if ( defined $filter->{'interface'} ) { $api_args{interface} = $filter->{interface}; $response = $apiset->ifconfig(%api_args); } else { $response = $apiset->ifconfig( all => 1 ); } $output = $response->get_parsed_output(); my $allowed_options = qw[(interface)]; foreach my $row (@$output) { $obj = $pkg->new( command_interface => $opts{command_interface} ); my $temp = $row->{configuration}; foreach my $val ( @{$temp} ) { my $row_config = $pkg->_hash_copy( source => $val, map => { 'ether' => 'hwaddr', 'inet' => 'inet_addr', 'netmask' => 'mask', }, copy => [qw(mtu)], ); $val->{flags} =~ /<(\w+),(\w+,\w+,\w+),.*/; $row_config->{'property'} = $2; $row_config->{'status'} = $1; $obj->_set_fields( row => $row_config ); } $obj->_set_fields( row => $row ); push @state_objs, $obj; } my $output_ipv6; if ( defined $filter->{interface} ) { $api_args{inet6} = 1; $response = $apiset->ifconfig(%api_args); $output_ipv6 = $response->get_parsed_output(); } if ( defined(@$output_ipv6) ) { foreach my $row (@$output_ipv6) { my $temp = $row->{configuration}; my %temp1; foreach my $val ( @{$temp} ) { $temp1{inet6_info}->[0]->{addr} = $val->{inet6}; $obj->_set_fields( row => \%temp1 ); } push @state_objs, $obj; } } $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_solaris_cli 1;