# # Copyright (c) 2001-2011 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary Cserver ComponentState Module ## @author Isshwarya.M@netapp.com, dl-nacl-dev@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::Cserver =head1 DESCRIPTION C is a derived class of L. It represents the state of an ONTAP Cserver (a.k.a admin vserver). A related class is L, which represents access to an ONTAP Cserver or Cluster. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the Cserver element are the attributes of the Cserver ComponentState. =over =item C<< cserver >> The name of the cserver element whose state is being represented. This is an alias for C =item All the CS attributes which are defined in L would be applicable for C as well. Note that, specifying C attribute in 'filter' is not supported as cservers belong to specific type ('admin') of vservers and it cannot be overriden by the user. =back =cut package NACL::CS::Cserver; 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 NACL::Exceptions::NoElementsFound qw(:try); use NATE::Exceptions::Argument; use base qw(NACL::CS::Vserver); use NACL::ComponentUtils qw(_dump_one Dumper); use Class::MethodMaker [ scalar => 'cserver', ]; =head1 METHODS =head2 fetch my $Cserver_state = NACL::CS::Cserver->fetch(command_interface=>$ci,...); my @Cserver_states = NACL::CS::Cserver->fetch(command_interface=>$ci,...); see L =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, %opts) = @_; if (exists $opts{filter}->{type}) { $Log->exit() if $may_exit; NATE::Exceptions::Argument->throw( "Specifying 'type' input in the filter is not supported". " as Cserver has a specific type ('admin') associated with it". " and it cannot be overriden" ); } $opts{requested_fields} = $pkg->_handle_requested_fields( requested_fields => $opts{requested_fields}); # specify the vserver type to be 'admin' in the filter for # find, fetch, state, get_one_state_attribute calls my %filter = %{$opts{filter}}; $filter{type} = 'admin'; $opts{filter} = \%filter; # If the caller had specified 'cserver' in filter, then map the # input to 'vserver'. if (defined $opts{filter}->{cserver}) { $opts{filter}->{vserver} = delete $opts{filter}->{cserver}; } # Reset the error message appropriately my @state_objs; try { @state_objs = $pkg->SUPER::fetch(%opts); } catch NACL::Exceptions::NoElementsFound with { my $ex = shift; my $text = $ex->text(); $text =~ s/No matching vserver\(s\) found/No matching cserver(s) found/s; $ex->set_text($text); $ex->throw(); }; # Create NACL::CS::Cserver objects from NACL::CS::Vserver foreach my $obj (@state_objs) { $obj->cserver($obj->vserver()); } $Log->exit() if $may_exit; return wantarray ? @state_objs : $state_objs[0]; } ## end sub fetch sub _handle_requested_fields { $Log->enter() if $may_enter; my ($pkg, %args) = @_; # 'cserver' present in the requested_fields should be updated to # 'vserver' for NACL::CS::Vserver->fetch to understand. my @req_fields; if (defined $args{requested_fields}) { @req_fields = @{$args{requested_fields}}; for (my $i=0; $i< @req_fields; $i++) { if($req_fields[$i] eq 'cserver') { $req_fields[$i] = 'vserver'; last; } } } $Log->exit() if $may_exit; return \@req_fields; } 1;