q5p4k0
q5p4k0

Reputation: 51

WLST execute stored variable "connect()" statement

So, I am passing a environment variable from bash to python;

#!/usr/bin/env python2
import os

#connect("weblogic", "weblogic", url=xxx.xxx.xxx.xxx:xxxx)
os.environ['bash_variable']

via wlst.sh I can print exported bash_variable, but how do I execute stored variable? Basically, I am trying to remove the original connect statement and pass a variable that has said information. Thanks

Upvotes: 2

Views: 2688

Answers (1)

Andre Gelinas
Andre Gelinas

Reputation: 912

Question though, why wouldn't you called the script with the variable as an argument and use sys.argv[] ?

By example something like this.

import os
import sys
import traceback
from java.io import *
from java.lang import *




wlDomain = sys.argv[1]
wlDomPath = sys.argv[2]
wlNMHost = sys.argv[3]
wlNMPort = sys.argv[4]
wlDPath="%s/%s" %(wlDomPath,wlDomain)
wlNMprop="/apps/bea/wls/scripts/.shadow/NM.prop"

try:
    print "Connection to Node Manager"
    print ""
    loadProperties(wlNMprop)
    nmConnect(username=NMuser,password=NMpass,host=wlNMHost,port=wlNMPort,domainName=wlDomain,domainDir=wlDPath,mType='ssl',verbose='true')
except:
    print "Fatal Error : No Connection to Node Manager"
    exit()

print "Connected to Node Manager"

The NM.prop file is a 600 file with the username/password for the NM.

EDIT :

So from what I understand you want to do something like this :

URLS = ['t3s://Host1:Port1','t3s://Host2:Port2','t3s://Host3:Port3']
for urls in URLS:
    connect('somebody','password',urls)
    {bunch of commands}
    disconnect()

And the values of the list URLS would be define by the environment.

The way I see it you have 3 choices :

  1. Have 1 script per environment, more or less identical save for the URLS list
  2. Have 1 script but with a conditionnal branching on sys.argv[1] (the environment as a parameter) and create the list there.
  3. Have 1 script which use a parameter file for each environment according to the environment. Each parameter file containing the list in question.

Something like that :

propENV = sys.argv[1]
propPath = "/path1/path2"
propFile = "%s/%s" %(propPath,propENV)

loadProperties(propFile)

I would probably use the properties file option myself as it is more flexible from an operational standpoint...at least IMHO.

Upvotes: 1

Related Questions