Fixed problem with pymongo compatibility (#1249)
* Fixed problem with pymongo compatibility Fixes #11
This commit is contained in:
parent
020379b0dc
commit
8263dd18a9
1 changed files with 13 additions and 2 deletions
|
@ -159,6 +159,17 @@ else:
|
||||||
# MongoDB module specific support methods.
|
# MongoDB module specific support methods.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
def check_compatibility(module, client):
|
||||||
|
srv_info = client.server_info()
|
||||||
|
if LooseVersion(srv_info['version']) >= LooseVersion('3.2') and LooseVersion(PyMongoVersion) <= LooseVersion('3.2'):
|
||||||
|
module.fail_json(msg=' (Note: you must use pymongo 3.2+ with MongoDB >= 3.2)')
|
||||||
|
elif LooseVersion(srv_info['version']) >= LooseVersion('3.0') and LooseVersion(PyMongoVersion) <= LooseVersion('2.8'):
|
||||||
|
module.fail_json(msg=' (Note: you must use pymongo 2.8+ with MongoDB 3.0)')
|
||||||
|
elif LooseVersion(srv_info['version']) >= LooseVersion('2.6') and LooseVersion(PyMongoVersion) <= LooseVersion('2.7'):
|
||||||
|
module.fail_json(msg=' (Note: you must use pymongo 2.7+ with MongoDB 2.6)')
|
||||||
|
elif LooseVersion(PyMongoVersion) <= LooseVersion('2.5'):
|
||||||
|
module.fail_json(msg=' (Note: you must be on mongodb 2.4+ and pymongo 2.5+ to use the roles param)')
|
||||||
|
|
||||||
def user_find(client, user, db_name):
|
def user_find(client, user, db_name):
|
||||||
for mongo_user in client["admin"].system.users.find():
|
for mongo_user in client["admin"].system.users.find():
|
||||||
if mongo_user['user'] == user and mongo_user['db'] == db_name:
|
if mongo_user['user'] == user and mongo_user['db'] == db_name:
|
||||||
|
@ -177,8 +188,6 @@ def user_add(module, client, db_name, user, password, roles):
|
||||||
db.add_user(user, password, None, roles=roles)
|
db.add_user(user, password, None, roles=roles)
|
||||||
except OperationFailure, e:
|
except OperationFailure, e:
|
||||||
err_msg = str(e)
|
err_msg = str(e)
|
||||||
if LooseVersion(PyMongoVersion) <= LooseVersion('2.5'):
|
|
||||||
err_msg = err_msg + ' (Note: you must be on mongodb 2.4+ and pymongo 2.5+ to use the roles param)'
|
|
||||||
module.fail_json(msg=err_msg)
|
module.fail_json(msg=err_msg)
|
||||||
|
|
||||||
def user_remove(module, client, db_name, user):
|
def user_remove(module, client, db_name, user):
|
||||||
|
@ -309,6 +318,8 @@ def main():
|
||||||
except ConnectionFailure, e:
|
except ConnectionFailure, e:
|
||||||
module.fail_json(msg='unable to connect to database: %s' % str(e))
|
module.fail_json(msg='unable to connect to database: %s' % str(e))
|
||||||
|
|
||||||
|
check_compatibility(module, client)
|
||||||
|
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
if password is None and update_password == 'always':
|
if password is None and update_password == 'always':
|
||||||
module.fail_json(msg='password parameter required when adding a user unless update_password is set to on_create')
|
module.fail_json(msg='password parameter required when adding a user unless update_password is set to on_create')
|
||||||
|
|
Loading…
Reference in a new issue