From 311a3fac7a0101012cf2729048d66b0203b76ff4 Mon Sep 17 00:00:00 2001 From: Isaac Shabtay Date: Fri, 30 Nov 2018 10:41:25 -0800 Subject: [PATCH] fixes #289 --- CHANGELOG.txt | 2 ++ openstack_plugin_common/floatingip.py | 8 +++++++- plugin.yaml | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index dbcaff94..5068b24c 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,5 @@ +2.14.4: + - By default, don't allow using an existing floating IP if it had already been allocated. 2.14.3: - Fix check subnet cidr for fixed ip. 2.14.2: diff --git a/openstack_plugin_common/floatingip.py b/openstack_plugin_common/floatingip.py index fe589652..9c6f173c 100644 --- a/openstack_plugin_common/floatingip.py +++ b/openstack_plugin_common/floatingip.py @@ -14,6 +14,7 @@ # * limitations under the License. from cloudify import ctx +from cloudify.exceptions import RecoverableError from openstack_plugin_common import ( delete_resource_and_runtime_properties, use_external_resource, @@ -22,7 +23,6 @@ OPENSTACK_ID_PROPERTY, OPENSTACK_TYPE_PROPERTY) - FLOATINGIP_OPENSTACK_TYPE = 'floatingip' # Runtime properties @@ -35,6 +35,12 @@ def use_external_floatingip(client, ip_field_name, ext_fip_ip_extractor): external_fip = use_external_resource( ctx, client, FLOATINGIP_OPENSTACK_TYPE, ip_field_name) if external_fip: + if ctx.node.properties['allow_reallocation'] \ + and external_fip['status'] == 'ACTIVE': + raise RecoverableError( + 'Floating IP address {0} is already associated'.format( + external_fip['floating_ip_address']) + ) ctx.instance.runtime_properties[IP_ADDRESS_PROPERTY] = \ ext_fip_ip_extractor(external_fip) return True diff --git a/plugin.yaml b/plugin.yaml index 4173490a..7c3320ae 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -883,6 +883,14 @@ node_types: description: > a boolean for setting whether to create the resource or use an existing one. See the using existing resources section. + allow_reallocation: + type: boolean + default: false + description: > + (Applicable only when use_external_resource is true) + If true, then allow using this floating IP even if it has already been allocated to + another instance. If false, and the floating IP is already allocated (that is, it is + in 'ACTIVE' state), a recoverable error is raised. create_if_missing: type: boolean default: false