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

Obtaining Application-Specific Parameters

In addition to the parameters required by the JUNOS::Device object, applications might need to define other parameters, such as the name of the file to which to write the data returned by the JUNOScript server in response to a request, or the name of the Extensible Stylesheet Transformation Language (XSLT) file to use for transforming the data.

As with the parameters required by the JUNOS::Device object, your application can hardcode the values in the application code, obtain them from a file, or obtain them interactively. The sample scripts obtain values for these parameters from command-line options in the same manner as they obtain the parameters required by the JUNOS::Device object (discussed in Obtaining and Recording Parameters Required by the JUNOS::Device Object). Several examples follow.

The following line enables a debugging trace if the user includes the -d command-line option. It invokes the JUNOS::Trace::init routine defined in the JUNOS::Trace module, which is already imported with the JUNOS::Device object.

     JUNOS::Trace::init(1) if $opt{d};

The following line sets the $outputfile variable to the value specified by the -o command-line option. It names the local file to which the JUNOScript server’s response is written. If the -o option is not provided, the variable is set to the empty string.

     my $outputfile = $opt{o} || “ “ ;

The following code from the diagnose_bgp.pl script defines which XSLT file to use to transform the JUNOScript server’s response. The first line sets the $xslfile variable to the value specified by the -x command-line option. If the option is not provided, the script uses the text.xsl file supplied with the script, which transforms the data to ASCII text. The if statement verifies that the specified XSLT file exists; the script terminates if it does not.

     my $xslfile = $opt{x} || "xsl/text.xsl";
     if ($xslfile && ! -f $xslfile) {
         die "ERROR: XSLT file $xslfile does not exist";
     }

The following code from the load_configuration.pl script defines whether to merge, replace, update, or overwrite the new configuration data into the configuration database (for more information about these operations, see Changing Configuration Information). The first two lines set the $load_action variable to the value of the -a command-line option, or to the default value merge if the option is not provided. If the specified value does not match one of the four defined in the third line, the script invokes the output_usage subroutine.

     # The default action for load_configuration is 'merge'
     my $load_action = "merge";
     $load_action = $opt{a} if $opt{a};
     use constant VALID_ACTIONS => "merge|replace|override";
     output_usage(???) unless ($load_action =~ /VALID_ACTIONS/);

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