T53161 elasticsearch can index nodes now. cli command. NOTE config changes!!
This commit is contained in:
@@ -12,6 +12,8 @@ from pillar.cli.celery import manager_celery
|
||||
from pillar.cli.maintenance import manager_maintenance
|
||||
from pillar.cli.operations import manager_operations
|
||||
from pillar.cli.setup import manager_setup
|
||||
from pillar.cli.elastic import manager_elk
|
||||
|
||||
from pillar.cli import translations
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -21,3 +23,4 @@ manager.add_command('celery', manager_celery)
|
||||
manager.add_command("maintenance", manager_maintenance)
|
||||
manager.add_command("setup", manager_setup)
|
||||
manager.add_command("operations", manager_operations)
|
||||
manager.add_command("elastic", manager_elk)
|
||||
|
42
pillar/cli/elastic.py
Normal file
42
pillar/cli/elastic.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import logging
|
||||
|
||||
from flask_script import Manager
|
||||
|
||||
from pillar import current_app
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
manager_elk = Manager(
|
||||
current_app, usage="Elastic utilities, like reset_index()")
|
||||
|
||||
|
||||
@manager_elk.command
|
||||
def reset_index(elk_index):
|
||||
"""
|
||||
Destroy and recreate elastic indices
|
||||
|
||||
node, user ...
|
||||
"""
|
||||
#real_current_app = current_app._get_current_object()._get_current_object()
|
||||
|
||||
with current_app.app_context():
|
||||
from pillar.api.search import index
|
||||
if elk_index == 'nodes':
|
||||
index.reset_node_index()
|
||||
|
||||
|
||||
@manager_elk.command
|
||||
def reindex_nodes():
|
||||
|
||||
db = current_app.db()
|
||||
nodes_coll = db['nodes']
|
||||
node_count = nodes_coll.count()
|
||||
|
||||
log.debug('Reindexing %d in Elastic', node_count)
|
||||
|
||||
from pillar.celery.search_index_tasks import prepare_node_data
|
||||
from pillar.api.search import elastic_indexing
|
||||
|
||||
for node in nodes_coll.find():
|
||||
to_index = prepare_node_data('', node=node)
|
||||
elastic_indexing.index_node_save(to_index)
|
Reference in New Issue
Block a user