Using functions from wsadminlib.py is the easiest option, as pointed out by covener. It comes with a host of other util functions as well.
However, if you don't want to use wsadminlib.py in your project and is looking for a quick solution, below snippet would work:
#Define the app name here or pass it as input
appName='DUMMY_APP_NAME'
#Get the app deployment ID
depId = AdminConfig.getid('/Deployment:%s/' % ( appName ))
#Get the deployment target details and convert it to a list
depTargetList = AdminUtilities.convertToList(AdminConfig.showAttribute(depId, 'deploymentTargets'))
#iterate the list and find the target details and print the result
for depTarget in depTargetList:
targetName = AdminConfig.showAttribute(depTarget, 'name')
print 'App %s is deployed to %s' %(appName, targetName)
#end for
You may further refine the result by checking if the target is a cluster or a server as given below:
for depTarget in depTargetList:
targetName = AdminConfig.showAttribute(depTarget, 'name')
if depTarget.find('ClusteredTarget') != -1:
targetType = 'Cluster'
else:
targetType = 'Server'
#end if
print 'App %s is deployed to %s: %s' %(appName, targetType, targetName)
#end for