WAS
asked on
jython script for list servers
i have a WAS7.0.0.21 ND on a linux machine, i got below script from the was_root/scriptLibraries/s ervers/V70 /AdminServ erManageme nt.py , so when i run this python script i get no output and it wsadmin tool just brings back to prompt, please help me what i need to do in order to get list of servers, why this script is not working, what else i need to provide in order it to work
########################## ########## ########## #######
#------------------------- ---------- ---------- ---------- ---------- ---
# Set global constants
#------------------------- ---------- ---------- ---------- ---------- ---
import sys
import java
import AdminUtilities
# Setting up Global Variable within this script
bundleName = "com.ibm.ws.scripting.reso urces.scri ptLibraryM essage"
resourceBundle = AdminUtilities.getResource Bundle(bun dleName)
## Example 1 List available servers with given server type and node ##
def listServers(serverType="AP PLICATION_ SERVER", nodeName="abe12", failonerror=AdminUtilities ._BLANK_):
if (failonerror==AdminUtiliti es._BLANK_ ):
failonerror=AdminUtilities ._FAIL_ON_ ERROR_
#endIf
msgPrefix = "listServers("+`serverType `+", "+`nodeName`+", "+`failonerror`+"): "
try:
#------------------------- ---------- ---------- ---------- ---------- ---
# List servers
#------------------------- ---------- ---------- ---------- ---------- ---
print "------------------------- ---------- ---------- ---------- --------"
print " AdminServerManagement: List servers"
print " Optional parameters: "
print " Server type: "+serverType
print " Node name: "+nodeName
print " Usage: AdminServerManagement.list Servers(\" "+serverTy pe+"\", \""+nodeName+"\") "
print " Return: List of the servers in the cell. The list is filtered based on the server type and node name parameters if they are provided."
print "------------------------- ---------- ---------- ---------- --------"
print " "
print " "
# Construct optional parameters
optionalParamList = []
if (len(serverType) > 0):
optionalParamList = ['-serverType', serverType]
if (len(nodeName) > 0):
# check if node exists
node = AdminConfig.getid("/Node:" +nodeName+"/")
if (len(node) == 0):
raise AttributeError(AdminUtilit ies._forma tNLS(resou rceBundle, "WASL6040E", ["nodeName", nodeName]))
#endIf
optionalParamList = optionalParamList + ['-nodeName', nodeName]
#endIf
optionalParamList = optionalParamList + ['-nodeName', nodeName]
#endIf
# List servers with specified server type
servers = AdminTask.listServers(opti onalParamL ist)
# Convert Jython string to list
servers = AdminUtilities.convertToLi st(servers )
# Loop through each server in server list
newservers = []
for aServer in servers:
# Obtain server and node names
sname = aServer[0:aServer.find("(" )]
nname = aServer[aServer.find("node s/")+6:aSe rver.find( "servers/" )-1]
# Retrieve the server config id
sid = AdminConfig.getid("/Node:" +nname+"/S erver:"+sn ame)
if (newservers.count(sid) <= 0):
newservers.append(sid)
#AdminUtilities.infoNotice ("Server: " + sid)
#endFor
return newservers
except:
typ, val, tb = sys.exc_info()
if (typ==SystemExit): raise SystemExit,`val`
if (failonerror != AdminUtilities._TRUE_):
print "Exception: %s %s " % (sys.exc_type, sys.exc_value)
val = "%s %s" % (sys.exc_type, sys.exc_value)
raise "ScriptLibraryException: ", `val`
return -1
else:
return AdminUtilities.fail(msgPre fix+AdminU tilities.g etExceptio nText(typ, val, tb), failonerror)
#endIf
#endTry
AdminUtilities.infoNotice( AdminUtili ties._OK_+ msgPrefix)
#endDef
##########################
#-------------------------
# Set global constants
#-------------------------
import sys
import java
import AdminUtilities
# Setting up Global Variable within this script
bundleName = "com.ibm.ws.scripting.reso
resourceBundle = AdminUtilities.getResource
## Example 1 List available servers with given server type and node ##
def listServers(serverType="AP
if (failonerror==AdminUtiliti
failonerror=AdminUtilities
#endIf
msgPrefix = "listServers("+`serverType
try:
#-------------------------
# List servers
#-------------------------
print "-------------------------
print " AdminServerManagement: List servers"
print " Optional parameters: "
print " Server type: "+serverType
print " Node name: "+nodeName
print " Usage: AdminServerManagement.list
print " Return: List of the servers in the cell. The list is filtered based on the server type and node name parameters if they are provided."
print "-------------------------
print " "
print " "
# Construct optional parameters
optionalParamList = []
if (len(serverType) > 0):
optionalParamList = ['-serverType', serverType]
if (len(nodeName) > 0):
# check if node exists
node = AdminConfig.getid("/Node:"
if (len(node) == 0):
raise AttributeError(AdminUtilit
#endIf
optionalParamList = optionalParamList + ['-nodeName', nodeName]
#endIf
optionalParamList = optionalParamList + ['-nodeName', nodeName]
#endIf
# List servers with specified server type
servers = AdminTask.listServers(opti
# Convert Jython string to list
servers = AdminUtilities.convertToLi
# Loop through each server in server list
newservers = []
for aServer in servers:
# Obtain server and node names
sname = aServer[0:aServer.find("("
nname = aServer[aServer.find("node
# Retrieve the server config id
sid = AdminConfig.getid("/Node:"
if (newservers.count(sid) <= 0):
newservers.append(sid)
#AdminUtilities.infoNotice
#endFor
return newservers
except:
typ, val, tb = sys.exc_info()
if (typ==SystemExit): raise SystemExit,`val`
if (failonerror != AdminUtilities._TRUE_):
print "Exception: %s %s " % (sys.exc_type, sys.exc_value)
val = "%s %s" % (sys.exc_type, sys.exc_value)
raise "ScriptLibraryException: ", `val`
return -1
else:
return AdminUtilities.fail(msgPre
#endIf
#endTry
AdminUtilities.infoNotice(
#endDef
ASKER
What do you mean by the phrase "I got below script from ..."?
yes i planning to use the sample scripts that came with WAS installations, just experimenting with them, (was_root/scriptLibraries/ servers/V7 0/AdminSer verManagem ent.py).
Did you copy the routine somewhere?
what is routine, i didn't copied any thing except the script from the WAS7 sample scripts
i just want to make this script work for me, if you help me fix this script by telling me what is missing in it, it will be easier for me modify other sample scripts that came with WAS7,
please feel free to ask more question if you didn't understand my goal.
yes i planning to use the sample scripts that came with WAS installations, just experimenting with them, (was_root/scriptLibraries/
Did you copy the routine somewhere?
what is routine, i didn't copied any thing except the script from the WAS7 sample scripts
i just want to make this script work for me, if you help me fix this script by telling me what is missing in it, it will be easier for me modify other sample scripts that came with WAS7,
please feel free to ask more question if you didn't understand my goal.
Are you using a wsadmin interactive session, or do you specify a script file to be executed (i.e., by providing the "-f" command line option)?
Did you modify the script to provide this command parameter?
nodeName="abe12"
Where did that come from?
My AdminServerManagement.py has this as line 99:
Did you modify the script to provide this command parameter?
nodeName="abe12"
Where did that come from?
My AdminServerManagement.py has this as line 99:
def listServers(serverType="", nodeName="", failonerror=AdminUtilities._BLANK_):
ASKER
i am providing the script with -f option and yes i modified this value nodeNAme="abc12" and also the serverType="APPLICATION_SE RVER", initially they are left blank in example script, for me this line is --> def listServers(serverType="AP PLICATION_ SERVER", nodeName="abe12", failonerror=AdminUtilities ._BLANK_): is on line number 13
You shouldn't be modifying the routine.
You should be specifying values when you call the routine, as I showed above...
You should be specifying values when you call the routine, as I showed above...
ASKER
when don't provide anything also i get nothing, basically comes back to prompt
def listServers(serverType="", nodeName="", failonerror=AdminUtilities ._BLANK_):
$ sudo -u webadmin ./wsadmin.sh -f ~/scripts/listservers.py
Realm/Cell Name: <default>
Username: xx31952
Password: WASX7209I: Connected to process "dmgr" on node abc12admgr using SOAP connector; The type of process is: DeploymentManager
$
def listServers(serverType="",
$ sudo -u webadmin ./wsadmin.sh -f ~/scripts/listservers.py
Realm/Cell Name: <default>
Username: xx31952
Password: WASX7209I: Connected to process "dmgr" on node abc12admgr using SOAP connector; The type of process is: DeploymentManager
$
the way you should be calling it is:
$ sudo -u webadmin ./wsadmin.sh -c "AdminServerManagement.lis tServers() "
You have to realize though, that what you get back from this routine is an array / list of the configuration IDs of the configured application servers.
Which say "execute this command" (i.e., the command after the "-c")
The "-f", as you show, is used to execute a script. If you want to, you could create a trivial script file to call this routine, and display more useful information from the results. For example:
/scripts/listservers.py
$ sudo -u webadmin ./wsadmin.sh -c "AdminServerManagement.lis
You have to realize though, that what you get back from this routine is an array / list of the configuration IDs of the configured application servers.
Which say "execute this command" (i.e., the command after the "-c")
The "-f", as you show, is used to execute a script. If you want to, you could create a trivial script file to call this routine, and display more useful information from the results. For example:
/scripts/listservers.py
for server in AdminServerManagement.listServers() :
Type = AdminConfig.showAttribute( server, 'serverType' )
name = AdminConfig.showAttribute( server, 'name' )
print 'ServerType:', Type
print 'ServerName:', name
ASKER
that trivial script is working that was excellent, but can use the usage given in /opt/app/WebSphere7.0.0.21 /AppServer /scriptLib raries/ser vers/V70/A dminServer Management .py script which is
Usage: AdminServerManagement.list Servers(\" "+serverTy pe+"\", \""+nodeName+"\") "
so i used it now i get below error, can you please correct me with this
$ sudo -u webadmin ./wsadmin.sh -c " AdminServerManagement.list Servers(\" "+serverTy pe+"\", \""+nodeName+"\") "
Realm/Cell Name: <default>
Username: webadmin
Password: WASX7209I: Connected to process "dmgr" on node lseth321admgr using SOAP connector; The type of process is: DeploymentManager
-------------------------- ---------- ---------- ---------- -------
AdminServerManagement: List servers
Optional parameters:
Server type: +serverType+
Node name: +nodeName+
Usage: AdminServerManagement.list Servers("+ serverType +", "+nodeName+")
Return: List of the servers in the cell. The list is filtered based on the server type and node name parameters if they are provided.
-------------------------- ---------- ---------- ---------- -------
Exception: exceptions.AttributeError WASL6040E: The nodeName:+nodeName+ specified argument does not exist.
WASX7015E: Exception running command: "AdminServerManagement.lis tServers(" +serverTyp e+", "+nodeName+")"; exception information:
com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
File "<input>", line 1, in ?
File "/opt/app/WebSphere7.0.0.2 1/AppServe r/scriptLi braries/se rvers/V70/ AdminServe rManagemen t.py", line 159, in listServers
ScriptLibraryException: : 'exceptions.AttributeError WASL6040E: The nodeName:+nodeName+ specified argument does not exist.'
$
Usage: AdminServerManagement.list
so i used it now i get below error, can you please correct me with this
$ sudo -u webadmin ./wsadmin.sh -c " AdminServerManagement.list
Realm/Cell Name: <default>
Username: webadmin
Password: WASX7209I: Connected to process "dmgr" on node lseth321admgr using SOAP connector; The type of process is: DeploymentManager
--------------------------
AdminServerManagement: List servers
Optional parameters:
Server type: +serverType+
Node name: +nodeName+
Usage: AdminServerManagement.list
Return: List of the servers in the cell. The list is filtered based on the server type and node name parameters if they are provided.
--------------------------
Exception: exceptions.AttributeError WASL6040E: The nodeName:+nodeName+ specified argument does not exist.
WASX7015E: Exception running command: "AdminServerManagement.lis
com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
File "<input>", line 1, in ?
File "/opt/app/WebSphere7.0.0.2
ScriptLibraryException: : 'exceptions.AttributeError
$
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sure it helped, earlier i was trying without removing special charactors, thank you HonorGod,
You are very welcome.
Thanks for the grade & points.
Good luck & have a great day.
If you are going to be doing much WebSphere Application Server administration using Jython, you may want to take a look at this book:
From IBM Press (publisher): http://www.ibmpressbooks.com/bookstore/product.asp?isbn=0137009526
From Amazon: http://www.amazon.com/dp/0137009526
Thanks for the grade & points.
Good luck & have a great day.
If you are going to be doing much WebSphere Application Server administration using Jython, you may want to take a look at this book:
From IBM Press (publisher): http://www.ibmpressbooks.com/bookstore/product.asp?isbn=0137009526
From Amazon: http://www.amazon.com/dp/0137009526
ASKER
yeah i have that book, but didn't had enough time to learn jython.... i rarely get work on jython...on top i am not good at programming .... trying logic and syntaxs are my hard part, but thanks for advice
You are welcome. If you have other questions, just ask. We'll do what we can to help.
Did you copy the routine somewhere?
I'll need to understand this in order to answer the "why didn't it work" question
- It is important to realize that the AdminServerManagement library is automatically provided to the wsadmin environment (unless, for some reason, you have removed the scriptLibraries directory).
So, to "use" the routine, you only need call the method, using syntax similar to:
Open in new window
By the way, the fact that the routine generates that big banner mean that I don't like it very much.
On the other hand, you don't indicate the kind of information that you want, or the format of how it should be displayed.
If, on the other hand, you only want to list the names of the application servers in your cell, you can do something simple like:
Open in new window