web: hosts: Filter host list using OR clauses
parent
23ae7fc0f7
commit
d51cb1d8d3
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue