How to use  Perl API bindings

Perform the following steps to invoke an API:

  1. Create a server (NaServer) context

Call the NaServer constructor with the host name or the IP address of the server (Data ONTAP or OnCommand Unified Manager), the major version, and the minor version of the API documentation.

For example:

my $s = NaServer->new( $server, 1, 0);

 

Provide the server with user name and password by using the following core APIs:

$s->set_admin_user($user, $password);

 

If you want to use certificate-based authentication, use set_style ("CERTIFICATE"). You can then use other core APIs related to certificate-based authentication. For more information, see Session Management APIs for Perl Bindings.

 

  1.  Invoke the API as a subroutine

Invoke the API as a subroutine of the server context and pass the input parameters as a hash. To invoke an API, convert the API name into a subroutine name by replacing all the hyphens (if any) with underscore.

 

For example:

system-get-version to system_get_version()

quota-status-iter to quota_status_iter()

dfm-schedule-content-get to dfm_schedule_content_get()

 

You can call this subroutine from the server context (created in Step 1) as a binding.

 

For example:

$s->system_get_version();

$s->quota_status_iter();

$s->dfm_schedule_content_get();

 

Pass the input parameters (if any) of the API as a hash into the subroutine.

 

For example:

If for quota-status-iter API, you want to pass the following XML input:

 

<query>

        <quota-status-attributes>

               <volume>vol0></volume>

        <quota-status-attributes>

<query>

 

The corresponding hash form of this XML input will be:

 

'query' => {

               'quota-status-attributes' =>

                               {'volume' => 'vol0'}

           }

 

This can be passed to the subroutine call as shown below:

 

$s->quota_status_iter('query' =>

     {'quota-status-attributes' => {'volume' => 'vol0'}} );

 

3.     Parse the output

 

The Perl API binding invocation returns a hash reference as the output, which you can parse to extract required output field parameters.

 

For example:

 

my $o = $s->system_get_version();

print "Version: $o->{version}\n";

     

my $tuple = $o->{'version-tuple'}->{'system-version-tuple'};

print "Generation: $tuple->{generation}  

        Major: $tuple->{major}  Minor: $tuple->{minor} \n";

 

4.     Detect the errors

When an error is encountered during the invocation of Perl bindings, an exception is thrown, which you can detect using the “eval” block.

For example:

 

my $s = NaServer->new("10.72.223.12", 1, 1);

$s->set_admin_user("admin", "password");

  

eval{   

    my $output = $s->system_get_version();   

    print "Version: $output->{version}\n";

};

if($@) {

    print "Error: $@\n";

    die;

}