Installing and configuring Jython
This topic describes how to set up a Jython environment on a computer where you have already installed either the BMC Server Automation Application Server or the BMC Server Automation Console (GUI).
Before you begin
Make sure the BMC Server Automation Application Server or the BMC Server Automation Console is installed on the machine. The paths in this section assume a default installation location. Adjust as necessary.
To install and configure Jython
- Go to http://sourceforge.net/projects/jython/files/.
- Expand the jython folder and select the latest stable version. In this document, the 2.5.1 version is used as an example.
- Navigate into the 2.5.1 folder near the bottom of the page and then click the jython_installer-2.5.1.jar file to download it.
If you want a reference for their Jython installation instructions, go to the following location: http://wiki.python.org/jython/InstallationInstructions - Open a command prompt as a local admin and navigate to the directory that contains jython_installer_2.5.1
Run the following command, where bljava is the location of the Java executable for BMC Server Automation. This step is required for the BMC Server Automation implementation of jython.
(Default location for Microsoft Windows)C:\Program Files\BMC Software\BladeLogic<version>\NSH\jre\bin\java.exe
(Default location for UNIX)/opt/bmc/BladeLogic<version>/NSH/br/java/bin/java
(Command syntax for Windows)
<bljava> -jar jython_installer-2.5.1.jar -s -d "C:\Program Files\Jython" -t minimum -i mod
(Command syntax for UNIX)
<bljava> -jar jython_installer-2.5.1.jar -s -d "/usr/local/jython" -t minimum -i mod
This command silently installs the core and libraries in the C:\Program Files\Jython or /usr/local/jython directories.- Perform the following configuration tasks:
- For Windows configuration:
- Edit the C:\Program Files\BMC Software\BladeLogic<version>\NSH\br\bljythonexe.cfg file as follows:
- The Java classpath must be the path to the exact JAR file. In other words:
java.classpath=C:\Program Files\Jython\jython.jar - The Python home needs to be set to the python install dir:
jvm.arg=-Dpython.home=C:\Program Files\Jython
- The Java classpath must be the path to the exact JAR file. In other words:
Ensure that the bljythonexe.cfg file looks like this:
java.mainclass=org/python/util/jython
java.classpath=C:\Program Files\Jython\jython.jar
java.classpath=C:\Program Files\BMC Software\BladeLogic<version>\NSH\br
java.classpath=C:\Program Files\BMC Software\BladeLogic<version>\NSH\br\stdlib
java.classpath=C:\Program Files\BMC Software\BladeLogic<version>\NSH\br\deployments
java.classpath=<default>
jvm.arg=-Xmx1024M
jvm.arg=-Dblx.cmrootdir=C:\Program Files\BMC Software\BladeLogic<version>\NSH\br
jvm.arg=-Dpython.home=C:\Program Files\Jython
jvm.arg=-Dcom.bladelogic.cli.xmldir=C:\Program Files\BMC Software\BladeLogic<version>\NSH\br\xml\cliIn the C:\Program files\Jython\registry file, look for the following line:
#python.path = d:\\python20\\libChange the line as follows:
python.path = C:\\Program Files\\BMC Software\\BladeLogic<version>\\NSH\\br\\jython
- Edit the C:\Program Files\BMC Software\BladeLogic<version>\NSH\br\bljythonexe.cfg file as follows:
- For UNIX configuration:
Edit the /opt/bmc/BladeLogic<version>/NSH//br/bljython file by adding the following lines after the two commented lines at the top.
JYTHON_HOME=/usr/local/jython
export JYTHON_HOME- Edit /usr/local/jython/registry by adding the following line to the top of the file
python.path = <blade_install_dir>/br/jython
- For Windows configuration:
- To verify that bljython runs correctly, open an NSH window and type the following code.
If a list of all servers is returned, your Jython installation and configuration is working correctly.For Windows:
cd "/C/Program Files/BMC Software/BladeLogic/NSH/bin/"
blcred cred -acquire -profile defaultProfile -username BLAdmin -password <password>
./bljythonexe
import sys
import bladelogic.cli.CLI as blcli
jli = blcli.CLI()
jli.setServiceProfileName('defaultProfile')
jli.setRoleName('BLAdmins')
jli.connect()
serverList=jli.run(["Server","listAllServers"]).returnValue
print serverListFor UNIX:
cd "/opt/bmc/BladeLogic/NSH/bin/"
blcred cred -acquire -profile defaultProfile -username BLAdmin -password <password>
./bljython
import sys
import bladelogic.cli.CLI as blcli
jli = blcli.CLI()
jli.setServiceProfileName('defaultProfile')
jli.setRoleName('BLAdmins')
jli.connect()
serverList=jli.run(["Server","listAllServers"]).returnValue
print serverList
You can now run Jython scripts from within the BMC Server Automation GUI or CLI by calling bljython /path/to/script/scriptName.jli from the following:
- Within an NSH Script Job
- The CLI directly
- An NSH script run at the CLI