Software Development Kit (SDK) and API Discussions
Software Development Kit (SDK) and API Discussions
I'm playing around with the ONTAP / managability SDK (v1.0) and am trying to work out the options around "host-list-info-iter-start", specifically with specifying "host-types"
I am trying to obtain a list of physical filers from DFM.
If I run:
perl apitest.pl -x -t dfm dfmserver user password host-list-info-iter-start host-types filer
It returns:
OUTPUT:
<results status="passed">
<records>149</records>
<tag>host5710_11376</tag>
</results>
If I then run
perl apitest.pl -x -t dfm dfmserver user password host-list-info-iter-next tag host5710_11376 maximum 149
I get a dump of everything, i.e. filers, vfilers, ossv clients, etc.
It seems as if the host-types parameter is being ignored, or I have made a mistake in the syntax...??
Any assistance will be greatly appreciated!
Thanks,
Josh
Solved! See The Solution
You need to use nested child as the host-types is an array.
perl apitest.pl -i -t dfm dfmserver user password "<host-list-info-iter-start><host-types><host-type>filer</host-type></host-types></host-list-info-iter-start>"
This should do the job for you
Regards
Vishal Kulkarni
You need to use nested child as the host-types is an array.
perl apitest.pl -i -t dfm dfmserver user password "<host-list-info-iter-start><host-types><host-type>filer</host-type></host-types></host-list-info-iter-start>"
This should do the job for you
Regards
Vishal Kulkarni
Thanks Vishal, that works perfectly!
I've tried implementing this in perl but have hit a similar roadblock...
I can use the method parse_raw_xml("<host-list-info-iter-start><host-types><host-type>filer</host-type></host-types></host-list-info-iter-start>") to get the correct output however, is there a cleaner way to do this by using the child_add_string() and/or child_add() methods instead? I've tried passing an array to child_add_string but this doesn't do the trick.
Nevermind... Figured it out by creating new elements and adding them as childs.
Cheers,
Josh
Would you please share your code for adding the children to the request?
Thanks
Here you go:
##### Global variables
my %host_to_ip;
##### VARIABLES SECTION
my $args = $#ARGV + 1;
if ($args < 3) {
usage();
}
my ( $dfmserver, $dfmuser, $dfmpw ) = @ARGV;
# Creating a server object and setting appropriate attributes
my $serv = NaServer->new( $dfmserver, 1, 0 );
$serv->set_style("LOGIN");
$serv->set_transport_type("HTTP");
$serv->set_server_type("DFM");
$serv->set_port(8088);
$serv->set_admin_user( $dfmuser, $dfmpw );
host_list($serv);
sub host_list($) {
my $server = $_[0]; # Reading the server object
# creating a input element
my $input = NaElement->new("host-list-info-iter-start");
# invoking the api and capturing the ouput
my $output = $server->invoke_elem($input);
if ( $output->results_status() eq "failed" ) {
print( "Error : " . $output->results_reason() . "\n" );
exit(-2);
}
# Extracting the record and tag values and printing them
my $records = $output->child_get_string("records");
if ($records eq "0") {
print "\nNo hosts to display.\n";
exit 0;
}
my $tag = $output->child_get_string("tag");
# Iterating through each record
# Extracting records one at a time
my $record =
$server->invoke( "host-list-info-iter-next", "maximum", $records, "tag", $tag );
if ( $record->results_status() eq "failed" ) {
print( "Error : " . $record->results_reason() . "\n" );
exit(-2);
}
# Navigating to the hosts child element
my $hosts = $record->child_get("hosts") or exit 0 if ($record);
# Navigating to the host-info child element
my @info = $hosts->children_get() or exit 0 if ($hosts);
# Iterating through each record
foreach my $info (@info) {
$host_to_ip{$info->child_get_string("host-name")} =
$info->child_get_string("host-address");
}
# invoking the iter-end zapi
my $end = $server->invoke( "host-list-info-iter-end", "tag", $tag );
if ( $end->results_status() eq "failed" ) {
print( "Error : " . $end->results_reason() . "\n" );
exit(-2);
}
}
Regards,
- Rick -
Thanks Rick. What I was looking for was how to specify the host-type in perl by adding to the element.
I am looking at the invoke_elem() method.
If I have it correct I need to build the element with NaElement methods and then invoke it with invoke_elem().
Thanks.
Craig -
Here is a code snippet:
# creating a input element to get all vfilers
my $input = NaElement->new("host-list-info-iter-start");
my $host_types = NaElement->new("host-types");
$host_types->child_add_string("host-type", "vfiler");
$input->child_add($host_types);
# invoking the api and capturing the ouput
my $output = $server->invoke_elem($input);
Regards,
- Rick -
Thank you! I did have a mistake.
This works great.
This is the code ZEDI produces in Perl for the given API when I select host-types -
require 5.6.1;
use lib '<path_to_nmsdk_root>/lib/perl/NetApp';
use strict;
use warnings;
use NaServer;
use NaElement;
my $s = new NaServer('<server name or IP address>', 1 , 0);
$s->set_server_type('DFM');
$s->set_transport_type('HTTPS');
$s->set_port(8488);
$s->set_style('LOGIN');
$s->set_admin_user('<user name>', '<password>');
my $api = new NaElement('host-list-info-iter-start');
my $xi = new NaElement('host-types');
$api->child_add($xi);
$xi->child_add_string('host-type','<host-type>');
my $xo = $s->invoke_elem($api);
if ($xo->results_status() eq 'failed') {
print 'Error:\n';
print $xo->sprintf();
exit 1;
}
print 'Received:\n';
print $xo->sprintf();
Should do the work on providing the host-type. You can find ZEDI within your NMSDK 5.0 folder.
-Kunal