Ask Your Question

create server with python api

asked 2014-05-21 08:35:35 -0500

ziliu2020 gravatar image

updated 2014-05-21 21:03:36 -0500

larsks gravatar image

I followed the link below to create a server by calling python nova client..

Here is my code:

nic_d = [{'net-id': int_net_id_1[0]}, {'net-id': int_net_id_2[0]}]

instance = nc.servers.create(name="vm2", image=img, flavor=my_flavor, nics=nic_d)`enter code here`

However when I specified the nics, it sent me the following error:

Traceback (most recent call last):
  File "/home/tsi/openstack/orch-os/src/", line 45, in <module>
    instance = nc.servers.create(name="vm2", image=img, flavor=my_flavor, nics=nic_d)
  File "/usr/lib/python2.7/dist-packages/novaclient/v1_1/", line 456, in create
  File "/usr/lib/python2.7/dist-packages/novaclient/v1_1/", line 147, in _boot
    if nic_info['v4-fixed-ip']:
KeyError: 'v4-fixed-ip'

I had no issue with this code before using the old version client.. but somehow the newer version added new checkpoint.. My problem is that I don't want to use fixed ip, instead I would like to use dhcp to get ip address. I'm thinking to use port-id to replace the net-id but I'm not sure how to code it with servers.create() function.

Any suggestions on how to workaround it?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2014-05-21 22:43:23 -0500

chbrian gravatar image

updated 2014-05-21 22:45:02 -0500

you may try this:

net_id = [your_net_id]
nics = [{"net-id": net_id, "v4-fixed-ip": ''}]
client = get_nova_client()  # I think it's easy for you to get a nova client, so I omit this function
image = client.images.find(name=image)
flavor = client.flavors.find(name=flavor)
client.servers.create(name, image, flavor, nics=nics)

or you don't want to enter net-id, just let new instance attach the first net:

nics = [{"net-id": client.networks.list()[0].id, "v4-fixed-ip": ''}]

hope this will help you.

edit flag offensive delete link more


"v4-fixed-ip": '' did the trick. It works great for me. Now I got the dhcp address. thank you so much

ziliu2020 gravatar imageziliu2020 ( 2014-05-23 00:22:57 -0500 )edit

answered 2014-05-21 21:07:30 -0500

larsks gravatar image

updated 2014-05-21 21:07:48 -0500

What version of python-novaclient are you using? I don't see a v1_1/ in what I'm running locally:

>>> import novaclient
>>> novaclient.__version__

And I'm able to create instances while specifying nics without a problem:

>>> n = NovaClient('2', creds['username'], creds['password'], creds['tenant_name'], creds['auth_url'])
>>> image = n.images.list()[3]
>>> flavor = n.flavors.list()[-1]
>>> nics = [ { 'net-id': u'bb4e5e37-74e1-41bd-880e-b59e94236c5e' } ]
>>> n.servers.create('test1', image, flavor, nics=nics)
<Server: test1>

Maybe your Python module just needs an upgrade?

edit flag offensive delete link more


Thanks for your answer.. I can't do this command. Any idea why?

import novaclient novaclient.__version__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute '__version__'

ziliu2020 gravatar imageziliu2020 ( 2014-05-23 00:27:48 -0500 )edit

It looks like your novaclient is simply too old. Consider upgrading to something current.

larsks gravatar imagelarsks ( 2014-05-23 08:58:14 -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



Asked: 2014-05-21 08:35:35 -0500

Seen: 3,371 times

Last updated: May 21 '14