diff --git a/library/cloud/rax_clb_nodes b/library/cloud/rax_clb_nodes index 04ec11fc94f..dc0950dca58 100644 --- a/library/cloud/rax_clb_nodes +++ b/library/cloud/rax_clb_nodes @@ -135,11 +135,20 @@ def _activate_virtualenv(path): execfile(activate_this, dict(__file__=activate_this)) -def _get_node(lb, node_id): - """Return a node with the given `node_id`""" - for node in lb.nodes: - if node.id == node_id: +def _get_node(lb, node_id=None, address=None, port=None): + """Return a matching node""" + for node in getattr(lb, 'nodes', []): + 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 @@ -230,10 +239,7 @@ def main(): except pyrax.exc.PyraxException, e: module.fail_json(msg='%s' % e.message) - if node_id: - node = _get_node(lb, node_id) - else: - node = None + node = _get_node(lb, node_id, address, port) result = _node_to_dict(node) @@ -272,22 +278,12 @@ def main(): except pyrax.exc.PyraxException, e: module.fail_json(msg='%s' % e.message) else: # Updating an existing node - immutable = { - 'address': address, - 'port': port, - } - mutable = { 'condition': condition, 'type': typ, 'weight': weight, } - for name, value in immutable.items(): - if value: - module.fail_json( - msg='Attribute %s cannot be modified' % name) - for name, value in mutable.items(): if value is None or value == getattr(node, name): mutable.pop(name)