Create datasource in weblogic by python script

Hi All,

If you want to create datasources in weblogic manually or through program. You can write a python script and invoke that python script with maven to use this in devops. This is quite common requirment. If you want to setup new environment using maven, this will be really helpful.

Below is follow script used for that

adminUserName='weblogic'
adminPassword='Weblogic1'
adminURL='t3://hostname:port'
databasehost='hostname'


connect(UserName, Password, adminURL)
edit()
startEdit()

cd('/')
cmo.createJDBCSystemResource('techartifactDS')

cd('/JDBCSystemResources/techartifact/JDBCResource/techartifactDS')
cmo.setName('techartifactDS')

cd('/JDBCSystemResources/techartifact/JDBCResource/JDBCDataSourceParams/techartifactDS')
set('JNDINames',jarray.array([String('jdbc/techartifactDS')], String))

cd('/JDBCSystemResources/techartifact/JDBCResource/JDBCDriverParams/techartifactDS')
cmo.setUrl('jdbc:oracle:thin:@' + databasehost + ':1521:xe')
cmo.setDriverName('oracle.jdbc.OracleDriver')
cmo.setPassword('passwordFortechartifactDS')

cd('/JDBCSystemResources/techartifact/JDBCResource/JDBCConnectionPoolParams/techartifactDS')
cmo.setTestTableName('SQL SELECT 1 FROM DUAL\r\n\r\n')

cd('/JDBCSystemResources/techartifact/JDBCResource/JDBCDriverParams/techartifactDS/Properties/techartifact')
cmo.createProperty('user')

cd('/JDBCSystemResources/techartifact/JDBCResource/JDBCDriverParams/techartifactDS/Properties/techartifact/Properties/user')
cmo.setValue('techartifact')

cd('/JDBCSystemResources/techartifact/JDBCResource/JDBCDataSourceParams/techartifactDS')
cmo.setGlobalTransactionsProtocol('OnePhaseCommit')

cd('/SystemResources/techartifact')
set('Targets',jarray.array([ObjectName('com.bea:Name=WCP_PORTAL,Type=Cluster')], ObjectName))

activate()

Happy coding with python with Vinay