[英]How to get fixed IP address of openstack instance using novaclient
I spin-up openstack instances using noveclient python api 我使用noveclient python api启动openstack实例
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. 我想获取创建的实例的IP地址。 How can I do it ?
我该怎么做 ?
Here is one way to do it, not sure if it is the most efficient, but this works for me on Rackspace cloud servers. 这是一种方法,不确定它是否是最有效的,但这适用于Rackspace云服务器。 Note that because spinning up a server is an asynchronous task it is necessary to wait for the server to be operational before extracting the IP address.
请注意,因为启动服务器是异步任务,所以在提取IP地址之前必须等待服务器运行。
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 I wrote on the nova
APIs, as supported by Rackspace. 这个例子是我在
nova
API上写的一篇文章的一部分,由Rackspace支持。 The full article is here . 完整的文章在这里 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.