1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Merge branch 'rax-clb-nodes-nodeid' of https://github.com/sivel/ansible into sivel-rax-clb-nodes-nodeid

This commit is contained in:
James Cammarata 2014-04-07 07:40:05 -05:00
commit 085d9aee72

View file

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