# $Id: //depot/prod/test/nacldev/lib/NACL/CS/NetworkRoutingGroupsRoute.pm#21 $ # # Copyright (c) 2001-2013 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary NetworkRoutingGroupsRoute ComponentState Module ## @author Sumit.Mittal@netapp.com, dl-nacl-dev@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::NetworkRoutingGroupsRoute =head1 DESCRIPTION C is a derived class of L. It represents the state of a NetworkRoutingGroupsRoute. A related class is L, which represents =head1 ATTRIBUTES The individual pieces of data that are part of the state of the element are the attributes of the ComponentState. =over =item C<< vserver >> Filled in for CMode CLI/ZAPI. Maps to: CM ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< server >> Filled in for CMode CLI/ZAPI. Maps to: CM ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< routing_group >> Filled in for CMode CLI/ZAPI. Maps to: CM ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< destination >> Filled in for CMode CLI/ZAPI,7Mode CLI. Maps to: CM ZAPI: For "requested_fields", "filter" and Output mapping: $value 7M 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<< gateway >> Filled in for CMode CLI/ZAPI,7Mode CLI. Maps to: CM ZAPI: For "requested_fields", "filter" and Output mapping: $value 7M 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 CMode CLI/ZAPI. Maps to: CM ZAPI: For "requested_fields", "filter" and Output mapping: $value =item C<< interface >> Filled in for 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<< pmtu >> Filled in for 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<< address_family >> Filled in for CMode CLI. =back =cut package NACL::CS::NetworkRoutingGroupsRoute; use strict; use warnings; 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 base 'NACL::CS::ComponentState::ONTAP'; use NACL::CS::NetworkRoute; use Class::MethodMaker [ # These fields are from the C Mode "network interface routing-groups route show" scalar => 'vserver', scalar => 'server', scalar => 'routing_group', scalar => 'destination', scalar => 'gateway', scalar => 'metric', scalar => 'interface', scalar => 'pmtu', scalar => 'address_family', ]; sub isa { $Log->enter() if $may_enter; my ($pkg_or_obj, $kind) = @_; my $isa = $pkg_or_obj->_build_isa( kind => $kind, alias => 'NACL::CS::Route' ); $Log->exit() if $may_exit; return $isa; } =head1 METHODS =head2 fetch my $node_state = NACL::CS::ExportPolicyRule->fetch(command_interface=>$ci,...); my @node_states = NACL::CS::ExportPolicyRule->fetch(command_interface=>$ci,...); see L Supports CMode CLI/ZAPI, 7Mode CLI. Invokes "net-routing-group-route-get-iter" API for CMode ZAPI. Invokes "route show" 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, @args) = @_; my %opts = validate @args, $pkg->_fetch_validate_spec(); my $ci = $opts{command_interface}; my $vm = $ci->version_manager(); if ($ci->is_cmode() && $opts{command_interface}->has_uichange( uichange => 'ipspaces-ms4', throw_exception => 0 ) ) { my $route_pkg = 'NACL::CS::NetworkRoute'; my $method = 'fetch'; $Log->warn("The method $pkg->$method was invoked on an " . "IPSpace build. However, the 'network routing-groups route' " . 'set of commands is now deprecated and has been replaced by ' . "the 'network route' set of commands. For this reason, all " . "calls to '$pkg' must be replaced by calls to '$route_pkg'. " . "The script updates will need to be made like this:\n\n" . "\tif (\$node->has_uichange(uichange => 'ipspaces-ms4') {\n" . "\t\t# IPSpace build, should use new library\n" . "\t\t$route_pkg->$method(%options);\n" . "\t} else {\n" . "\t\t# Non-IPSpace build, should use older library\n" . "\t\t$pkg->$method(%options);\n" . "\t}\n\n" . 'Since this is a functionality change, not all of the options ' . 'accepted by the old commands are accepted by the new commands. ' . 'See ' . 'http://wikid.netapp.com/w/SCON/QA/FS0/IPspaces/Regression_scripts_guidelines' . ' for complete details. For any further queries, mail ' . "dl-ipspace-automation.\n"); } my @state_objs = $pkg->SUPER::fetch( %opts, show_cmd => 'network routing-groups route show', choices => [ { method => '_fetch_cmode_cli', interface => 'CLI', set => 'CMode', }, { method => '_fetch_cmode_zapi', interface => 'ZAPI', set => 'CMode', }, { method => '_fetch_7mode_cli', interface => 'CLI', set => '7Mode', }, ], exception_text => 'No matching network routing groups route(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 @state_objs = $pkg->SUPER::_fetch_cmode_cli(@_, api => 'network_routing_groups_route_show'); $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_cmode_cli sub _fetch_cmode_zapi { $Log->enter() if $may_enter; my $pkg = shift; my @state_objs = $pkg->SUPER::_fetch_cmode_zapi( @_, api => 'net_routing_group_route_get_iter', copy => [qw(routing-group metric vserver)], map => { 'server' => ['vserver'], 'destination' => ['destination-address'], 'gateway' => ['gateway-address'], }, ); foreach my $obj (@state_objs) { if (!$obj->server_isset && $obj->vserver_isset) { $obj->server($obj->vserver); } } $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_cmode_zapi sub _fetch_7mode_cli { $Log->enter() if $may_enter; my $pkg = shift; my %opts = validate @_, $pkg->_fetch_backend_validate_spec(); my $apiset = delete $opts{apiset}; 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 @state_objs; my $response = $apiset->route_show(); my $output = $response->get_parsed_output(); foreach my $row (@$output) { my $row_modified; my $inet = $row->{internet} || $row->{internet_v6}; foreach my $inet_details (@$inet) { my $obj = $pkg->new(command_interface => $opts{command_interface}); $row_modified = $pkg->_hash_copy( source => $inet_details, copy => [qw(destination gateway interface pmtu)], ); $obj->_set_fields(row => $row_modified); push @state_objs, $obj; } } $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_7mode_cli 1;