Merge pull request #2436 from emonty/fix-floating-ip-api
Use add_ips_to_server API
This commit is contained in:
commit
fde6ee15d6
1 changed files with 7 additions and 18 deletions
|
@ -122,10 +122,10 @@ def main():
|
||||||
argument_spec = openstack_full_argument_spec(
|
argument_spec = openstack_full_argument_spec(
|
||||||
server=dict(required=True),
|
server=dict(required=True),
|
||||||
state=dict(default='present', choices=['absent', 'present']),
|
state=dict(default='present', choices=['absent', 'present']),
|
||||||
network=dict(required=False),
|
network=dict(required=False, default=None),
|
||||||
floating_ip_address=dict(required=False),
|
floating_ip_address=dict(required=False, default=None),
|
||||||
reuse=dict(required=False, type='bool', default=False),
|
reuse=dict(required=False, type='bool', default=False),
|
||||||
fixed_address=dict(required=False),
|
fixed_address=dict(required=False, default=None),
|
||||||
wait=dict(required=False, type='bool', default=False),
|
wait=dict(required=False, type='bool', default=False),
|
||||||
timeout=dict(required=False, type='int', default=60),
|
timeout=dict(required=False, type='int', default=60),
|
||||||
)
|
)
|
||||||
|
@ -154,23 +154,12 @@ def main():
|
||||||
msg="server {0} not found".format(server_name_or_id))
|
msg="server {0} not found".format(server_name_or_id))
|
||||||
|
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
if floating_ip_address is None:
|
cloud.add_ips_to_server(
|
||||||
if reuse:
|
server=server, ips=floating_ip_address, reuse=reuse,
|
||||||
f_ip = cloud.available_floating_ip(network=network)
|
|
||||||
else:
|
|
||||||
f_ip = cloud.create_floating_ip(network=network)
|
|
||||||
else:
|
|
||||||
f_ip = _get_floating_ip(cloud, floating_ip_address)
|
|
||||||
if f_ip is None:
|
|
||||||
module.fail_json(
|
|
||||||
msg="floating IP {0} not found".format(
|
|
||||||
floating_ip_address))
|
|
||||||
|
|
||||||
cloud.attach_ip_to_server(
|
|
||||||
server_id=server['id'], floating_ip_id=f_ip['id'],
|
|
||||||
fixed_address=fixed_address, wait=wait, timeout=timeout)
|
fixed_address=fixed_address, wait=wait, timeout=timeout)
|
||||||
|
fip_address = cloud.get_server_public_ip(server)
|
||||||
# Update the floating IP status
|
# Update the floating IP status
|
||||||
f_ip = cloud.get_floating_ip(id=f_ip['id'])
|
f_ip = _get_floating_ip(cloud, fip_address)
|
||||||
module.exit_json(changed=True, floating_ip=f_ip)
|
module.exit_json(changed=True, floating_ip=f_ip)
|
||||||
|
|
||||||
elif state == 'absent':
|
elif state == 'absent':
|
||||||
|
|
Loading…
Reference in a new issue