Ask Your Question
0

Cannot assign instance to a given network from Python novaclient API

asked 2013-10-10 14:06:12 -0500

aditya-neel09 gravatar image

Hi, I have 2 networks and when I create an instance, it attaches itself automatically to both the networks by default. I want to mainly disable this and attach the instance to a network of my choice specified by the net-id I am writing Python novaclient API calls for this:

import os import time import novaclient.v1_1.client as nvclient from credentials import get_nova_creds creds=get_nova_creds() nova=nvclient.Client(**creds) image=nova.images.find(name="Ubuntu 12.10 cloudimg amd64") flavor=nova.flavors.find(name="m1.tiny") #network=nova.networks.find(label="net_left")

instance=nova.servers.create(name="samplehost", image=image, flavor=flavor,nic= '9883ec93-4589-4fa2-825d-7a9a8215fd07') //9883ec93-4589-4fa2-825d-7a9a8215fd07 is the ID of a network named 'net_left' status=instance.status

print "Status: %s" % status

My problem is in the nova.servers.create command where I am not able to specify the correct arguments for the net-id.

Could someone help me on by specifying the correct way to give the 'net-id' argument

Thanks

edit retag flag offensive close merge delete

7 answers

Sort by ยป oldest newest most voted
0

answered 2015-11-19 00:56:48 -0500

updated 2015-11-19 00:58:37 -0500

This will help you in better way.

   image=nova.images.find(name="Ubuntu 12.10 cloudimg amd64") 
   flavor=nova.flavors.find(name="m1.tiny")
   my-nic= [{"net-id": myNet.id, "v4-fixed-ip": str(ip_address)}]
   instance=nova.servers.create(name="samplehost", image=image, flavor=flavor,nics=my-nic)
edit flag offensive delete link more
0

answered 2013-10-10 15:05:31 -0500

aji-zqfan gravatar image

oh, sorry, novaclient use boot instead of create, so the nova help command is nova help boot

edit flag offensive delete link more
0

answered 2013-10-10 14:12:05 -0500

aditya-neel09 gravatar image

http://www.ibm.com/developerworks/cloud/library/cl-openstack-pythonapis/ (http://www.ibm.com/developerworks/clo...) http://docs.openstack.org/developer/python-novaclient/api/novaclient.v1_1.servers.html (http://docs.openstack.org/developer/p...)

These are the 2 links I am following

edit flag offensive delete link more
0

answered 2013-10-10 15:04:04 -0500

aji-zqfan gravatar image

i think the common way to solve such problem is:

  1. find documents in http://docs.openstack.org for i.e. http://docs.openstack.org/api/openstack-compute/2/content/NetworksSection.html (http://docs.openstack.org/api/opensta...) , it may not be right, but can provide a general knowlege, like it said:"The parameter fixed_ip is used only when network uuid is specified; also, when port is specified, network uuid and fixed_ip are properties of the port and are ignored. Omit fixed_ip and (network) uuid to avoid validation errors."
  2. use cli help, for this case: nova help create, it can give you a direct param help message
  3. read the source code, code is power for i.e. in novaclient/base.py:

384 if nics is not None: 385 # NOTE(tr3buchet): nics can be an empty list 386 all_net_data = [] 387 for nic_info in nics: 388 net_data = {} 389 # if value is empty string, do not send value in body 390 if nic_info.get('net-id'): 391 net_data['uuid'] = nic_info['net-id'] 392 if nic_info.get('v4-fixed-ip'): 393 net_data['fixed_ip'] = nic_info['v4-fixed-ip'] 394 if nic_info.get('port-id'): 395 net_data['port'] = nic_info['port-id'] 396 all_net_data.append(net_data) 397 body['server']['networks'] = all_net_data

so, nics is a list of dict, each may have key of net-id, v4-fixed-ip, port-id, in your case, you can use nova.servers.create(name="samplehost", image=image, flavor=flavor,nics=[{'net-id': '9883ec93-4589-4fa2-825d-7a9a8215fd07'}])

it may not be right, because it depends on which version of novaclient you have installed. you can check and fix it

good luck

edit flag offensive delete link more
0

answered 2013-10-10 15:16:50 -0500

aditya-neel09 gravatar image

That was exactly what i was looking for....awesome....thanks a lot

edit flag offensive delete link more
0

answered 2013-10-10 15:17:08 -0500

aditya-neel09 gravatar image

Thanks ZhiQiang Fan, that solved my question.

edit flag offensive delete link more
0

answered 2013-10-10 15:41:27 -0500

aji-zqfan gravatar image

you're welcome

ps, you can subscribe the mailing list: 1. http://www.openstack.org/community/ 2. http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack (http://lists.openstack.org/cgi-bin/ma...) to get more help, because the http://anwsers.launchpad.net is not so actvie as mailing list

and/or you can join irc channel to get realtime help (if someone interests on the question): 1. https://wiki.openstack.org/wiki/IRC

edit flag offensive delete link more

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: 2013-10-10 14:06:12 -0500

Seen: 247 times

Last updated: Nov 19 '15