From 8a98773089a5329d31d40e89997b75affbc37173 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Sun, 6 Apr 2014 19:17:13 -0500 Subject: [PATCH] Simplify node matching --- library/cloud/rax_clb_nodes | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/library/cloud/rax_clb_nodes b/library/cloud/rax_clb_nodes index 30514abde92..dc0950dca58 100644 --- a/library/cloud/rax_clb_nodes +++ b/library/cloud/rax_clb_nodes @@ -137,19 +137,18 @@ def _activate_virtualenv(path): def _get_node(lb, node_id=None, address=None, port=None): """Return a matching node""" - searches = { - 'id': node_id, - 'address': address, - 'port': port - } - for node in getattr(lb, 'nodes', []): - try: - if all(getattr(node, attr) == value - for (attr, value) in searches.items() if value is not None): - return node - except AttributeError: - continue + match_list = [] + if node_id is not None: + match_list.append(getattr(node, 'id', None) == node_id) + if address is not None: + match_list.append(getattr(node, 'address', None) == address) + if port is not None: + match_list.append(getattr(node, 'port', None) == port) + + if match_list and all(match_list): + return node + return None