Im trying to get the string value name of the first cluster of a datasource in wlst
cd("/JDBCSystemResources/<datasource name>")
targets = get('Targets')
mytarget = targets[0]
This works fine. If I use a viewMBean command "viewMBean(mytarget)" I can see the Name as the attribute "Name"
If I print the value mytarget I get something like: "com.bea:Name=Cluster-1,Type=Cluster"
But I cannot work out how to get the name ("Cluster-1" in the example above)
At the moment I can't think of anything to do other than getting the cluster name as a substring of the string representation of the object, which doesn't sound like the thing to do
Any help appreciated.
Update:
With no answers so far I'm using this solution, but still hoping for a better one
# get the target cluster from the string "com.bea:Name=<clustername>,Type=Cluster"
if len(targets) == 1 :
tstring = str(targets[0])
targetCluster = tstring[13:tstring.find(",Type=Cluster")]
print "targetCluster = "+targetCluster;
else :
raise Exception("Expected single target cluster for datasource. Targets length was "+str(len(targets)))
you can just say targets[0].getName()
worked for me :)