The task is to modify namespace binding using wsadmin (Jython). I have several string bindings for scope server. I plan to list existing bindings; add / modify target binding.
I can list them:
for ns in AdminConfig.list( 'NameSpaceBinding' ).splitlines() :
name = AdminConfig.showAttribute( ns, 'name' )
stringToBind = AdminConfig.showAttribute( ns, 'stringToBind' )
print '%s="%s"' % ( name, stringToBind )
I can create a new one:
server1 = AdminConfig.list('Server')
print AdminConfig.create('StringNameSpaceBinding', server1, [['name', 'binding2'], ['nameInNameSpace', 'myBindings/myString'], ['stringToBind', "This is the String value"]])
AdminConfig.save()
I guess it can be done with AdminConfig.modify and AdminConfig.remove. Links:
I manage to do it myself. I'm not experienced in Jython, but it works. Script requires 4 parameters: target server for scope, binding name, binding value and name in name space:
server = sys.argv[0]
bindingName = sys.argv[1]
bindingValue = sys.argv[2]
bindingNameSpace = sys.argv[3]
# Obtain the "simple" server name
def getServerName(s):
return AdminConfig.showAttribute(s, 'name')
# Add binding
def addBindingsToServer(s):
for ns in AdminConfig.list( 'NameSpaceBinding' ).splitlines() :
if bindingName == AdminConfig.showAttribute( ns, 'name' ):
print "Removing existing binding from Server %s" % getServerName(s)
AdminConfig.remove(ns)
# Create binding
print "Adding binding to Server %s" % getServerName(s)
print AdminConfig.create('StringNameSpaceBinding', s, [['name', bindingName], ['nameInNameSpace', bindingNameSpace], ['stringToBind', bindingValue]])
# Set server and call function
server = AdminConfig.getid('/Server:'+server+'/')
addBindingsToServer(server)
# Save changes
if (AdminConfig.hasChanges()):
AdminConfig.save()