Ask Your Question
1

create and add floating IP to instance via Python API

asked 2015-04-15 17:51:13 -0500

johntest gravatar image

updated 2016-02-02 05:26:18 -0500

dbaxps gravatar image

I am following this tutorial (http://docs.pistoncloud.com/getting_s...) and got the part of adding and associating a floating IP;

However, I get the following when I try this: http://paste.openstack.org/show/204048/

>>> fip = nova.floating_ips.create()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/novaclient/v1_1/floating_ips.py", line 41, in create
    return self._create("/os-floating-ips", {'pool': pool}, "floating_ip")
  File "/usr/lib/python2.7/dist-packages/novaclient/base.py", line 152, in _create
    _resp, body = self.api.client.post(url, body=body)
  File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 286, in post
    return self._cs_request(url, 'POST', **kwargs)
  File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 260, in _cs_request
    **kwargs)
  File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 242, in _time_request
    resp, body = self.request(url, method, **kwargs)
  File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 236, in request
    raise exceptions.from_response(resp, body, url, method)
novaclient.exceptions.NotFound: FloatingIpPoolNotFound: Floating ip pool not found. (HTTP 404) (Request-ID: req-c1c73af4-89c2-4871-a84c-ff0cfc6e6ba7)
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2016-02-02 10:23:42 -0500

dbaxps gravatar image

updated 2016-02-03 02:43:29 -0500

UPDATE 02/03/2016
I was able reproduce issue described in question above,
having floating pool defined
That's why I have addressed the question one more time
END UPDATE

I believe the correct commands in interactive mode would be

[root@ip-192-169-142-127 ~(keystone_demo)]# python
Python 2.7.5 (default, Nov 20 2015, 02:00:19) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import time
>>> from novaclient.v2.client import Client
>>> from credentials import get_nova_creds
>>> def get_nova_creds():
...     d = {}
...     d['username'] = os.environ['OS_USERNAME']
...     d['api_key'] = os.environ['OS_PASSWORD']
...     d['auth_url'] = os.environ['OS_AUTH_URL']
...     d['project_id'] = os.environ['OS_TENANT_NAME']
...     return d
... 
>>> creds = get_nova_creds()
>>> nova = Client(**creds)
/usr/lib/python2.7/site-packages/novaclient/v2/client.py:109: UserWarning: 'novaclient.v2.client.Client' is not designed to be initialized directly. It is inner class of novaclient. Please, use 'novaclient.client.Client' instead. Related lp bug-report: 1493576
  _LW("'novaclient.v2.client.Client' is not designed to be "
>>> nova.floating_ip_pools.list()
[<FloatingIPPool: name=public1>, <FloatingIPPool: name=public2>]
>>> floating_ip = nova.floating_ips.create(nova.floating_ip_pools.list()[0].name)
>>> floating_ip.ip
u'10.10.10.120'
>>> instance = nova.servers.find(name="UbuntuWereWolf")
>>> instance.add_floating_ip(floating_ip)
>>>

Now verify what we achieved :-

[root@ip-192-169-142-127 ~(keystone_demo)]# nova list
+--------------------------------------+------------------+---------+------------+-------------+---------------------------------------+
| ID                                   | Name             | Status  | Task State | Power State | Networks                              |
+--------------------------------------+------------------+---------+------------+-------------+---------------------------------------+
| 21e80e44-afe1-45b1-a10d-458b0be2ce35 | Ubuntu1404Devs01 | SHUTOFF | -          | Shutdown    | demo_network2=70.0.0.16, 10.10.50.107 |
| 530dc56b-9cae-4276-bfb9-f7ed0111292e | Ubuntu1510Devs01 | SHUTOFF | -          | Shutdown    | demo_network2=70.0.0.17, 10.10.50.108 |
| bb7d6072-f76e-4bd3-b5d8-b0bb4678c4e0 | UbuntuWereWolf   | ACTIVE  | -          | Running     | demo_network1=50.0.0.35, 10.10.10.120 |
| ba8c8ef9-8af2-4373-860c-3de3955cdeb0 | VF23ViaPython    | SHUTOFF | -          | Shutdown    | demo_network1=50.0.0.30, 10.10.10.118 |
+--------------------------------------+------------------+---------+------------+-------------+-

If credentials.py per http://www.ibm.com/developerworks/clo...
is already in current directory, there is no need to redefine get_nova_creds() due to

from credentials import get_nova_creds
edit flag offensive delete link more
0

answered 2015-04-15 18:51:09 -0500

You need to have a floating IP pool already created before you can add a FIP to an instance.

As you can see from the errror:

FloatingIpPoolNotFound: Floating ip pool not found.

You either didnt specify the correct floating IP pool (multiple pools are can exist) or you dont have any floating IP pool created yet.

edit flag offensive delete link more

Comments

I have a floating ip pool: ext-net. I tried to specify via fip = nova.floating_ips.create(ext-net) but no go.

johntest gravatar imagejohntest ( 2015-04-15 19:07:30 -0500 )edit

Ensure that the ext-net attribute External Network is set to yes ( on GUI) or on cli neutron net-show ext-net should have attribute name router:external True

Mohit gravatar imageMohit ( 2016-02-02 08:03:38 -0500 )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

Stats

Asked: 2015-04-15 17:51:13 -0500

Seen: 2,907 times

Last updated: Feb 03 '16