The problem is that if the application is "stopped" this will return nothing. But i still want to uninstall it anyway. I don't know the application name, i'm getting all applications installed on a Server and then uninstalling them all.
apps = AdminControl.queryNames('type=Application,node=' + nodeName + ',process=' + serverName + ',*').split()
Here is my code.
serverObj = AdminControl.completeObjectName('type=Server,node=%s,name=%s,*' % (nodeName, serverName))
serverID = AdminConfig.getid('/Node:%s/Server:%s/' % (nodeName, serverName))
if serverID == "":
print "Can't find the server, exiting..."
sys.exit(1)
else:
cellName = AdminControl.getAttribute(serverObj, 'cellName')
#Uninstall Apps
apps = AdminControl.queryNames('type=Application,node=' + nodeName + ',process=' + serverName + ',*').split()
appManager=AdminControl.queryNames('type=ApplicationManager,node=' + nodeName + ',process=,*')
if len(apps) > 0:
for app in apps:
appName = AdminControl.getAttribute(app, 'name')
AdminControl.invoke(appManager,'stopApplication', appName)
print "Uninstalling application: " + appName
AdminApp.uninstall(appName)
else:
print "No applications to uninstall"
You can use the below snippet to uninstall all Apps deployed on the target server:
#Get the list of all Apps deployed in target server
installedApps=AdminApp.list("WebSphere:cell=%s,node=%s,server=%s" % (cellName, nodeName, serverName))
#Check if there are any installed Apps on the server
if len (installedApps) > 0:
#if there are installed Apps, iterate through the list and uninstall Apps one by one
for app in installedApps.splitlines():
print "uninstalling "+ app +" ...."
AdminApp.uninstall(app)
#Save the changes
AdminConfig.save()
else:
#if there are no installed Apps, do nothing
print "No applications to uninstall"