mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-04-22 10:21:29 -07:00
fix get_resource_limit to work with MariaDB and MySQL
I was getting KeyError 0
This commit is contained in:
parent
089e1c3fb1
commit
248b30cad6
1 changed files with 24 additions and 21 deletions
|
@ -763,7 +763,7 @@ def convert_priv_dict_to_str(priv):
|
||||||
return '/'.join(priv_list)
|
return '/'.join(priv_list)
|
||||||
|
|
||||||
|
|
||||||
def get_resource_limits(cursor, user, host):
|
def get_resource_limits(module, cursor, user, host):
|
||||||
"""Get user resource limits.
|
"""Get user resource limits.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -774,33 +774,36 @@ def get_resource_limits(cursor, user, host):
|
||||||
Returns: Dictionary containing current resource limits.
|
Returns: Dictionary containing current resource limits.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
srv_type = get_server_type(cursor)
|
||||||
|
if srv_type == 'mysql':
|
||||||
query = ('SELECT max_questions AS MAX_QUERIES_PER_HOUR, '
|
query = ('SELECT max_questions AS MAX_QUERIES_PER_HOUR, '
|
||||||
'max_updates AS MAX_UPDATES_PER_HOUR, '
|
'max_updates AS MAX_UPDATES_PER_HOUR, '
|
||||||
'max_connections AS MAX_CONNECTIONS_PER_HOUR, '
|
'max_connections AS MAX_CONNECTIONS_PER_HOUR, '
|
||||||
'max_user_connections AS MAX_USER_CONNECTIONS '
|
'max_user_connections AS MAX_USER_CONNECTIONS '
|
||||||
'FROM mysql.user WHERE User = %s AND Host = %s')
|
'FROM mysql.user WHERE User = %s AND Host = %s')
|
||||||
|
elif srv_type == 'mariadb':
|
||||||
|
query = ('SELECT max_questions AS MAX_QUERIES_PER_HOUR, '
|
||||||
|
'max_updates AS MAX_UPDATES_PER_HOUR, '
|
||||||
|
'max_connections AS MAX_CONNECTIONS_PER_HOUR, '
|
||||||
|
'max_user_connections AS MAX_USER_CONNECTIONS '
|
||||||
|
'max_statement_time AS MAX_STATEMENT_TIME '
|
||||||
|
'FROM mysql.user WHERE User = %s AND Host = %s')
|
||||||
|
else:
|
||||||
|
msg = "Error detecting if the server is MariaDB or MySQL is %s" % srv_type
|
||||||
|
|
||||||
|
module.fail_json(msg=msg)
|
||||||
|
|
||||||
cursor.execute(query, (user, host))
|
cursor.execute(query, (user, host))
|
||||||
res = cursor.fetchone()
|
res = cursor.fetchone()
|
||||||
|
|
||||||
if not res:
|
if not res:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
current_limits = {
|
# If all resources are at zero, then the user as no resources limits
|
||||||
'MAX_QUERIES_PER_HOUR': res[0],
|
if all(value == 0 for value in res.values()):
|
||||||
'MAX_UPDATES_PER_HOUR': res[1],
|
return None
|
||||||
'MAX_CONNECTIONS_PER_HOUR': res[2],
|
|
||||||
'MAX_USER_CONNECTIONS': res[3],
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor.execute("SELECT VERSION()")
|
return res
|
||||||
if 'mariadb' in cursor.fetchone()[0].lower():
|
|
||||||
query = ('SELECT max_statement_time AS MAX_STATEMENT_TIME '
|
|
||||||
'FROM mysql.user WHERE User = %s AND Host = %s')
|
|
||||||
cursor.execute(query, (user, host))
|
|
||||||
res_max_statement_time = cursor.fetchone()
|
|
||||||
current_limits['MAX_STATEMENT_TIME'] = res_max_statement_time[0]
|
|
||||||
|
|
||||||
return current_limits
|
|
||||||
|
|
||||||
|
|
||||||
def match_resource_limits(module, current, desired):
|
def match_resource_limits(module, current, desired):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue