My guess is that you've developed your script on Windows, then you run it on UNIX/Linux. Hence, .split('\r\n')
which works fine on Windows, doesn't split lines. With .splitlines()
your script would be more portable, you don't have to bother with '\n'
vs '\r\n'
then.
BTW: There's a quicker way of finding the right provider via AdminConfig.getid
:
# getid will return only JDBCProviders with specified name
# then splitlines will return an array of matched objects
# finally [0] will get the first item
db2provider = AdminConfig.getid('/JDBCProvider:%s/' % providerName).splitlines()[0]
if db2provider:
dsAttrs = [['name', 'myDS1'], ['jndiName','jdbc/MY/DS1']]
newDs = AdminConfig.create('DataSource', db2provider, dsAttrs)
else:
print 'JDBCProvider not found'
Same script with WDR library (http://wdr.github.io/WDR/):
# getid1 will return single JDBCProvider1 or fail
db2provider = getid1('/JDBCProvider:%s/' % providerName)
newDs = db2provider.create('DataSource', name = 'myDS1', jndiName = 'jdbc/MY/DS1')
Or even better (idempotent):
# getid1 will return single JDBCProvider1 or fail
db2provider = getid1('/JDBCProvider:%s/' % providerName)
ds = db2provider.assure('DataSource', {'name': 'myDS1'}, jndiName = 'jdbc/MY/DS1')
Confession: I'm one of WDR contributors.