The "Writing your first OpenStack application" book contains code that does not work with OpenStack installations that use private IP's as public IP's

Bug #1512215 reported by Martin Paulo
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
openstack-api-site
Confirmed
Medium
Martin Paulo

Bug Description

The sample libcloud code from the "Writing your first OpenStack application" book, in the "Getting Started" chapter will fail if run on an installation that that doesn't provide floating IP's - if it uses private IP's as public IP's.

Further, if floating IP's are supported, it will try to allocate a floating IP even if a public IP is assigned: and then not attach it. Given I'm on one of the aforesaid clouds that use private IP's as public IP's, this might be the correct behavior, but it strikes me as strange.

Lastly, if the aforesaid installation enables floating IP pools, but doesn't let them to dish out IP addresses, the code fails as well. Again, I'm on one such cloud.

Having checked out the api repository I think that these issues exist across all of the supported languages that cover this chapter, not just the libcloud implementation.

Tags: firstapp
Changed in openstack-api-site:
assignee: nobody → Martin Paulo (martin-paulo)
Revision history for this message
Atsushi SAKAI (sakaia) wrote :

Would you describe which IP address is problematic?

Also
  From seeing following URL
  http://developer.openstack.org/firstapp-libcloud/getting_started.html

It describes
 Note
  If you do not use floating IPs, substitute another IP address as appropriate

Tom Fifield (fifieldt)
Changed in openstack-api-site:
milestone: none → mitaka
Revision history for this message
Martin Paulo (martin-paulo) wrote : Re: [Bug 1512215] Re: The "Writing your first OpenStack application" book contains code that does not work with OpenStack installations that use private IP's as public IP's
Download full text (3.3 KiB)

Um: let me see if I can work out a suitable answer.

As it stands, step 13 tries to assign unused_floating_ip to a free floating
ip. If there isn't one, it then tries to allocate a floating ip from the
pool, and assigns it to unused_floating_ip

print('Checking for unused Floating IP...')
unused_floating_ip = None
for floating_ip in conn.ex_list_floating_ips():
    if not floating_ip.node_id:
        unused_floating_ip = floating_ip
        break

if not unused_floating_ip:
    pool = conn.ex_list_floating_ip_pools()[0]
    print('Allocating new Floating IP from pool: {}'.format(pool))
    unused_floating_ip = pool.create_floating_ip()

So at the end of step 13 unused_floating_ip will be assigned, on those
installations that support floating ip pools. If you are on an installation
that doesn't I'm guessing the adventure stops here because an exception
will have been thrown.

Then in step 14 a test is done to see if the instance has a public ip: and
if it doesn't, attaches the allocated floating ip to the instance.

if len(testing_instance.public_ips) > 0:
    print('Instance ' + testing_instance.name + ' already has a public ip.
Skipping attachment.')
else:
    conn.ex_attach_floating_ip_to_node(testing_instance, unused_floating_ip)

Finally in step 15 it is reported that the instance can be found at
unused_floating_ip

print('The Fractals app will be deployed to http://%s' %
unused_floating_ip.ip_address)

However, at this point, this ip address might not have been allocated to
the instance, as the instance had a public ip address. So the wrong ip
address is shown...

And on installations where the private ip is in fact the public ip none of
the above would have worked.

On installations where there is a public ip allocated, an attempt is made
to creating a floating ip, which is then reported as the ip address at
which the instance will be found. Which is surely also wrong?

And yes, the documentation says substitute another ip address as
appropriate, but I think that given that this is aimed at developers who
might be new to OpenStack, getting correct code and good documentation in
front of them is worth the effort.

I'm happy to try and improve the libcloud version of the code the matching
documentation if you like: I've already had to work around it for our local
cloud.

Martin

On 2 November 2015 at 22:06, Atsushi SAKAI <email address hidden> wrote:

> Would you describe which IP address is problematic?
>
> Also
> From seeing following URL
> http://developer.openstack.org/firstapp-libcloud/getting_started.html
>
> It describes
> Note
> If you do not use floating IPs, substitute another IP address as
> appropriate
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1512215
>
> Title:
> The "Writing your first OpenStack application" book contains code that
> does not work with OpenStack installations that use private IP's as
> public IP's
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/openstack-api-site/+bug/1512215/+subscriptions
>

--
=================================================================

Martin Paulo, ...

Read more...

Revision history for this message
Tom Fifield (fifieldt) wrote :

Yeah, this does seem a bit confusing for beginners, so probably worth fixing.

Changed in openstack-api-site:
importance: Undecided → Medium
status: New → Confirmed
tags: added: firstap
tags: added: firstapp
removed: firstap
Revision history for this message
Martin Paulo (martin-paulo) wrote :

Can I just say that its remarkably easy to make mistakes in trying to create code that will run on different clouds that you don't necessarily have access to?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.