From 5703c85736b600a101ea48a7adde168b0dbcbd32 Mon Sep 17 00:00:00 2001 From: Tzu-Mainn Chen Date: Thu, 3 Apr 2014 21:01:49 +0200 Subject: Add node filter Closes-Bug: #1302022 Change-Id: I09127cbc689f4f0dab9a03dcf939a067828ceaa2 --- tuskar_ui/infrastructure/nodes/tables.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'tuskar_ui') diff --git a/tuskar_ui/infrastructure/nodes/tables.py b/tuskar_ui/infrastructure/nodes/tables.py index edd5c5bc..a40b6579 100644 --- a/tuskar_ui/infrastructure/nodes/tables.py +++ b/tuskar_ui/infrastructure/nodes/tables.py @@ -35,6 +35,21 @@ class DeleteNode(tables.BatchAction): api.Node.delete(request, obj_id) +class NodeFilterAction(tables.FilterAction): + def filter(self, table, nodes, filter_string): + """Really naive case-insensitive search.""" + q = filter_string.lower() + + def comp(node): + return any(q in attr for attr in + (node.ip_address, + node.properties['cpu'], + node.properties['ram'], + node.properties['local_disk'],)) + + return filter(comp, nodes) + + class NodesTable(tables.DataTable): node = tables.Column(lambda node: node.driver_info['ip_address'], link="horizon:infrastructure:nodes:detail", @@ -88,7 +103,8 @@ class FreeNodesTable(NodesTable): class Meta: name = "free_nodes" verbose_name = _("Free Nodes") - table_actions = (DeleteNode,) + table_actions = (DeleteNode, + NodeFilterAction,) row_actions = (DeleteNode,) @@ -109,7 +125,7 @@ class DeployedNodesTable(NodesTable): class Meta: name = "deployed_nodes" verbose_name = _("Deployed Nodes") - table_actions = () + table_actions = (NodeFilterAction,) row_actions = () columns = ('node', 'deployment_role', 'capacity', 'architecture', 'cpu', 'ram', 'local_disk', 'health', 'power_state') -- cgit v1.2.1