web: hosts: Filter host list using OR clauses

master
Dustin 2016-01-01 11:23:41 -06:00
parent 23ae7fc0f7
commit d51cb1d8d3
2 changed files with 16 additions and 4 deletions

View File

@ -12,6 +12,7 @@ class HostListController(controllers.BaseController):
def GET(self, request):
hosts = request.db.query(model.Host)
criteria = None
for attr in request.GET:
try:
column = model.Host.__table__.columns[attr]
@ -24,7 +25,12 @@ class HostListController(controllers.BaseController):
if not value.endswith('*'):
value += '*'
value = value.replace('*', '%')
hosts = hosts.filter(column.like(value))
if criteria is not None:
criteria |= column.like(value)
else:
criteria = column.like(value)
if criteria is not None:
hosts = hosts.filter(criteria)
response = request.ResponseClass()
response.set_payload(None, hosts.all())
return response

View File

@ -19,15 +19,21 @@ paths:
- name: macaddr
description: Filter by MAC address
in: query
type: string
type: array
items: string
collectionFormat: multi
- name: ipaddr
description: Filter by IP address
in: query
type: string
type: array
items: string
collectionFormat: multi
- name: hostname
description: Filter by hostname
in: query
type: string
type: array
items: string
collectionFormat: multi
responses:
200:
description: Host list