Important

   

This space contains documentation for TrueSight Server Automation 8.9.03 and the later service packs for 8.9. For earlier releases, see BMC Server Automation 8.9.

Instantiating and executing the JLI

The following sample code shows how to instantiate and execute the Jython Line Interface (JLI):

01 #!/usr/bin/env jython
02 import bladelogic.cli.CLI as blcli
03 jli = blcli.CLI()
04 jli.setServiceProfileName("defaultProfile")
05 jli.setRoleName("BLAdmins")
06 jli.connect()
07 cmd = [NameSpace,blcliCmd,Arg1,...,ArgN]
08 returnObject = jli.run(cmd)
09 # returnObject has various methods and properties.
10 # The following 'if' statement demonstrates the important three
11 if(returnObject.success()):
12     print returnObject.returnValue
13 else:
14     print returnObject.getError()

Here is a brief analysis of the preceding lines. See Basic Jython programming principles for more information about underlying concepts.

Line 1: Specify the Jython interpreter.
Line 2: Import the CLI class from the bladelogic.cli module.
Line 3: Create an instance of the CLI class named jli.
Line 4 & 5: Set the profile and role for a BLCLI connection to the application server. This connection is used by the script until it finishes running.
Line 6: Call the jli.connect function to establish a connection to the application server using the credentials acquired using blcred for making CLI calls.
Line 7: The JLI accepts BLCLI commands as arrays (lists). This line demonstrates a pseudo-command in the JLI.
Line 8: The jli.run(cmd) statement accepts the array variable cmd and returns a BLCLI return object to the returnObject variable.
Line 9 & 10: Comments.
Line 11: Test for the successful execution of the JLI command processor. If the command executed successfully, returnObject.success() returns 1; if unsuccessful, returnObject.success() returns 0.
Line 12: If .success() equals 1, this line executes, printing the return value of the executed command.
Line 13: If .success() equals 0, this line begins the else suite of the if…else clause.
Line 14: If .success() equals 0, executing the else suite, this line prints the error retrieved from the unsuccessful execution of the JLI processor.

Note

Although the BLCLI API indicates that some commands accept an integer, the JLI requires that a script pass all commands as strings. Therefore, a script must cast all non-string values to a string before passing their values in an array to the JLI processor. This includes numbers and DB keys.

Was this page helpful? Yes No Submitting... Thank you

Comments