# # Copyright (c) 2001-2013 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary VolumeFileCloneToken ComponentState Module (auto-generated by CGT) ## @author dl-nacl-dev@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::VolumeFileCloneToken =head1 DESCRIPTION C is a derived class of L. It represents the state of an ONTAP VolumeFileCloneToken. A related class is L, which represents access to an ONTAP VolumeFileCloneToken. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the VolumeFileCloneToken element are the attributes of the VolumeFileCloneToken ComponentState. Additionally, the command_interface used to obtain the ComponentState object is also an attribute of the object. This makes it easier to obtain the component object corresponding to the CS object, using L. =over =item command_interface The command_interface with which the CS object was obtained. (Available in all CS objects regardless of requested_fields and the mode/interface) =item C<< expiry_limit >> Token Expiry Limit (in seconds) Filled in for CMode CLI/ZAPI Maps to: CMode ZAPI: "requested_fields", "filter" and Output mapping: $value =item C<< reserve_size >> Available Reserve in Split Load Filled in for CMode CLI/ZAPI =item C<< time_left >> Time Left (in seconds) for Token Expiry Filled in for CMode CLI/ZAPI Maps to: CMode ZAPI: "requested_fields", "filter" and Output mapping: $value =item C<< node >> Node Name possible value(s) are, ,local Filled in for CMode CLI/ZAPI =item C<< token_uuid >> UUID of the token Filled in for CMode CLI/ZAPI =back =cut package NACL::CS::VolumeFileCloneToken; use strict; use warnings; use Params::Validate qw(validate validate_with ARRAYREF UNDEF); 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 base 'NACL::CS::ComponentState::ONTAP'; use Class::MethodMaker [ scalar => 'expiry_limit', scalar => 'reserve_size', scalar => 'time_left', scalar => 'node', scalar => 'token_uuid', ]; =head1 METHODS =head2 fetch my $VolumeFileCloneToken_state = NACL::CS::VolumeFileCloneToken->fetch(command_interface => $ci, ...); my @VolumeFileCloneToken_states = NACL::CS::VolumeFileCloneToken->fetch(command_interface => $ci, ...); (Class method) Discovers which elements are present and returns their state in ComponentState objects. Called in scalar context it returns only one state object, in list context it returns all state objects. See L for a more detailed description along with a complete explanation of the options it accepts. Uses CMode CLI/ZAPI. Invokes "clone-token-get" API for CMode ZAPI. =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 @state_objs = $pkg->SUPER::fetch( @args, choices => [ { method => '_fetch_cmode_cli', interface => 'CLI', set => 'CMode' }, { method => '_fetch_cmode_zapi', interface => 'ZAPI', set => 'CMode', }, ], exception_text => 'No matching volume file clone token(s) found', frontend => 'NACL::CS::VolumeFileCloneToken::fetch', ); $Log->exit() if $may_exit; return wantarray ? @state_objs : $state_objs[0]; } sub _fetch_cmode_cli { $Log->enter() if $may_enter; my ($pkg, %args) = @_; my $filter = $args{filter}; my @state_objs = $pkg->SUPER::_fetch_cmode_cli(%args, api => 'volume_file_clone_token_show',); foreach my $obj (@state_objs) { $obj->token_uuid($filter->{'token-uuid'}); } $Log->exit() if $may_exit; return @state_objs; } sub _fetch_cmode_zapi { $Log->enter() if $may_enter; my ($pkg, @args) = @_; my %opts = validate @args, $pkg->_fetch_backend_validate_spec(); my $command_interface = $opts{command_interface}; my $apiset = $opts{apiset}; my $node = $opts{filter}->{node}; if (!defined $node) { if ($command_interface->can('node')) { $node = $command_interface->node(); } } my ($response, $caught_exception); try { $response = $apiset->clone_token_get( node => $node, 'token-uuid' => $opts{filter}->{'token-uuid'} ); } catch NACL::APISet::Exceptions::NoMatchingEntriesException with { $caught_exception = 1; }; if ($caught_exception) { $Log->exit() if $may_exit; return; } my $output = $response->get_parsed_output(); my $clone_output = $output->[0]->{'clone-token-info'}->[0]; my $obj = $pkg->new(command_interface => $command_interface); my %obj_fields; $obj_fields{token_uuid} = $opts{filter}->{'token-uuid'}; $pkg->_hash_copy( source => $clone_output, target => \%obj_fields, copy => [qw(node reserve-size)], map => { 'reservation-duration-remaining' => 'time-left', 'reservation-duration-limit' => 'expiry-limit', }, ); $obj->_set_fields(row => \%obj_fields); $Log->exit() if $may_exit; return $obj; } sub _compute_cmode_cli_options { $Log->enter() if $may_enter; my ($pkg, @args) = @_; my %opts = validate_with( params => \@args, spec => {requested_fields => {type => ARRAYREF | UNDEF}}, allow_extra => 1 ); my $requested_fields = $opts{requested_fields} || []; if (@$requested_fields) { my %req_field_hash = map { $_ => 1 } @$requested_fields; # "token-uuid" is not applicable for "-fields", so deleting it # from the requested_fields list. delete $req_field_hash{'token-uuid'}; $opts{requested_fields} = [keys %req_field_hash]; } my $options = $pkg->SUPER::_compute_cmode_cli_options(%opts); $Log->exit() if $may_exit; return $options; } 1;