First python script to list server in websphere

Hi All,

This is my frist python script working on... I would like to list the servers or cluster from websphere. The script contents are below...
run by cmd - wsadmin.bat -lang jython -F listServers.py
Error -
WASX7209I: Connected to process "dmgr" on node dmgrNode using SOAP connector;  The type of process is: DeploymentManager
WASX7017E: Exception received while running file "listServers.py"; exception information: com.ibm.bsf.BSFException: exception from Jython:
Traceback (most recent call last):
  File "<string>", line 13, in <module>
ValueError: call stack is not deep enough

Content of the script - this example got from - C:\IBM\WebSphere\AppServer\scriptLibraries\servers\V70

#--------------------------------------------------------------------
# Set global constants
#--------------------------------------------------------------------
import sys
import java
import AdminUtilities

# Setting up Global Variable within this script
bundleName = "com.ibm.ws.scripting.resources.scriptLibraryMessage"
resourceBundle = AdminUtilities.getResourceBundle(bundleName)

# Retrieve scripting objects from local name space
AdminConfig = sys._getframe(1).f_locals['AdminConfig']
AdminApp = sys._getframe(1).f_locals['AdminApp']
AdminControl = sys._getframe(1).f_locals['AdminControl']
AdminTask = sys._getframe(1).f_locals['AdminTask']
Help = sys._getframe(1).f_locals['Help']    


## Example 1 List available servers with given server type and node ##
def listServers(serverType="", nodeName="", failonerror=AdminUtilities._BLANK_):
    if (failonerror==AdminUtilities._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.listServers(\""+serverType+"\", \""+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:appNode1" +nodeName+"/")
            if (len(node) == 0):
               raise AttributeError(AdminUtilities._formatNLS(resourceBundle, "WASL6040E", ["nodeName", nodeName]))
            #endIf
            optionalParamList = optionalParamList + ['-nodeName', nodeName]
        #endIf

        # List servers with specified server type
        servers = AdminTask.listServers(optionalParamList)

        # Convert Jython string to list
        servers = AdminUtilities.convertToList(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("nodes/")+6:aServer.find("servers/")-1]
            # Retrieve the server config id
            sid = AdminConfig.getid("/Node:appNode1"+nname+"/Server:"+sname)
            # convert unicode string to normal string
            sid = str(sid)
            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 Exception("ScriptLibraryException: " + val)
            return -1
        else:
            return AdminUtilities.fail(msgPrefix+AdminUtilities.getExceptionText(typ, val, tb), failonerror)
        #endIf
    #endTry
    AdminUtilities.infoNotice(AdminUtilities._OK_+msgPrefix)
#endDef

Thanks
Aarif
Mohammed Aarif ShaikhAsked:
Who is Participating?
 
CEHJCommented:
I don't get it. Why are you running Python on a Java application server?
0
All Courses

From novice to tech pro — start learning today.