任务是使用wsadmin(Jython)修改名称空间绑定。 我有几个针对作用域服务器的字符串绑定。我打算列出现有的绑定;添加/修改目标绑定。
我可以列出它们:
for ns in AdminConfig.list( 'NameSpaceBinding' ).splitlines() :
name = AdminConfig.showAttribute( ns, 'name' )
stringToBind = AdminConfig.showAttribute( ns, 'stringToBind' )
print '%s="%s"' % ( name, stringToBind )
我可以创建一个新的:
server1 = AdminConfig.list('Server')
print AdminConfig.create('StringNameSpaceBinding', server1, [['name', 'binding2'], ['nameInNameSpace', 'myBindings/myString'], ['stringToBind', "This is the String value"]])
AdminConfig.save()
我想可以使用AdminConfig.modify和AdminConfig.remove来完成。 链接:
答案 0 :(得分:2)
我设法自己做。我没有Jython的经验,但它确实有效。脚本需要4个参数:作用域的目标服务器,绑定名称,绑定值和名称空间中的名称:
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()