如何创建浮动 IP,然后使用 Openstack 将其分配给服务器 API

How to Create a Floating IP and then assign it to a server using Openstack API

我目前正在使用 OpenStack API 以编程方式创建 OpenStack 虚拟机。我需要将浮动 IP 关联到创建的服务器。关于此的 API 文档我不清楚。计算 API 说它已被弃用,虽然我尝试使用它,但我不确定如何正确使用它。没有 API 来首先创建浮动 IP - 使用计算 API 来创建浮动 IP。我也尝试过使用 Neutron 网络 API 作为浮动 IP,这也没有说明如何将浮动 IP 关联到新服务器。它要求端口 ID,创建服务器 API 的响应不是 return 端口 ID,也不是 return IP 地址。

有人可以指导我吗?

你应该使用neutron-API作为浮动IP。 nova 版本确实被贬低了,是那个时代的遗留物,当时 nova 和 neutron 是一个单一的组件,直到他们将大部分网络内容移到 neutron 中。

创建服务器是一个异步过程,几秒后获取其IP地址。因此,您应该创建一个循环,它针对新的服务器 ID 运行 get-requests 并检查服务器的状态,直到他变为活动状态并拥有 ip(https://docs.openstack.org/api-ref/compute/?expanded=show-server-details-detail#show-server-details and check OS-EXT-STS:vm_state for the active state). After this you can request all ports and check in the result, which port-id belongs to the ip of the new created server (https://docs.openstack.org/api-ref/network/v2/?expanded=list-ports-detail#list-ports 并检查 fixed_ips 的 ip你的服务器)。使用此端口 ID,您应该能够创建您的浮动 IP。

也许有更简单的方法,但当我必须解决此任务时,这是我首先尝试的方法。