web: hosts: Filter host list using OR clauses
parent
23ae7fc0f7
commit
d51cb1d8d3
|
@ -12,6 +12,7 @@ class HostListController(controllers.BaseController):
|
||||||
|
|
||||||
def GET(self, request):
|
def GET(self, request):
|
||||||
hosts = request.db.query(model.Host)
|
hosts = request.db.query(model.Host)
|
||||||
|
criteria = None
|
||||||
for attr in request.GET:
|
for attr in request.GET:
|
||||||
try:
|
try:
|
||||||
column = model.Host.__table__.columns[attr]
|
column = model.Host.__table__.columns[attr]
|
||||||
|
@ -24,7 +25,12 @@ class HostListController(controllers.BaseController):
|
||||||
if not value.endswith('*'):
|
if not value.endswith('*'):
|
||||||
value += '*'
|
value += '*'
|
||||||
value = value.replace('*', '%')
|
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 = request.ResponseClass()
|
||||||
response.set_payload(None, hosts.all())
|
response.set_payload(None, hosts.all())
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -19,15 +19,21 @@ paths:
|
||||||
- name: macaddr
|
- name: macaddr
|
||||||
description: Filter by MAC address
|
description: Filter by MAC address
|
||||||
in: query
|
in: query
|
||||||
type: string
|
type: array
|
||||||
|
items: string
|
||||||
|
collectionFormat: multi
|
||||||
- name: ipaddr
|
- name: ipaddr
|
||||||
description: Filter by IP address
|
description: Filter by IP address
|
||||||
in: query
|
in: query
|
||||||
type: string
|
type: array
|
||||||
|
items: string
|
||||||
|
collectionFormat: multi
|
||||||
- name: hostname
|
- name: hostname
|
||||||
description: Filter by hostname
|
description: Filter by hostname
|
||||||
in: query
|
in: query
|
||||||
type: string
|
type: array
|
||||||
|
items: string
|
||||||
|
collectionFormat: multi
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: Host list
|
description: Host list
|
||||||
|
|
Loading…
Reference in New Issue