Syntax change to make module compatible with Python 2.4

reviewable/pr18780/r1
Pepe Barbe 12 years ago
parent 51e85b4bde
commit 35e27fe1b2

@ -121,13 +121,20 @@ def main():
if not postgresqldb_found: if not postgresqldb_found:
module.fail_json(msg="the python psycopg2 module is required") module.fail_json(msg="the python psycopg2 module is required")
# To use defaults values, keyword arguments must be absent, so
# check which values are empty and don't include in the **kw
# dictionary
params_map = {
"login_host":"host",
"login_user":"user",
"login_password":"password"
}
kw = dict( (params_map[k], v) for (k, v) in module.params.iteritems()
if k in params_map and v != "" )
try: try:
db_connection = psycopg2.connect(host=module.params["login_host"], db_connection = psycopg2.connect(database=db, **kw)
user=module.params["login_user"],
password=module.params["login_password"],
database=db)
cursor = db_connection.cursor() cursor = db_connection.cursor()
except Exception as e: except Exception, e:
module.fail_json(msg="unable to connect to database: %s" % e) module.fail_json(msg="unable to connect to database: %s" % e)
if state == "present": if state == "present":

Loading…
Cancel
Save