简体   繁体   中英

How to add one config file for my WLST python script

I have one script to check the server status. But instead of hard coding the server details like (username,password,url) I would like to give those configuration details in seperate config file. Could some one help me to create one seperate config file to give these server details. Please let me know how to create and how to add in this python file.

I am running the script in WLST using below command:

java -cp $weblogic_path/weblogic.jar  weblogic.WLST Sever_status.py

Sever_status.py:

try:
    connect('weblogic','Oracle123','https://weblogic.com')
    domainConfig()
    serverList=cmo.getServers();

First, it is a best practice to encrypt user and password instead of storing them in clear text, even in a separate config file. For this purpose use the

storeUserConfig()

method to encrypt and store connection's credentials. Next, use the generated file when connecting to the server.

Read this documentation for details: https://docs.oracle.com/cd/E23943_01/web.1111/e13813/reference.htm#i1064674

You can define variables in an external property file and use them in your wlst script :

import ConfigParser ... conf = ConfigParser.ConfigParser()
conf.read(PATH TO YOUR PROPERTIES FILE)

to read a property :

val = conf.get("property name")

@Emmanuel

I am writing a script to stop/start all the domain using WLST based on config file.

#!/path/to/wlst/sh
import time, getopt, sys, re, os, datetime
from configparser import ConfigParser

config_parser = configparser.ConfigParser()
config_parser.read('path/to/file')


Problem invoking WLST - Traceback (innermost last):
File "/oas/oraamp/wlst/ampMdw.py", line 5, in ?
ImportError: no module named configparser

THe configParser is installed, I ran as python script and not wlst, it works.

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