How to: Using APIs in WFA with Perl and Clustered ONTAP

by Occasional Contributor on ‎2013-04-25 12:33 PM

I wanted to be able to use perl to use the APIs to run commands against Clustered ONTAP, currently WFA does not have this functionality built in but if you would like to use Perl to write commands for Clustered ONTAP, here is how you can do that:

1. Download the attached WFAUtil.PM, here is what I actually added to it, basically I just copied the existing 7mode connection information and converted it to Clustered ONTAP friendly information:

sub connectCM {

          my ($self, $cmarray, $vserver) = @_;

 

          my $server = NaServer->new($cmarray, 1, 15);

          $server->set_server_type('FILER');

 

          if (defined $vserver)

          {

                    $server->set_vserver($vserver);

          }

 

          my @credentials = getCredentials($self, $cmarray);

 

          if(defined @credentials[0] && defined @credentials[1])

          {

  # use regular authentication

                    $server->set_style('LOGIN');

                    $server->set_admin_user($credentials[0], $credentials[1]);

                    $server->set_transport_type('HTTPS');

          }

else

          {

  # use domain authentication

                    $server->set_style('CERTIFICATE');

       

        # disable certification verification (since simulators have self signed certificates)

        $server->set_server_cert_verification(0);

          }

 

# connect over HTTPS and fall back to HTTP in case of failure

          my $result = checkConnectionCM($self, $server);

          if($result == 0)

          {

  # connection over HTTPS failed - fall back to HTTP

                    $server->set_transport_type('HTTP');

 

  # chech the connection again

                    my $result = checkConnectionCM($self, $server);

                    if($result == 0)

                    {

  warn "\nUnable to connect to array\n";

                              exit 2;

                    }

          }

 

          return $server;

}

sub checkConnectionCM {

          my ($self, $server ) = @_;

 

# invoke a command in order to verify connection

          my $output = $server->invoke( "system-get-ontapi-version" );

          if (ref ($output) eq "NaElement" && $output->results_errno != 0)

          {

  # failed to establish connection

  return 0;

          }

else

          {

  # successfully connected

  return 1;

          }

}

2. Place the WFAUtil.PM in your perl library folder on your WFA server

3. You can use the attached command as an example for how it works

Thanks!

Comments
Extraordinary Contributor

Excellent Post. 5 Stars.

Frequent Contributor

I agree.  Truely awesome stuff!

Frequent Contributor

Great stuff! thanks!

Nice info.Helpful.thnks.

One question..

I want to create new User and role in the filer using the WFA(I wanna perl code for that).Can you plz share with me if you have code for that?.

I have tried with below code..but not working..

#!/usr/bin/perl

use strict;

use warnings;

use  NaServer;

use NaElement;

use Getopt::Long;

use WFAUtil;

our $array;our $server;our $vfiler;our $RoleName;our $comment;our $CapaName;our $api;our $xi1;

GetOptions("array=s" => \$array,

                 "RoleName" => \$RoleName,

                       "comment"   =>  \$comment,

                       "CapaName"  =>  \$CapaName

             ) or die "Illigal Options";

if(!  defined $array){ die "Array Name/ip Address is mendatory";}

my $wfautil=WFAUtil->new();

$wfautil->sendLog('INFO','Connecting to array:',$array);

$server=$wfautil->connect($array,$vfiler);

my $api = WFAUtil->new('useradmin-role-add');

my $xi = WFAUtil->new('useradmin-role');

$api->child_add($xi);

my $xi2 = WFAUtil->new('allowed-capabilities');

my $xi1->child_add($xi2);

my $xi3 = WFAUtil->new('useradmin-capability-info');

$xi2->child_add($xi3);

$xi3->child_add_string('name','login-snmp');

$xi1->child_add_string('comment','Testing');

$xi1->child_add_string('name','snmpAuth');

my $xi4=$wfautil->checkFailure("Failed to run the command",$server->invoke($api));

$wfautil->sendLog('INFO','Create the role for the user failed'.$array);

Thanks in advance..

Regards

Rao.


Thanks in advance..

Warning!

This NetApp Community is public and open website that is indexed by search engines such as Google. Participation in the NetApp Community is voluntary. All content posted on the NetApp Community is publicly viewable and available. This includes the rich text editor which is not encrypted for https.

In accordance to our Code of Conduct and Community Terms of Use DO NOT post or attach the following:

  • Software files (compressed or uncompressed)
  • Files that require an End User License Agreement (EULA)
  • Confidential information
  • Personal data you do not want publicly available
  • Another’s personally identifiable information
  • Copyrighted materials without the permission of the copyright owner

Files and content that do not abide by the Community Terms of Use or Code of Conduct will be removed. Continued non-compliance may result in NetApp Community account restrictions or termination.