From d51cb1d8d3e966f71b4cc8f7dba168b18617d5c5 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Fri, 1 Jan 2016 11:23:41 -0600 Subject: [PATCH] web: hosts: Filter host list using OR clauses --- src/rouse/web/hosts.py | 8 +++++++- src/rouse/web/swagger.yml | 12 +++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/rouse/web/hosts.py b/src/rouse/web/hosts.py index c4224a3..d25d5e7 100644 --- a/src/rouse/web/hosts.py +++ b/src/rouse/web/hosts.py @@ -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 diff --git a/src/rouse/web/swagger.yml b/src/rouse/web/swagger.yml index 4057780..dbfae5a 100644 --- a/src/rouse/web/swagger.yml +++ b/src/rouse/web/swagger.yml @@ -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