mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
use memcached instead of memcache for sdb and util modules
This commit is contained in:
parent
a522f694c2
commit
cbcc362033
@ -1,42 +1,41 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Memcache "Salt DB" Module
|
||||
Memcached "Salt DB" Module
|
||||
|
||||
:maintainer: SaltStack
|
||||
:maturity: New
|
||||
:depends: python-memcached
|
||||
:platform: all
|
||||
|
||||
This module allows access to memcache using an ``sdb://`` URI. This
|
||||
This module allows access to memcached using an ``sdb://`` URI. This
|
||||
package is located at ``https://pypi.python.org/pypi/python-memcached``.
|
||||
|
||||
Like all sdb modules, the memcache module requires a configuration profile to
|
||||
Like all sdb modules, the memcached module requires a configuration profile to
|
||||
be configured in either the minion or master configuration file. This profile
|
||||
requires very little. In the example:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
mymemcache:
|
||||
driver: memcache
|
||||
driver: memcached
|
||||
host: localhost
|
||||
port: 11211
|
||||
|
||||
The ``driver`` refers to the memcache module, ``host`` and ``port`` the
|
||||
memcache server to connect to (defaults to ``localhost`` and ``11211``,
|
||||
and ``mymemcache`` refers to the name that will appear in the URI:
|
||||
The ``driver`` refers to the memcached module, ``host`` and ``port`` the
|
||||
memcached server to connect to (defaults to ``localhost`` and ``11211``,
|
||||
and ``mymemcached`` refers to the name that will appear in the URI:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
password: sdb://mymemcache/mykey
|
||||
password: sdb://mymemcached/mykey
|
||||
|
||||
'''
|
||||
|
||||
# import python libs
|
||||
from __future__ import absolute_import
|
||||
import logging
|
||||
|
||||
# import Salt libs
|
||||
import salt.utils.memcache
|
||||
import salt.utils.memcached
|
||||
|
||||
|
||||
DEFAULT_HOST = '127.0.0.1'
|
||||
@ -49,15 +48,13 @@ __func_alias__ = {
|
||||
'set_': 'set'
|
||||
}
|
||||
|
||||
__virtualname__ = 'memcache'
|
||||
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Only load the module if memcache is installed
|
||||
Only load the module if memcached is installed
|
||||
'''
|
||||
if salt.utils.memcache.HAS_LIBS:
|
||||
return __virtualname__
|
||||
if salt.utils.memcached.HAS_LIBS:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
@ -65,14 +62,14 @@ def set_(key, value, profile=None):
|
||||
'''
|
||||
Set a key/value pair in memcached
|
||||
'''
|
||||
conn = salt.utils.memcache.get_conn(profile)
|
||||
conn = salt.utils.memcached.get_conn(profile)
|
||||
time = profile.get('expire', DEFAULT_EXPIRATION)
|
||||
return salt.utils.memcache.set_(conn, key, value, time=time)
|
||||
return salt.utils.memcached.set_(conn, key, value, time=time)
|
||||
|
||||
|
||||
def get(key, profile=None):
|
||||
'''
|
||||
Get a value from memcached
|
||||
'''
|
||||
conn = salt.utils.memcache.get_conn(profile)
|
||||
return salt.utils.memcache.get(conn, key)
|
||||
conn = salt.utils.memcached.get_conn(profile)
|
||||
return salt.utils.memcached.get(conn, key)
|
@ -13,24 +13,24 @@ used. The following configurations are both valid:
|
||||
.. code-block:: yaml
|
||||
|
||||
# No profile name
|
||||
memcache.host: 127.0.0.1
|
||||
memcache.port: 11211
|
||||
memcached.host: 127.0.0.1
|
||||
memcached.port: 11211
|
||||
|
||||
# One or more profiles defined
|
||||
my_memcache_config:
|
||||
memcache.host: 127.0.0.1
|
||||
memcache.port: 11211
|
||||
my_memcached_config:
|
||||
memcached.host: 127.0.0.1
|
||||
memcached.port: 11211
|
||||
|
||||
Once configured, the get_conn() function is passed a set of opts, and,
|
||||
optionally, the name of a profile to be used.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import salt.utils.memcache_utils.py
|
||||
conn = salt.utils.memcache_utils.get_conn(__opts__,
|
||||
profile='my_memcache_config')
|
||||
import salt.utils.memcached_utils.py
|
||||
conn = salt.utils.memcached_utils.get_conn(__opts__,
|
||||
profile='my_memcached_config')
|
||||
|
||||
It should be noted that some usages of memcache may require a profile to be
|
||||
It should be noted that some usages of memcached may require a profile to be
|
||||
specified, rather than top-level configurations. This being the case, it is
|
||||
better to always use a named configuration profile, as shown above.
|
||||
'''
|
||||
@ -63,8 +63,6 @@ __func_alias__ = {
|
||||
'set_': 'set'
|
||||
}
|
||||
|
||||
__virtualname__ = 'memcache'
|
||||
|
||||
|
||||
# Although utils are often directly imported, it is also possible
|
||||
# to use the loader.
|
||||
@ -72,7 +70,7 @@ def __virtual__():
|
||||
'''
|
||||
Only load if python-memcached is installed
|
||||
'''
|
||||
return __virtualname__ if HAS_LIBS else False
|
||||
return True if HAS_LIBS else False
|
||||
|
||||
|
||||
def get_conn(opts, profile=None, host=None, port=None):
|
||||
@ -93,8 +91,8 @@ def get_conn(opts, profile=None, host=None, port=None):
|
||||
else:
|
||||
conf = opts_merged
|
||||
|
||||
host = conf.get('memcache.host', DEFAULT_HOST)
|
||||
port = conf.get('memcache.port', DEFAULT_PORT)
|
||||
host = conf.get('memcached.host', DEFAULT_HOST)
|
||||
port = conf.get('memcached.port', DEFAULT_PORT)
|
||||
|
||||
if not str(port).isdigit():
|
||||
raise SaltInvocationError('port must be an integer')
|
Loading…
Reference in New Issue
Block a user