The graceful_shutdown subroutine in the load_configuration.pl script handles errors in a slightly more elaborate manner than the generic structure described in Submitting a Request. It employs the following additional constants:
use constant REPORT_SUCCESS => 1;
use constant REPORT_FAILURE => 0;
use constant STATE_CONNECTED => 1;
use constant STATE_LOCKED => 2;
use constant STATE_CONFIG_LOADED => 3;
The first two if statements in the subroutine refer to the STATE_CONFIG_LOADED and STATE_LOCKED conditions, which apply specifically to loading a configuration in the load_configuration.pl script. The if statement for STATE_CONNECTED is similar to the error checking described in Submitting a Request. The eval statement used in each case ensures that any errors that occur during execution of the enclosed function call are trapped so that failure of the function call does not cause the script to exit.
sub graceful_shutdown
{
my ($jnx, $req, $state, $success) = @_;
if ($state >= STATE_CONFIG_LOADED) {
print "Rolling back configuration ...\n";
eval {
$jnx->load_configuration(rollback => 0);
};
}
if ($state >= STATE_LOCKED) {
print "Unlocking configuration database ...\n";
eval {
$jnx->unlock_configuration(????);
};
}
if ($state >= STATE_CONNECTED) {
print "Disconnecting from the router ...\n";
eval {
$jnx->request_end_session(????);
$jnx->disconnect(????);
};
}
if ($success) {
die "REQUEST $req SUCCEEDED\n";
} else {
die "REQUEST $req FAILED\n";
};
}