Skip to content

Commit

Permalink
Merge pull request #319 from cloudify-cosmo/CY-1815-expose-ips-as-run…
Browse files Browse the repository at this point in the history
…time-properties-for-dual-port-2_x

CY-1815 Expose ips as runtime properties for port node instance in 2.x
  • Loading branch information
EarthmanT authored Oct 22, 2019
2 parents 438ff6e + 4386b17 commit 03219e7
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
2.14.12:
- expose ipv4 and ipv6 addresses as runtime properties for port.
2.14.11:
- Fix issue with re-attach port to server on deployment update.
2.14.10:
Expand Down
64 changes: 60 additions & 4 deletions neutron_plugin/port.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
from cloudify.decorators import operation
from cloudify.exceptions import NonRecoverableError

import neutronclient.common.exceptions as neutron_exceptions
from IPy import IP

import neutronclient.common.exceptions as neutron_exceptions
from openstack_plugin_common import (
with_neutron_client,
with_nova_client,
Expand Down Expand Up @@ -50,9 +51,16 @@
# Runtime properties
FIXED_IP_ADDRESS_PROPERTY = 'fixed_ip_address' # the fixed ip address
MAC_ADDRESS_PROPERTY = 'mac_address' # the mac address
RUNTIME_PROPERTIES_KEYS = \
COMMON_RUNTIME_PROPERTIES_KEYS + [FIXED_IP_ADDRESS_PROPERTY,
MAC_ADDRESS_PROPERTY]
# List of all ip addresses exported as runtime properties for port instance
IPS_ADDRESS_PROPERTIES = [
'ipv4_addresses',
'ipv6_addresses',
'ipv4_address',
'ipv6_address'
]
PORT_IPS_PROPERTIES = [FIXED_IP_ADDRESS_PROPERTY, MAC_ADDRESS_PROPERTY]\
+ IPS_ADDRESS_PROPERTIES
RUNTIME_PROPERTIES_KEYS = COMMON_RUNTIME_PROPERTIES_KEYS + PORT_IPS_PROPERTIES

NO_SG_PORT_CONNECTION_RETRY_INTERVAL = 3

Expand Down Expand Up @@ -95,6 +103,52 @@ def _port_update(neutron_client, port_id, args, ext_port):
runtime_properties[MAC_ADDRESS_PROPERTY] = ext_port['mac_address']


def _get_ips_from_port(port):
"""
This method will extract ipv4 & ipv6 for from port object
:param port:
:return:
"""
net_ips = port['fixed_ips'] if port.get('fixed_ips') else []
ips_v4 = []
ips_v6 = []
for net_ip in net_ips:
if net_ip.get('ip_address'):
ip_address = net_ip['ip_address']
try:
# Lookup all ipv4s
IP(ip_address, ipversion=4)
ips_v4.append(ip_address)
except ValueError:
# If it is not an ipv4 then collect the ipv6
IP(ip_address, ipversion=6)
ips_v6.append(ip_address)
return ips_v4, ips_v6


def _export_ips_to_port_instance(port):
"""
This method will export ips of the current port as runtime properties
for port node instance to be access later on
:param port:
"""
ips_v4, ips_v6 = _get_ips_from_port(port)
# Set list of ipv4 for the current nod as runtime properties
ctx.instance.runtime_properties['ipv4_addresses'] = ips_v4
# # Set list of ipv6 for the current nod as runtime properties
ctx.instance.runtime_properties['ipv6_addresses'] = ips_v6

if len(ips_v4) == 1:
ctx.instance.runtime_properties['ipv4_address'] = ips_v4[0]
else:
ctx.instance.runtime_properties['ipv4_address'] = ''

if len(ips_v6) == 1:
ctx.instance.runtime_properties['ipv6_address'] = ips_v6[0]
else:
ctx.instance.runtime_properties['ipv6_address'] = ''


@operation
@with_neutron_client
def create(neutron_client, args, **kwargs):
Expand Down Expand Up @@ -130,6 +184,8 @@ def create(neutron_client, args, **kwargs):
ctx.instance.runtime_properties[FIXED_IP_ADDRESS_PROPERTY] = \
_get_fixed_ip(p)
ctx.instance.runtime_properties[MAC_ADDRESS_PROPERTY] = p['mac_address']
# Export ip addresses attached to port as runtime properties
_export_ips_to_port_instance(p)


@operation
Expand Down
4 changes: 2 additions & 2 deletions nova_plugin/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,15 +885,15 @@ def _get_mgmt_ip(net_ips):
elif len(ipv4_addrs) == 1:
ctx.instance.runtime_properties[IPV4_PROPERTY] = ipv4_addrs[0]
else:
ctx.instance.runtime_properties[IPV4_PROPERTY] = None
ctx.instance.runtime_properties[IPV4_PROPERTY] = ''
if server.accessIPv6:
ctx.instance.runtime_properties[IPV6_PROPERTY] = server.accessIPv6
elif netaddr.valid_ipv6(manager_network_ip):
ctx.instance.runtime_properties[IPV6_PROPERTY] = manager_network_ip
elif len(ipv6_addrs) == 1:
ctx.instance.runtime_properties[IPV6_PROPERTY] = ipv6_addrs[0]
else:
ctx.instance.runtime_properties[IPV6_PROPERTY] = None
ctx.instance.runtime_properties[IPV6_PROPERTY] = ''


@operation
Expand Down
4 changes: 2 additions & 2 deletions plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
plugins:
openstack:
executor: central_deployment_agent
source: https://github.com/cloudify-cosmo/cloudify-openstack-plugin/archive/2.14.11.zip
source: https://github.com/cloudify-cosmo/cloudify-openstack-plugin/archive/2.14.12.zip
package_name: cloudify-openstack-plugin
package_version: '2.14.11'
package_version: '2.14.12'

data_types:
cloudify.openstack.types.custom_configuration:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
setup(
zip_safe=True,
name='cloudify-openstack-plugin',
version='2.14.11',
version='2.14.12',
author='Cloudify',
author_email='[email protected]',
packages=[
Expand Down

0 comments on commit 03219e7

Please sign in to comment.