#!/usr/bin/python
# Script Name: oracleDataSourceCreate.py
# Author: Ty Lim
# Date: 06/30/2016
# Description: Thi is a simple script that will generate an XML stub for a WebSphere Liberty JVM's server.xml file.
"""
Sample Usage and Output:
./oracleGenerateDataSource.py
Application Name: appname
JNDI Name: jdbc/test
DB Server Name: dbserver
DB Port: 1521
DB Name: dbname
User: user
Password: thisismypassw0rd
{xor}Kzc2LDYsMiYvPiwsKG8tOw==
--------- CUT BELOW THIS LINE ---------
--------- CUT ABOVE THIS LINE ---------
"""
import subprocess
def inputOracleParam():
"""Input all the required Oracle Parameters
for the XML stub.
"""
# Input Appication Name
appName=raw_input('Application Name: ')
# Input JNDI
jndi=raw_input('JNDI Name: ')
# Input Server
server = raw_input('DB Server Name: ')
# Input Port
port = raw_input('DB Port: ')
# Input DB Name
db = raw_input('DB Name: ')
# Input user
user = raw_input('User: ')
# Input Password
password = raw_input('Password: ')
return appName, jndi, server, port, db, user, password
def createXML(appName, jndi, server, port, db, user, password):
comment1="\n"
ds1="\n"
ds2="\t\n"
ds3="\t\n"
ds4="\n"
comment2="\n"
return comment1+ds1+ds2+ds3+ds4+comment2
def generateOutput(datasource):
print "--------- CUT BELOW THIS LINE ---------\n"
print datasource
print "--------- CUT ABOVE THIS LINE ---------\n"
def encodePassword(password):
# Path to securityUtility
secUtilityPath="/opt/IBM/WebSphere/Liberty/bin/securityUtility "
secUtilityParam1="encode "
secUtilityParam2=" --notrim"
cmd=secUtilityPath+secUtilityParam1+password+secUtilityParam2
encodedPassword = subprocess.check_output(cmd, shell=True)
return encodedPassword.rstrip("\n")
def main():
appName, jndi, server, port, db, user, password = inputOracleParam()
encodedPassword = encodePassword(password)
datasource = createXML(appName, jndi, server, port, db, user, encodedPassword)
generateOutput(datasource)
if __name__ == '__main__':
main()