Merge pull request #1182 from sky-shiny/os_validate_fip_network
Validate openstack floating ip against provided network name.
This commit is contained in:
commit
75319519cc
1 changed files with 12 additions and 3 deletions
|
@ -172,7 +172,7 @@ def _get_port_info(neutron, module, instance_id, internal_network_name=None):
|
|||
return None, None
|
||||
return fixed_ip_address, port_id
|
||||
|
||||
def _get_floating_ip(module, neutron, fixed_ip_address):
|
||||
def _get_floating_ip(module, neutron, fixed_ip_address, network_name):
|
||||
kwargs = {
|
||||
'fixed_ip_address': fixed_ip_address
|
||||
}
|
||||
|
@ -182,7 +182,16 @@ def _get_floating_ip(module, neutron, fixed_ip_address):
|
|||
module.fail_json(msg = "error in fetching the floatingips's %s" % e.message)
|
||||
if not ips['floatingips']:
|
||||
return None, None
|
||||
return ips['floatingips'][0]['id'], ips['floatingips'][0]['floating_ip_address']
|
||||
for address in ips['floatingips']:
|
||||
if _check_ips_network(neutron, address['floating_network_id'], network_name):
|
||||
return address['id'], address['floating_ip_address']
|
||||
return None, None
|
||||
|
||||
def _check_ips_network(neutron, net_id, network_name):
|
||||
if neutron.show_network(net_id)['network']['name'] == network_name:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def _create_floating_ip(neutron, module, port_id, net_id, fixed_ip):
|
||||
kwargs = {
|
||||
|
@ -245,7 +254,7 @@ def main():
|
|||
if not port_id:
|
||||
module.fail_json(msg="Cannot find a port for this instance, maybe fixed ip is not assigned")
|
||||
|
||||
floating_id, floating_ip = _get_floating_ip(module, neutron, fixed_ip)
|
||||
floating_id, floating_ip = _get_floating_ip(module, neutron, fixed_ip, module.params['network_name'])
|
||||
|
||||
if module.params['state'] == 'present':
|
||||
if floating_ip:
|
||||
|
|
Loading…
Reference in a new issue