Created
March 24, 2016 16:10
-
-
Save jamesdmorgan/6c8a0ff6c698a7400dcd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Filters for retrieving jdbc information | |
# | |
# https://www.ibm.com/support/knowledgecenter/SSGU8G_12.1.0/com.ibm.jdbc_pg.doc/ids_jdbc_036.htm?lang=en | |
# | |
# >>-jdbc:informix-sqli://-hostname:portnum--/database_name:------> | |
# >--+--------------------------------+---------------------------> | |
# '-USER=userid;-PASSWORD=password-' | |
# >--+----------------------------+-------------------------------> | |
# '-INFORMIXSERVER=servername;-' | |
# >--+-----------------------------------------------------------+->< | |
# | .-;-----------. | | |
# | V | | | |
# '-CSM=(SSO=database_server@realm,ENC=true)}---;name=value-+-' | |
# | |
# | |
# If the informix connection manager is enabled the format of the connection | |
# string should be based on | |
# https://www.ibm.com/support/knowledgecenter/SSGU8G_12.1.0/com.ibm.jdbc_pg.doc/ids_jdbc_048.htm | |
# | |
# jdbc:informix-sqli://INFORMIXSERVER=sla_primary; | |
# SQLH_TYPE=FILE;SQLH_FILE=sqlhosts; | |
# USER=my_user_name;PASSWORD=my_password; | |
# INFORMIXCONRETRY=2;INFORMIXCONTIME=10;LOGINTIMEOUT=10 | |
import re | |
from ansible.callbacks import display | |
def ob_jdbc_informix_driver(d,host, user=None, password=None,database=None): | |
''' | |
Build Informix JDBC Driver connection string | |
''' | |
conn_dict = {} | |
conn_string = "jdbc:informix-sqli://" | |
inv_dict = d[host] | |
informix_cm_enabled = inv_dict.get("informix_cm_enabled",False) | |
informix_client_dir = inv_dict.get("informix_client_dir","/opt/informix_client_3.70") | |
informix_server_string = "INFORMIXSERVER="+inv_dict.get("informix_server_name_tcp","") | |
if user is None: | |
user = inv_dict.get("informix_database_user","") | |
if password is None: | |
password = inv_dict.get("informix_database_password","") | |
if database is None: | |
database = inv_dict.get("informix_database","undefined") | |
if user.strip() != "": | |
conn_dict['USER'] = user | |
if password.strip() != "": | |
conn_dict['PASSWORD'] = password | |
conn_dict['IFX_LOCK_MODE_WAIT'] = inv_dict.get("jdbc_wait_time",20) | |
if informix_cm_enabled == True: | |
conn_dict['SQLH_TYPE'] = inv_dict.get("jdbc_sqlh_type","FILE") | |
conn_dict['SQLH_FILE'] = inv_dict.get("informix_client_sqlhosts_file",informix_client_dir+"/etc/hosts") | |
conn_dict['INFORMIXCONRETRY'] = inv_dict.get("jdbc_conn_retry",2) | |
conn_dict['INFORMIXCONTIME'] = inv_dict.get("jdbc_conn_time",10) | |
conn_dict['LOGINTIMEOUT'] = inv_dict.get("jdbc_login_timeout",10) | |
conn_string += "%s:%s;" % (database,informix_server_string) | |
else: | |
# Example non-connection manager string | |
# jdbc:informix-sqli://{{ cas_informix_server_host }}:{{ cas_informix_server_port }}/{{ cas_informix_database }}:INFORMIXSERVER={{ cas_informix_server_name_tcp }} | |
informix_server_host = inv_dict.get("informix_server_host","localhost") | |
informix_server_port = inv_dict.get("informix_server_port",1924) | |
conn_string += "%s:%s/%s:%s;" % (informix_server_host,informix_server_port,database,informix_server_string) | |
# Append all connection dictionary keys | |
conn_string += ';'.join("%s=%r" % (key,val) for (key,val) in sorted(conn_dict.iteritems())) | |
return conn_string+';' | |
class FilterModule(object): | |
def filters(self): | |
return { | |
'ob_jdbc_informix_driver': ob_jdbc_informix_driver, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment