How to get fixed IP address of openstack instance using novaclient
I am running openstack instances using the neweclient python api
server = nova.servers.create(name ="xxx",password="xxx",image="xxx",flavor= flavor.id ,key_name = "adikarikey",nics = [{'net-id': 'xxx','v4-fixed-ip': ''}])
I want to get the IP address of the created instance. How can i do this?
+3
source to share
1 answer
Here is one way to do it, not sure if it is the most efficient, but it works for me on Rackspace cloud servers. Note that since server rotation is an asynchronous task, you need to wait for the server to run before retrieving the IP address.
ip_address = None
for network in server.networks['public']:
if re.match('\d+\.\d+\.\d+\.\d+', network):
ip_address = network
break
if ip_address is None:
print 'No IP address assigned!'
sys.exit(1)
print 'The server is waiting at IP address {0}.'.format(ip_address)
This example is part of an article written in an API nova
maintained by Rackspace. The full article is here .
0
source to share