Ask Your Question

Revision history [back]

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 |
+--------------------------------------+------------------+---------+------------+-------------+-

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/cloud/library/cl-openstack-pythonapis/
is already in current directory, there is no need to redefine get_nova_creds() due to

from credentials import get_nova_creds

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/cloud/library/cl-openstack-pythonapis/
is already in current directory, there is no need to redefine get_nova_creds() due to

from credentials import get_nova_creds