Software Development Kit (SDK) and API Discussions

got empty returned when invoke 'aggr-option-list-info' and other aggr API in Perl

wolfohyeah
6,061 Views

Hi, I got an empty returned when I use 'child_get' after invoke 'aggr-options-list-info' API in Perl.

'aggr-options-list-info' invoke result is 'pass'. But it returns 'undefined' when i use 'child_get' to get the options.

I debug this for many times but it didn't work for me. aggr-space-list-info also doesn't work for me due to the same reason.

Any one can help me? Thanks.

 

Linux version: Redhat5.4 32bit

Perl version: 5.8.8

Simulator: 7.3.6-sim-cdrom-image-v22.iso

SDK: 5.4P1

 

By the way, as a new Perl user, I'm always confused between 'child_get" and "children_get".

 

[root@szds script]# ./nasmanager Can't call method "children_get" on an undefined value at ./nasmanager line 45.

 

My code:

sub get_aggr_option()

{

        connect_filer();

        $out=$s->invoke("aggr-options-list-info","aggregate","aggr1");

     if ($out->results_status() eq "failed")

     {

            print($out->results_reason() ."\n");

            exit (-2);

     }

     my $optinfo = $out->child_get("aggr-option-info");

     ### this line below has error because $optinfo is undefined

     my @result=$optinfo->children_get();

     foreach $opt (@result)

     {

         my $realloc=$opt->child_get_string("free-space-realloc");

         print $realloc;

     }

}

1 ACCEPTED SOLUTION

wh_slayer
6,015 Views

The output of the aggr-options-list-info API is called "options".  That is what you need to fetch via child_get.  "options" is an array of aggr-option-info data types which you can then fetch with children_get.

 

my $optinfo = $out->child_get("options");
my @result = $optinfo->children_get();

 

View solution in original post

8 REPLIES 8

wolfohyeah
6,019 Views

well, I try another filer and it returned 'fail' when invoke it. XML return 13001 result with title '404 not found'. But it works in ZEDI.

I don't know why it works in Zedi but doesn't work in Perl script. I copied the script from Zedi.

wh_slayer
6,016 Views

The output of the aggr-options-list-info API is called "options".  That is what you need to fetch via child_get.  "options" is an array of aggr-option-info data types which you can then fetch with children_get.

 

my $optinfo = $out->child_get("options");
my @result = $optinfo->children_get();

 

wolfohyeah
6,011 Views

Hi wh_slayer,

Thank you for your reply. I try '$optinfo=$out->child_get("options")' and the script can run correctly.

But I still confused about how to get the value of the specific options (eg. fs_size_fixed).

Before this week, I just invoke the qtree/volume/quota API for sime simple management. Now I need to try the options API but the document doesn't cleary describe it .

Thank you again.

wh_slayer
5,897 Views

Well I generally work with the Perl bindings interface rather than the XML interface, but I think you'd do something like this:

 

my $optinfo = $out->child_get("options");
my $fs_size_fixed = $optinfo->child_get("fs_size_fixed");

If you haven't already discovered this, the NaElement::sprintf function is incredibly helpful for determining the structure of the data returned, especially given the amount of nesting some elements have.

wolfohyeah
5,875 Views

Hi wh_slayer,

  In fact, i tried 'sprintf' and can get the name-value information in XML style.  But my purpose is to get specific name-value pairs instead of returning all. I tried "child_get" and "child_get_string" and "children_get" but empty was returned. This child_get* works in non-option API but failed in option API.  I think this is related to Perl program instead of netapp api but i have no idea.

 

  Sprintf returns like below:

  <options>

          <aggr-option-info>

                   <name>fs_size_fixed</name>

                  <value>off</value

          </aggr-option-info>

          <aggr-optioninfo>

                   <name>...</name>

                   <value>...</value>

          </aggr-option-info>

               .......

   </options>

wolfohyeah
5,831 Views
well, it still doesn't work except sprintf.

asulliva
5,814 Views

Hello @wolfohyeah,

 

Here is a Perl snippet which will return the value of a specific aggregate option without using the Perl bindings.

 

 

#! /usr/bin/perl

use NaServer;
use NaElement;

my $server = "controller.name.or.ip";
my $username = "admin";
my $password = "SuperSecret!";
my $aggregate_name = "aggr1";


my $s = NaServer->new ($server, 1, 3);
$s->set_style(LOGIN);
$s->set_admin_user($username, $password);
$s->set_transport_type(HTTP);
$s->set_hostname_verification( 0 );

my $aggr_options_request = $s->invoke(
    "aggr-options-list-info", 
    "aggregate", 
    $aggregate_name
);

foreach my $option ($aggr_options_request->child_get('options')->children_get()) {
    if ($option->child_get_string("name") eq "fs_size_fixed") {
        print "fs_size_fixed = " . $option->child_get_string("value") . "\n";
    }
    
    # show all options and their values
    #print " Option Name: " . $option->child_get_string("name") . "\n";
    #print "Option Value: " . $option->child_get_string("value") . "\n\n";
  
}

 

Here is the same thing using Perl bindings:

 

my $aggr_options_request = $s->aggr_options_list_info( 'aggregate' => $aggregate_name );

foreach (@{$aggr_options_request->{'options'}->{'aggr-option-info'}}) {
    if ($_->{'name'} eq "fs_size_fixed") {
        print "fs_size_fixed = " . $_->{'value'} . "\n";
    }
    
    # show all options and their values
    #print " Option Name: " . $_->{'name'} . "\n";
    #print "Option Value: " . $_->{'value'} . "\n\n";
  
}

 

Hope that helps.

 

Andrew

 

If this post resolved your issue, please help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

wolfohyeah
5,794 Views

@asulliva

 

Hi Asulliva,

 

Thank you for your suggestion. It  perfectly solved my problem. I can get the specific value now. Thank you again.

Public