CLI examples and docstrings

This commit is contained in:
Ryan Lane 2015-01-15 16:54:52 -08:00
parent 0c000cc500
commit a1421e6dff
2 changed files with 19 additions and 0 deletions

View File

@ -35,6 +35,10 @@ def exists(index, id, doc_type='_all', hosts=None, profile='elasticsearch'):
'''
Check for the existence of an elasticsearch document specified by id in the
index.
CLI example::
salt myminion elasticsearch.exists grafana-dash mydash profile='grafana'
'''
es = _get_instance(hosts, profile)
try:
@ -46,6 +50,10 @@ def exists(index, id, doc_type='_all', hosts=None, profile='elasticsearch'):
def index(index, doc_type, body, id=None, hosts=None, profile='elasticsearch'):
'''
Create or update an index with the specified body for the specified id.
CLI example::
salt myminion elasticsearch.index grafana-dash dashboard '{"user":"guest","group":"guest","body":"",...}' mydash profile='grafana'
'''
es = _get_instance(hosts, profile)
return es.index(index=index, doc_type=doc_type, body=body, id=id)
@ -54,6 +62,10 @@ def index(index, doc_type, body, id=None, hosts=None, profile='elasticsearch'):
def get(index, id, doc_type='_all', hosts=None, profile='elasticsearch'):
'''
Get the contents of the specifed id from the index.
CLI example::
salt myminion elasticsearch.get grafana-dash mydash profile='grafana'
'''
es = _get_instance(hosts, profile)
return es.get(index=index, id=id, doc_type=doc_type)
@ -62,6 +74,10 @@ def get(index, id, doc_type='_all', hosts=None, profile='elasticsearch'):
def delete(index, doc_type, id, hosts=None, profile='elasticsearch'):
'''
Delete the document specified by the id in the index.
CLI example::
salt myminion elasticsearch.delete grafana-dash dashboard mydash profile='grafana'
'''
es = _get_instance(hosts, profile)
try:

View File

@ -182,6 +182,9 @@ def __virtual__():
def _parse_profile(profile):
'''
From a pillar key, or a dictionary, return index and host keys.
'''
if isinstance(profile, string_types):
_profile = __salt__['config.option'](profile)
if not _profile: