|
Problem |
The Information Center documents how one jython script can
call another. However, using the second script to perform wsadmin commands
can fail with a NamingError. |
|
Cause |
Example error:
WASX7093I: Issuing message: "WASX7017E: Exception received while
running file "MyScript.py"; exception information:
com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
File "<string>", line 10, in ?
File "C:/temp/MyScript2.py",
line 8, in saveChanges
NameError: AdminConfig
The problem is that "AdminConfig" is not identified as a valid function,
keyword, or variable in the second script. |
|
Solution |
The example below shows how one jython script can call
another jython script to perform a wsadmin command. The example simply has
one script (CreateVirtualHost.py) which creates a new virtual host, and
calls a second script (save.py), which performs the save. This example can
be used as a template for a more complex scenario.
The contents of CreateVirtualHost.py:
execfile('C:/temp/save.py')
cell = AdminConfig.getid('/Cell:<Cell_Name>/')
print cell
vtempl = AdminConfig.listTemplates('VirtualHost',
'default_host')
print vtempl
AdminConfig.createUsingTemplate('VirtualHost', cell, [['name',
'newVirtualHostName']], vtempl)
print "Calling save module"
print save()
The contents of save.py:
def save():
AdminConfig.save()
return "Save Complete"
Execution:
wsadmin.bat -lang jython -f C:/TEMP/CreateVirtualHost.py
Note: the "-lang jython" is only needed if jacl is the default
language |
|
|