bigip_node: additional code
- checks if address already assigned to other node name - add description for node - check for node addres changes - add missing code "node exists, potentially modify attributes"
This commit is contained in:
parent
9f1e024bf9
commit
bb8ae983c3
1 changed files with 43 additions and 5 deletions
|
@ -76,11 +76,17 @@ options:
|
||||||
choices: []
|
choices: []
|
||||||
host:
|
host:
|
||||||
description:
|
description:
|
||||||
- "Node IP. Required when state=present. Ignored when state=present."
|
- "Node IP. Required when state=present. Ignored when state=absent."
|
||||||
required: true
|
required: true
|
||||||
default: null
|
default: null
|
||||||
choices: []
|
choices: []
|
||||||
aliases: ['address']
|
aliases: ['address']
|
||||||
|
description:
|
||||||
|
description:
|
||||||
|
- "Optional node description."
|
||||||
|
required: false
|
||||||
|
default: null
|
||||||
|
choices: []
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
|
@ -123,7 +129,19 @@ def node_exists(api, address):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def create_node_address(api, address, name):
|
def create_node_address(api, address, name):
|
||||||
api.LocalLB.NodeAddressV2.create(nodes=[name], addresses=[address], limits=[0])
|
try:
|
||||||
|
api.LocalLB.NodeAddressV2.create(nodes=[name], addresses=[address], limits=[0])
|
||||||
|
return True, ""
|
||||||
|
except bigsuds.OperationFailed, e:
|
||||||
|
if "invalid node address" in str(e) and "already exists" in str(e):
|
||||||
|
return (False, "The referenced IP address is already in use.")
|
||||||
|
else:
|
||||||
|
# genuine exception
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def get_node_address(api, name):
|
||||||
|
return api.LocalLB.NodeAddressV2.get_address(nodes=[name])[0]
|
||||||
|
|
||||||
def delete_node_address(api, address):
|
def delete_node_address(api, address):
|
||||||
result = False
|
result = False
|
||||||
|
@ -138,6 +156,14 @@ def delete_node_address(api, address):
|
||||||
raise
|
raise
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def set_node_description(api, name, description):
|
||||||
|
api.LocalLB.NodeAddressV2.set_description(nodes=[name],
|
||||||
|
descriptions=[description])
|
||||||
|
|
||||||
|
|
||||||
|
def get_node_description(api, name):
|
||||||
|
return api.LocalLB.NodeAddressV2.get_description(nodes=[name])[0]
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
|
@ -149,6 +175,7 @@ def main():
|
||||||
partition = dict(type='str', default='Common'),
|
partition = dict(type='str', default='Common'),
|
||||||
name = dict(type='str', required=True),
|
name = dict(type='str', required=True),
|
||||||
host = dict(type='str', aliases=['address', 'ip']),
|
host = dict(type='str', aliases=['address', 'ip']),
|
||||||
|
description = dict(type='str', default='')
|
||||||
),
|
),
|
||||||
supports_check_mode=True
|
supports_check_mode=True
|
||||||
)
|
)
|
||||||
|
@ -164,6 +191,7 @@ def main():
|
||||||
host = module.params['host']
|
host = module.params['host']
|
||||||
name = module.params['name']
|
name = module.params['name']
|
||||||
address = "/%s/%s" % (partition, name)
|
address = "/%s/%s" % (partition, name)
|
||||||
|
description = module.params['description']
|
||||||
|
|
||||||
# sanity check user supplied values
|
# sanity check user supplied values
|
||||||
|
|
||||||
|
@ -189,14 +217,24 @@ def main():
|
||||||
if not node_exists(api, address):
|
if not node_exists(api, address):
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
if not node_exists(api, address):
|
if not node_exists(api, address):
|
||||||
create_node_address(api, address=host, name=address)
|
res, desc = create_node_address(api, address=host, name=address)
|
||||||
|
if not res:
|
||||||
|
module.fail_json(msg=desc)
|
||||||
result = {'changed': True}
|
result = {'changed': True}
|
||||||
else:
|
else:
|
||||||
# node exists -- potentially modify attributes
|
# node exists -- potentially modify attributes
|
||||||
if host is not None:
|
if host is not None:
|
||||||
|
current_address = get_node_address(api, address)
|
||||||
|
if current_address != host:
|
||||||
|
module.fail_json(msg="""Changing the node address is not
|
||||||
|
supported by the API, delete and
|
||||||
|
recreate the node.""")
|
||||||
|
|
||||||
|
current_descrip = get_node_description(api, address)
|
||||||
pass
|
if current_descrip != description:
|
||||||
|
if not module.check_mode:
|
||||||
|
set_node_description(api, address, description)
|
||||||
|
result = {'changed': True}
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
traceback.print_exc(file=sys.stdout)
|
traceback.print_exc(file=sys.stdout)
|
||||||
|
|
Loading…
Reference in a new issue