Software Development Kit (SDK) and API Discussions
Software Development Kit (SDK) and API Discussions
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;
}
}
Solved! See The Solution
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();
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.
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();
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.
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.
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>
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
Hi Asulliva,
Thank you for your suggestion. It perfectly solved my problem. I can get the specific value now. Thank you again.