diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 487871de..fc3dadca 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -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: diff --git a/neutron_plugin/port.py b/neutron_plugin/port.py index c0ee88a9..25735fdf 100644 --- a/neutron_plugin/port.py +++ b/neutron_plugin/port.py @@ -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, @@ -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 @@ -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): @@ -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 diff --git a/nova_plugin/server.py b/nova_plugin/server.py index d11924e8..b707fe3f 100644 --- a/nova_plugin/server.py +++ b/nova_plugin/server.py @@ -885,7 +885,7 @@ 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): @@ -893,7 +893,7 @@ def _get_mgmt_ip(net_ips): 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 diff --git a/plugin.yaml b/plugin.yaml index 3af87058..7fd972c0 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -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: diff --git a/setup.py b/setup.py index 17883e67..ccd81af7 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ setup( zip_safe=True, name='cloudify-openstack-plugin', - version='2.14.11', + version='2.14.12', author='Cloudify', author_email='hello@cloudify.co', packages=[