Merge branch 'develop' into fix-file.absent-inconsistency

This commit is contained in:
Melissa Michels 2017-08-09 13:30:19 -04:00 committed by GitHub
commit cfd1b960d3
4 changed files with 147 additions and 21 deletions

View File

@ -67,6 +67,29 @@ host: ``localhost``
port: ``6379``
The Redis server port.
cluster_mode: ``False``
Whether cluster_mode is enabled or not
cluster.startup_nodes:
A list of host, port dictionaries pointing to cluster members. At least one is required
but multiple nodes are better
.. code-block::yaml
cache.redis.cluster.startup_nodes
- host: redis-member-1
port: 6379
- host: redis-member-2
port: 6379
cluster.skip_full_coverage_check: ``False``
Some cluster providers restrict certain redis commands such as CONFIG for enhanced security.
Set this option to true to skip checks that required advanced privileges.
.. note::
Most cloud hosted redis clusters will require this to be set to ``True``
db: ``'0'``
The database index.
@ -89,6 +112,24 @@ Configuration Example:
cache.redis.bank_keys_prefix: #BANKEYS
cache.redis.key_prefix: #KEY
cache.redis.separator: '@'
Cluster Configuration Example:
.. code-block::yaml
cache.redis.cluster_mode: true
cache.redis.cluster.skip_full_coverage_check: true
cache.redis.cluster.startup_nodes:
- host: redis-member-1
port: 6379
- host: redis-member-2
port: 6379
cache.redis.db: '0'
cache.redis.password: my pass
cache.redis.bank_prefix: #BANK
cache.redis.bank_keys_prefix: #BANKEYS
cache.redis.key_prefix: #KEY
cache.redis.separator: '@'
'''
from __future__ import absolute_import
@ -105,6 +146,12 @@ try:
except ImportError:
HAS_REDIS = False
try:
from rediscluster import StrictRedisCluster
HAS_REDIS_CLUSTER = True
except ImportError:
HAS_REDIS_CLUSTER = False
# Import salt
from salt.ext.six.moves import range
from salt.exceptions import SaltCacheError
@ -135,9 +182,13 @@ REDIS_SERVER = None
def __virtual__():
'''
The redis library must be installed for this module to work.
The redis redis cluster library must be installed if cluster_mode is True
'''
if not HAS_REDIS:
return (False, "Please install the python-redis package.")
if not HAS_REDIS_CLUSTER and _get_redis_cache_opts()['cluster_mode']:
return (False, "Please install the redis-py-cluster package.")
return __virtualname__
@ -154,7 +205,10 @@ def _get_redis_cache_opts():
'host': __opts__.get('cache.redis.host', 'localhost'),
'port': __opts__.get('cache.redis.port', 6379),
'db': __opts__.get('cache.redis.db', '0'),
'password': __opts__.get('cache.redis.password', '')
'password': __opts__.get('cache.redis.password', ''),
'cluster_mode': __opts__.get('cache.redis.cluster_mode', False),
'startup_nodes': __opts__.get('cache.redis.cluster.startup_nodes', {}),
'skip_full_coverage_check': __opts__.get('cache.redis.cluster.skip_full_coverage_check', False),
}
@ -168,10 +222,16 @@ def _get_redis_server(opts=None):
return REDIS_SERVER
if not opts:
opts = _get_redis_cache_opts()
REDIS_SERVER = redis.Redis(opts['host'],
opts['port'],
db=opts['db'],
password=opts['password'])
if opts['cluster_mode']:
REDIS_SERVER = StrictRedisCluster(startup_nodes=opts['startup_nodes'],
skip_full_coverage_check=opts['skip_full_coverage_check'],
decode_responses=True)
else:
REDIS_SERVER = redis.StrictRedis(opts['host'],
opts['port'],
db=opts['db'],
password=opts['password'])
return REDIS_SERVER

View File

@ -1978,6 +1978,8 @@ def acl_create(consul_url=None, **kwargs):
Create a new ACL token.
:param consul_url: The Consul server URL.
:param id: Unique identifier for the ACL to create
leave it blank to let consul server generate one
:param name: Meaningful indicator of the ACL's purpose.
:param type: Type is either client or management. A management
token is comparable to a root user and has the
@ -2008,6 +2010,9 @@ def acl_create(consul_url=None, **kwargs):
else:
raise SaltInvocationError('Required argument "name" is missing.')
if 'id' in kwargs:
data['ID'] = kwargs['id']
if 'type' in kwargs:
data['Type'] = kwargs['type']
@ -2126,7 +2131,7 @@ def acl_delete(consul_url=None, **kwargs):
ret['res'] = False
return ret
function = 'acl/delete/{0}'.format(kwargs['id'])
function = 'acl/destroy/{0}'.format(kwargs['id'])
res = _query(consul_url=consul_url,
data=data,
method='PUT',

View File

@ -12,6 +12,19 @@ config, these are the defaults:
redis.host: 'salt'
redis.port: 6379
Cluster Mode Example:
.. code-block::yaml
redis.db: '0'
redis.cluster_mode: true
redis.cluster.skip_full_coverage_check: true
redis.cluster.startup_nodes:
- host: redis-member-1
port: 6379
- host: redis-member-2
port: 6379
Alternative configuration values can be used by prefacing the configuration.
Any values not found in the alternative configuration will be pulled from
the default location:
@ -44,6 +57,32 @@ To override individual configuration items, append --return_kwargs '{"key:": "va
salt '*' test.ping --return redis --return_kwargs '{"db": "another-salt"}'
Redis Cluster Mode Options:
cluster_mode: ``False``
Whether cluster_mode is enabled or not
cluster.startup_nodes:
A list of host, port dictionaries pointing to cluster members. At least one is required
but multiple nodes are better
.. code-block::yaml
cache.redis.cluster.startup_nodes
- host: redis-member-1
port: 6379
- host: redis-member-2
port: 6379
cluster.skip_full_coverage_check: ``False``
Some cluster providers restrict certain redis commands such as CONFIG for enhanced security.
Set this option to true to skip checks that required advanced privileges.
.. note::
Most cloud hosted redis clusters will require this to be set to ``True``
'''
# Import python libs
@ -66,14 +105,28 @@ except ImportError:
log = logging.getLogger(__name__)
try:
from rediscluster import StrictRedisCluster
HAS_REDIS_CLUSTER = True
except ImportError:
HAS_REDIS_CLUSTER = False
# Define the module's virtual name
__virtualname__ = 'redis'
def __virtual__():
'''
The redis library must be installed for this module to work.
The redis redis cluster library must be installed if cluster_mode is True
'''
if not HAS_REDIS:
return False, 'Could not import redis returner; ' \
'redis python client is not installed.'
if not HAS_REDIS_CLUSTER and _get_options()['cluster_mode']:
return (False, "Please install the redis-py-cluster package.")
return __virtualname__
@ -83,13 +136,20 @@ def _get_options(ret=None):
'''
attrs = {'host': 'host',
'port': 'port',
'db': 'db'}
'db': 'db',
'cluster_mode': 'cluster_mode',
'startup_nodes': 'cluster.startup_nodes',
'skip_full_coverage_check': 'cluster.skip_full_coverage_check',
}
if salt.utils.is_proxy():
return {
'host': __opts__.get('redis.host', 'salt'),
'port': __opts__.get('redis.port', 6379),
'db': __opts__.get('redis.db', '0')
'db': __opts__.get('redis.db', '0'),
'cluster_mode': __opts__.get('redis.cluster_mode', False),
'startup_nodes': __opts__.get('redis.cluster.startup_nodes', {}),
'skip_full_coverage_check': __opts__.get('redis.cluster.skip_full_coverage_check', False)
}
_options = salt.returners.get_returner_options(__virtualname__,
@ -103,10 +163,12 @@ def _get_options(ret=None):
CONN_POOL = None
def _get_conn_pool():
def _get_conn_pool(_options):
global CONN_POOL
if CONN_POOL is None:
CONN_POOL = redis.ConnectionPool()
CONN_POOL = redis.ConnectionPool(host=_options.get('host'),
port=_options.get('port'),
db=_options.get('db'))
return CONN_POOL
@ -115,16 +177,14 @@ def _get_serv(ret=None):
Return a redis server object
'''
_options = _get_options(ret)
host = _options.get('host')
port = _options.get('port')
db = _options.get('db')
pool = _get_conn_pool()
return redis.Redis(
host=host,
port=port,
db=db,
connection_pool=pool)
if _options.get('cluster_mode'):
return StrictRedisCluster(startup_nodes=_options.get('startup_nodes'),
skip_full_coverage_check=_options.get('skip_full_coverage_check'),
decode_responses=True)
else:
pool = _get_conn_pool(_options)
return redis.StrictRedis(connection_pool=pool)
def _get_ttl():
@ -150,7 +210,7 @@ def save_load(jid, load, minions=None):
Save the load to the specified jid
'''
serv = _get_serv(ret=None)
serv.setex('load:{0}'.format(jid), json.dumps(load), _get_ttl())
serv.setex('load:{0}'.format(jid), _get_ttl(), json.dumps(load))
def save_minions(jid, minions, syndic_id=None): # pylint: disable=unused-argument

View File

@ -19,6 +19,7 @@ except ImportError:
# Import Salt libs
import salt.loader
import salt.config
from salt.template import compile_template
from salt.ext.six import string_types
from salt.roster import get_roster_file
@ -43,7 +44,7 @@ def targets(tgt, tgt_type='glob', **kwargs):
**kwargs)
conditioned_raw = {}
for minion in raw:
conditioned_raw[str(minion)] = raw[minion]
conditioned_raw[str(minion)] = salt.config.apply_sdb(raw[minion])
rmatcher = RosterMatcher(conditioned_raw, tgt, tgt_type, 'ipv4')
return rmatcher.targets()