mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Return an empty dict instead of 'None' from grafana4 states
Fixes #46985
This commit is contained in:
parent
5b7544eaa0
commit
6c8c3da74d
4 changed files with 137 additions and 3 deletions
|
@ -163,7 +163,7 @@ def present(name,
|
|||
datasource[key] = None
|
||||
|
||||
if data == datasource:
|
||||
ret['changes'] = None
|
||||
ret['changes'] = {}
|
||||
ret['comment'] = 'Data source {0} already up-to-date'.format(name)
|
||||
return ret
|
||||
|
||||
|
|
|
@ -187,7 +187,7 @@ def present(name,
|
|||
if ret['changes']:
|
||||
ret['comment'] = 'Org {0} updated'.format(name)
|
||||
else:
|
||||
ret['changes'] = None
|
||||
ret['changes'] = {}
|
||||
ret['comment'] = 'Org {0} already up-to-date'.format(name)
|
||||
|
||||
return ret
|
||||
|
|
|
@ -124,7 +124,7 @@ def present(name,
|
|||
if ret['changes']:
|
||||
ret['comment'] = 'User {0} updated'.format(name)
|
||||
else:
|
||||
ret['changes'] = None
|
||||
ret['changes'] = {}
|
||||
ret['comment'] = 'User {0} already up-to-date'.format(name)
|
||||
|
||||
return ret
|
||||
|
|
134
salt/states/influxdb_retention_policy.py.dist
Normal file
134
salt/states/influxdb_retention_policy.py.dist
Normal file
|
@ -0,0 +1,134 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Management of Influxdb retention policies
|
||||
=========================================
|
||||
|
||||
.. versionadded:: 2017.7.0
|
||||
|
||||
(compatible with InfluxDB version 0.9+)
|
||||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Only load if the influxdb module is available
|
||||
'''
|
||||
if 'influxdb.db_exists' in __salt__:
|
||||
return 'influxdb_retention_policy'
|
||||
return False
|
||||
|
||||
|
||||
def present(name, database, duration="7d",
|
||||
replication=1, default=False,
|
||||
**client_args):
|
||||
'''
|
||||
Ensure that given retention policy is present.
|
||||
|
||||
name
|
||||
Name of the retention policy to create.
|
||||
|
||||
database
|
||||
Database to create retention policy on.
|
||||
'''
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': 'retention policy {0} is already present'.format(name)}
|
||||
|
||||
if not __salt__['influxdb.retention_policy_exists'](name=name,
|
||||
database=database,
|
||||
**client_args):
|
||||
if __opts__['test']:
|
||||
ret['result'] = None
|
||||
ret['comment'] = ' {0} is absent and will be created'\
|
||||
.format(name)
|
||||
return ret
|
||||
if __salt__['influxdb.create_retention_policy'](
|
||||
database, name,
|
||||
duration, replication, default, **client_args
|
||||
):
|
||||
ret['comment'] = 'retention policy {0} has been created'\
|
||||
.format(name)
|
||||
ret['changes'][name] = 'Present'
|
||||
return ret
|
||||
else:
|
||||
ret['comment'] = 'Failed to create retention policy {0}'\
|
||||
.format(name)
|
||||
ret['result'] = False
|
||||
return ret
|
||||
|
||||
else:
|
||||
current_policy = __salt__['influxdb.get_retention_policy'](database=database, name=name)
|
||||
update_policy = False
|
||||
if current_policy['duration'] != convert_duration(duration):
|
||||
update_policy = True
|
||||
ret['changes']['duration'] = "Retention changed from {0} to {1}.".format(current_policy['duration'],duration)
|
||||
|
||||
if current_policy['replicaN'] != replication:
|
||||
update_policy = True
|
||||
ret['changes']['replication'] = "Replication changed from {0} to {1}.".format(current_policy['replicaN'],replication)
|
||||
|
||||
if current_policy['default'] != default:
|
||||
update_policy = True
|
||||
ret['changes']['default'] = "Default changed from {0} to {1}.".format(current_policy['default'],default)
|
||||
|
||||
if update_policy:
|
||||
if __opts__['test']:
|
||||
ret['result'] = None
|
||||
ret['comment'] = ' {0} is present and set to be changed'\
|
||||
.format(name)
|
||||
return ret
|
||||
else:
|
||||
if __salt__['influxdb.alter_retention_policy'](
|
||||
database, name,
|
||||
duration, replication, default, **client_args
|
||||
):
|
||||
ret['comment'] = 'retention policy {0} has been changed'\
|
||||
.format(name)
|
||||
return ret
|
||||
else:
|
||||
ret['comment'] = 'Failed to update retention policy {0}'\
|
||||
.format(name)
|
||||
ret['result'] = False
|
||||
return ret
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
def absent(name, database, **client_args):
|
||||
'''
|
||||
Ensure that given retention policy is absent.
|
||||
|
||||
name
|
||||
Name of the retention policy to remove.
|
||||
|
||||
database
|
||||
Name of the database that the retention policy was defined on.
|
||||
'''
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': 'retention policy {0} is not present'.format(name)}
|
||||
|
||||
if __salt__['influxdb.retention_policy_exists'](database, name, **client_args):
|
||||
if __opts__['test']:
|
||||
ret['result'] = None
|
||||
ret['comment'] = (
|
||||
'retention policy {0} is present and needs to be removed'
|
||||
).format(name)
|
||||
return ret
|
||||
if __salt__['influxdb.drop_retention_policy'](database, name, **client_args):
|
||||
ret['comment'] = 'retention policy {0} has been removed'\
|
||||
.format(name)
|
||||
ret['changes'][name] = 'Absent'
|
||||
return ret
|
||||
else:
|
||||
ret['comment'] = 'Failed to remove retention policy {0}'\
|
||||
.format(name)
|
||||
ret['result'] = False
|
||||
return ret
|
||||
|
||||
return ret
|
Loading…
Add table
Reference in a new issue