[Contents] [Prev] [Next] [Index] [Report an Error]

Submitting a Request

The following is the recommended way to send a request to the JUNOScript server. It assumes that the $jnx variable was previously defined to be a JUNOS::Device object, as discussed in Establishing the Connection.

The following code sends a request to the JUNOScript server and handles error conditions. A detailed discussion of the functional subsections follows the complete code sample.

     my %arguments = (???);
     %arguments = ( argument1  =>  value1 ,
          argument2  =>  value2 , ...);
          argument3  =>  value3 ,
         ...);
    
     my $res = $jnx-> method (%args);
    
     unless ( ref $res ) {
         $jnx->request_end_session(????);
         $jnx->disconnect(????);
         print "ERROR: Could not send request to $hostname\n";
     }
    
     my $err = $res->getFirstError(????);
     if ($err) {
         $jnx->request_end_session(????);
         $jnx->disconnect(????);
         print "ERROR: Error for $hostname: " . $err->{message} . "\n";
     }

The first subsection of the preceding code sample creates a hash called %arguments to define values for a method’s options or attributes. For each argument, the application uses the notation described in Providing Method Options or Attributes.

     my %arguments = (????);
     %arguments = ( argument1  =>  value1 ,
          argument2  =>  value2 , ...);
          argument3  =>  value3 ,
         ...);

The application then invokes the method, defining the $res variable to point to the JUNOS::Response object that the JUNOScript server returns in response to the request (the object is defined in the lib/JUNOS/Response.pm file in the JUNOScript Perl distribution):

     my $res = $jnx-> method (%args);

If the attempt to send the request failed, the application prints an error message and closes the connection:

     unless ( ref $res ) {
         $jnx->request_end_session(????);
         $jnx->disconnect(????);
         print "ERROR: Could not send request to $hostname\n";
     }

If there was an error in the JUNOScript server’s response, the application prints an error message and closes the connection. The getFirstError function is defined in the JUNOS::Response module (lib/JUNOS/Response.pm) in the JUNOScript Perl distribution.

     my $err = $res->getFirstError(????);
     if ($err) {
         $jnx->request_end_session(????);
         $jnx->disconnect(????);
         print "ERROR: Error for $hostname: " . $err->{message} . "\n";
     }

[Contents] [Prev] [Next] [Index] [Report an Error]