Ask Your Question

How to associate floating IP to specific interface with Heat

asked 2018-07-20 14:45:41 -0600

mheniMerzouki gravatar image

i am trying to create a stack using openstack HEAT, one of the VMs (NOVA::Server) needs to have 2 network interfaces

so in my hot template i create 2 ports and associate them to the NOVA::Server and give a floating IP to one of them gw_float_port

     type: "OS::Nova::Server"
       key_name: { get_param: key_name }
       image: { get_param: image_id }
       flavor: { get_param: instance_type }          
       user_data:"#!/bin/sh \necho \"Starting the OVS setup!\" ... "
       user_data_format: RAW
          - port: {get_resource: gw_float_port}
          - port: {get_resource: gw_ovs_port }

   type: "OS::Neutron::Port"
      network_id: {get_resource: "private_net"}

   type: "OS::Neutron::Port"
      network_id: {get_resource: "private_net"}

   type: "OS::Neutron::FloatingIP"
      floating_network_id: {get_param: "public_network"}
      port_id: {get_resource: "gw_float_port"}

And when i do an ifconfig inside the VM i get the following:

 ens3      Link encap:Ethernet  HWaddr fa:16:3e:76:98:82
           inet addr:  Bcast:  Mask:
 ens4      Link encap:Ethernet  HWaddr fa:16:3e:11:9f:ed
           BROADCAST MULTICAST  MTU:1500  Metric:1
 lo        Link encap:Local Loopback
           inet addr:  Mask:

what i want to know is how to map the NICs from the ifconfig with the NICs in the template and control which one gets the floating IP?

within the template (automatically while creating the stack not with manual manipulation after it is created)

thanks for you help in advance.

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted

answered 2018-07-20 19:16:42 -0600

updated 2018-07-20 19:38:28 -0600

This is not a Heat specific problem. Generally, you can’t predict which port is mapped to which interface when creating a server with several NICs. From the API documentation:

If multiple networks are defined, the order in which they appear in the guest operating system will not necessarily reflect the order in which they are given in the server boot request.

The solution given in the API description is tags. You tag NICs, and the instance uses them to map interfaces as intended. There is more info in the spec, but the 5 minutes I spent googling for this were not sufficient to find out how hypervisors support this feature. The spec mentions that a “future version of qemu” may use it. If your application bases NIC configuration on NIC tags, I guess you can live without hypervisor support.

edit flag offensive delete link more


Interesting. I wasn't aware that the device ordering is not guaranteed. I will note that in several years of creating many Heat stacks on libvirt/kvm-based clouds I've never had the nics not come up in the order I specified. Apparently YMMV on that though.

bnemec gravatar imagebnemec ( 2018-07-24 09:40:18 -0600 )edit

answered 2018-07-24 09:46:57 -0600

bnemec gravatar image

As I noted in my comment on Bernd's answer, I've been doing this for years and have never had the nics out of order, but it sounds like that's not something you can necessarily rely on.

I will also mention that in my experience putting two nics on the same network can create some weird routing issues in the instance, so if you can you may want to move the ovs port to a separate network, and then you'd be able to tell which nic is which by looking at the DHCP-assigned address.

Also be aware that most cloud images will only DHCP the first interface on the instance (as you can see in your ifconfig output), so you'll need to have your user_data script DHCP any extra interfaces.

edit flag offensive delete link more


The last paragraph is worth highlighting. People often think that additional interfaces automatically get IP addresses. In fact, it’s the instance’s responsibility to configure its interfaces. Nova or Neutron can’t force NICs to have a certain configuration.

Bernd Bausch gravatar imageBernd Bausch ( 2018-07-24 23:19:21 -0600 )edit

thanks for the response, the way i'm trying to bring the second interface up is by writing to the network config file "/etc/networks/interfaces" then restarting the network service.But i lose connectivity through the floating IP. does restarting the service affect the floating IP affectation ?

mheniMerzouki gravatar imagemheniMerzouki ( 2018-07-25 14:11:09 -0600 )edit

It shouldn’t. A packet sent to the floating IP gets its destination IP address rewritten to the fixed IP. If the instance still has that fixed IP, the packet should eventually arrive.

You don’t have to restart the entire network service to configure a single interface, though.

Bernd Bausch gravatar imageBernd Bausch ( 2018-07-25 15:47:17 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2018-07-20 14:45:41 -0600

Seen: 266 times

Last updated: Jul 24