mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 17:37:37 -02:30
basic fact search grammar
* Establish a base grammar for handling json path specification and value matching. With boolean logic support and parenthesis grouping i.e. (a.b.c="value") and ((a.b="foo") or (a="bar")) * generate Q() results for passing to Host.objects.filter() * Hooked up via /api/v1/hosts?host_filter=... * DynamicFilterField added to store host filter as string with grammar parser attached as static methods for later use by DynamicInventory & continued use by host_filter=...
This commit is contained in:
@@ -75,7 +75,7 @@ class FieldLookupBackend(BaseFilterBackend):
|
||||
'''
|
||||
|
||||
RESERVED_NAMES = ('page', 'page_size', 'format', 'order', 'order_by',
|
||||
'search', 'type')
|
||||
'search', 'type', 'host_filter')
|
||||
|
||||
SUPPORTED_LOOKUPS = ('exact', 'iexact', 'contains', 'icontains',
|
||||
'startswith', 'istartswith', 'endswith', 'iendswith',
|
||||
|
||||
@@ -78,6 +78,7 @@ from awx.api.metadata import RoleMetadata
|
||||
from awx.main.consumers import emit_channel_notification
|
||||
from awx.main.models.unified_jobs import ACTIVE_STATES
|
||||
from awx.main.scheduler.tasks import run_job_complete
|
||||
from awx.main.fields import DynamicFilterField
|
||||
|
||||
logger = logging.getLogger('awx.api.views')
|
||||
|
||||
@@ -1701,6 +1702,14 @@ class HostList(ListCreateAPIView):
|
||||
serializer_class = HostSerializer
|
||||
capabilities_prefetch = ['inventory.admin']
|
||||
|
||||
def get_queryset(self):
|
||||
qs = super(HostList, self).get_queryset()
|
||||
filter_string = self.request.query_params.get('host_filter', None)
|
||||
if filter_string:
|
||||
filter_q = DynamicFilterField.filter_string_to_q(filter_string)
|
||||
qs = qs.filter(filter_q)
|
||||
return qs
|
||||
|
||||
|
||||
class HostDetail(RetrieveUpdateDestroyAPIView):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user