简体   繁体   中英

Dynamically change variables in WLST script

I'm creating a bunch of .py WLST scripts (15-20) which will each check a different setting in a Weblogic environment. For example, password requirements, security settings, user properties etc.

However, I want to run these scripts in a number of WebLogic environments, all having different host URLs and credentials. Is there an easy way to dynamically change the connection details for each script as they are run in different environments:

script:

connect(x,y,z)

script in env 1:

connect('weblogic','welcome1','example-host1:7001')

script in env 2:

connect('weblogic','welcome2','example-host1:7001')

This is my first occasion asking a question on stackoverflow after using it as a source for the first couple of years of my career, so apologies if this issue is described poorly.

Simple Answer would be . Keep Environment related properties in the property file . And read those properties using Python (Jython)

from java.io import FileInputStream

propInputStream = FileInputStream("preprodenv.properties") 
configProps = Properties()
configProps.load(propInputStream)

adminHost=configProps.get("admin.host)
adminPort=configProps.get("admin.port")
adminUserName=configProps.get("admin.userName")
adminPassword=configProps.get("admin.password")

# t3 or t3s depends upon your config
adminURL = "t3://"+adminHost+":"+adminPort
connect(adminUserName, adminPassword, adminURL)

Option#2

Keep the environment related information in properties and read using

loadProperties('c:/temp/myLoad.properties')

or pass it as argument to your wlst script -loadProperties='C:\\temp\\myLoad.properties'

Anything would work.

I am assuming that the hostnames will be different in different environments. The way we do this is by creating an "env shell script" which contains a mapping using simple case statements. We then create a wrapper script that iterates over various environments in the "env shell script". Does this help or do you need more details ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM