WLST 查询(列出已部署的应用程序和主机)

WLST query (List deployed applications and hosts together)

我有两个 WLST 查询。我通过 WebLogic 脚本工具控制台执行它。这些查询是:

1) 已部署应用程序列表和状态:

connect('weblogic','password','t3://localhost:7001')
cd('AppDeployments')
deplymentsList=cmo.getAppDeployments()
for app in deplymentsList:
      domainConfig()
      cd ('/AppDeployments/'+app.getName()+'/Targets')
      mytargets = ls(returnMap='true')
      domainRuntime()
      cd('AppRuntimeStateRuntime')
      cd('AppRuntimeStateRuntime')
      for targetinst in mytargets:
            curstate4=cmo.getCurrentState(app.getName(),targetinst)
            print app.getApplicationName(), targetinst, curstate4;

输出示例:

2) 主机列表

connect('weblogic','password','t3://localhost:7001')     
svrs = cmo.getServers()
domainRuntime()
for host in svrs: 
    machine = host.getMachine();
    print "Host:  " + machine.getName()

输出示例:

我需要获取这两个信息(一个应用程序及其主机或共享主机,如果它们有多个)。我不知道如何解决和混合查询以在一个查询中获取这两个信息,或者至少在第二个查询中获取与部署应用程序相关的信息 - 主机。

所需的输出是这样的:

提前致谢。

聚会有点晚了。但是如果其他人通过搜索答案来我想出了第一个脚本的扩展来给出期望的结果:

connect('weblogic','password','t3://localhost:7001')
setShowLSResult(false)
cd('AppDeployments')
deplymentsList=cmo.getAppDeployments()
domainConfig()
for app in deplymentsList:
    cd ('/AppDeployments/'+app.getName()+'/Targets')
    mytargets = ls(returnMap='true')
    for targetinst in mytargets:
        domainRuntime()
        cd('AppRuntimeStateRuntime')
        cd('AppRuntimeStateRuntime')
        curstate4 = cmo.getCurrentState(app.getName(),targetinst)
        domainConfig()
        cd('/AppDeployments/'+app.getName()+'/Targets/'+targetinst)
        myType = cmo.getType()
        if myType == 'Cluster':
            myServers = cd('/AppDeployments/'+app.getName()+'/Targets/'+targetinst+'/Servers', returnMap='true')
            for server in myServers:
                cd('/AppDeployments/'+app.getName()+'/Targets/'+targetinst+'/Servers/'+server)
                machineName = cmo.getMachine().getName()
                print app.getApplicationName(), targetinst, curstate4, machineName
        elif myType == 'Server':
            cd('/AppDeployments/'+app.getName()+'/Targets/'+targetinst)
            machineName = cmo.getMachine().getName()
            print app.getApplicationName(), targetinst, curstate4, machineName

输出将类似于原始问题中所述的输出。