salt icon indicating copy to clipboard operation
salt copied to clipboard

[salt-cloud] Attribution of floating IPs works partially in parallel mode

Open arthurzenika opened this issue 12 years ago • 7 comments

salt-cloud is working fine for my use case in "normal" (sequential) mode.

When I do the same thing with "-P" only one of the machines in the map gets a floating IP attributed, so the other machines never get to be accessed and the thing runs in a loop (I guess there's a timeout).

Am using it against an openstack installation.

arthurzenika avatar Apr 23 '14 13:04 arthurzenika

can you provide your map?

gtmanfred avatar Apr 23 '14 14:04 gtmanfred

debian_wheezy_small:
  - django-db
  - django-web1
  - django-web2
  - django-web3

arthurzenika avatar Apr 23 '14 15:04 arthurzenika

Sorry, Also need the cloud.profile and your provider, where ever you have your floating IP addresses set. I will try and look at this in a bit, I need to re setup my openstack environment.

gtmanfred avatar Apr 23 '14 15:04 gtmanfred

nevermind, I will look at this while working on #12223 @gtmanfred

gtmanfred avatar Apr 23 '14 16:04 gtmanfred

I hit the same problem and I think I was able to track it down.

The problem is that salt-cloud uses a pool.list_floating_ips() call to get a list of floating IPs and then it confirms whether the IP has been assigned to an instance by checking the node_id property (see below).

                for idx in pool.list_floating_ips():
                    if idx.node_id is None:
                        floating.append(idx)
                if not floating:

When running in parallel mode this leads to a race condition, so what happens is that instances get the very same floating IP attached. On the other hand, OpenStack will not allow a floating IP to be shared by multiple instances, hence the final result is one instance with a floating IP and the rest without.

A quick hackish fix is to change the pool.list_floating_ips() call with pool.create_floating_ip() (see below)

-                for idx in pool.list_floating_ips():
+               for idx in [pool.create_floating_ip()]:
                     if idx.node_id is None:
                         floating.append(idx)
                 if not floating:

After that, I can confirm that floating IPs will be allocated to all instances correctly.

rhormaza avatar Jul 10 '14 00:07 rhormaza

Does create_floating_ips create a new one each time? or will it grab an unallocated ip first?

Thanks Daniel

gtmanfred avatar Jul 10 '14 16:07 gtmanfred

Hi Daniel, Sorry for such a late response.

Yes, if create_floating_ip() is used, a new floating ip will be allocated each time a vm is created. No ideal, but I reckon is better that have instances without floating ip.

rhormaza avatar Sep 01 '14 05:09 rhormaza