003 File Manager
Current Path:
/usr/local/lib/python3.8/site-packages/salt/sdb
usr
/
local
/
lib
/
python3.8
/
site-packages
/
salt
/
sdb
/
📁
..
📄
__init__.py
(29 B)
📁
__pycache__
📄
cache.py
(2.71 KB)
📄
confidant.py
(3.69 KB)
📄
consul.py
(1.68 KB)
📄
couchdb.py
(2.34 KB)
📄
env.py
(1.65 KB)
📄
etcd_db.py
(1.95 KB)
📄
keyring_db.py
(2.48 KB)
📄
memcached.py
(1.61 KB)
📄
redis_sdb.py
(1.72 KB)
📄
rest.py
(3.25 KB)
📄
sqlite3.py
(3.57 KB)
📄
tism.py
(2.16 KB)
📄
vault.py
(2.89 KB)
📄
yaml.py
(2.53 KB)
Editing: couchdb.py
""" CouchDB sdb Module :maintainer: SaltStack :maturity: New :depends: python2-couchdb :platform: all This allow interaction between Salt and a CouchDB [couchdb.apache.org] database. It uses salt's `sdb` system to allow for inserts and retrevals using the `sdb://` prefix in salt configuration files. To use the couchbase sdb module, it must first be configured in the salt master or minion config. The following arguments are required: .. code-block:: yaml couchdb_sdb: driver: couchdb host: localhost port: 5984 database: salt_sdb One could then query the CouchDB instance via an `sdb://` URI such as the following: .. code-block:: yaml password: sdb://couchdb_sdb/mykey To use this interface, you must track IDs on your own or have another source to do the map-reduce logic necessary to calculate the ID you wish to fetch. Additional contributions to build true map-reduce functionality into this module would be welcome. """ # Import Python libraries import logging from uuid import uuid4 # Import Salt libraries from salt.utils.decorators import memoize try: import couchdb HAS_COUCH = True except ImportError: HAS_COUCH = False log = logging.getLogger(__name__) # 'set' is a reserved word __func_alias__ = {"set_": "set"} def __virtual__(): """ Require the python2-couchdb libraries """ return HAS_COUCH @memoize def _construct_uri(profile): """ Examine configuration and return a uri for the couchdb server in the following format: .. code-block:: bash http://localhost:5984/ """ return "http://{host}:{port}".format(**profile) def _get_conn(profile): """ Get a connection to CouchDB """ DEFAULT_BASE_URL = _construct_uri(profile) or "http://localhost:5984" server = couchdb.Server() if profile["database"] not in server: server.create(profile["database"]) return server def set_(key, value, profile=None): """ Set a key/value pair in couchdb """ db = _get_db(profile) return db.save({"_id": uuid4().hex, key: value}) def get(key, profile=None): """ Get a value from couchdb by id """ db = _get_db(profile) return db.get(key) def _get_db(profile): """ Wraps _get_conn() to return a db """ server = _get_conn(profile) db = _get_db(profile) return db
Upload File
Create Folder