Simplify node matching

reviewable/pr18780/r1
Matt Martz 11 years ago
parent 9a19792eff
commit a191688c71

@ -137,19 +137,18 @@ def _activate_virtualenv(path):
def _get_node(lb, node_id=None, address=None, port=None): def _get_node(lb, node_id=None, address=None, port=None):
"""Return a matching node""" """Return a matching node"""
searches = {
'id': node_id,
'address': address,
'port': port
}
for node in getattr(lb, 'nodes', []): for node in getattr(lb, 'nodes', []):
try: match_list = []
if all(getattr(node, attr) == value if node_id is not None:
for (attr, value) in searches.items() if value is not None): match_list.append(getattr(node, 'id', None) == node_id)
return node if address is not None:
except AttributeError: match_list.append(getattr(node, 'address', None) == address)
continue if port is not None:
match_list.append(getattr(node, 'port', None) == port)
if match_list and all(match_list):
return node
return None return None

Loading…
Cancel
Save