0

I am currently creating OpenStack virtual machines programmatically using OpenStack API. I need to associate floating IP(s) to the server(s) created. The API documentation on this is not clear to me. The compute API says it is deprecated, though I tried to use it, but I am not sure how to correctly use it. There is no API to first create the floating IP - using the compute API for floating IP. I have also tried using the Neutron networking API for floating IP, also this does not show how to associate the floating IP to a new server. It is asking for a port id, and the response of the create server API does not return a port id, neither does it return an IP address.

Could someone please direct me on this?

Kunbi
  • 658
  • 7
  • 18

1 Answers1

0

You should use the neutron-API for the floating-ip. The nova-version is really depricated and is a leftover from the time, when nova and neutron were one single component until they moved out most of the networking stuff into neutron.

Creating a Server is an asynchronous process and get its ip address after a few seconds. So you should create a loop, which runs get-requests against the new server-id and checks the state of the server until he becomes active and has the 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 and check the fixed_ips for the ip of your server). With this port-id you should be able to create your floating-ip.

Maybe there is an easier way, but that's the first I would try, when I would have to solve this task.

Tobias
  • 543
  • 1
  • 3
  • 15
  • Thank you very much for the detailed answer. I am now working on it. – Kunbi Jul 23 '20 at 09:40
  • I have now hit a problem with this implementation. Whenever I call the create floating IP API, it returns a Bad Request (400) error. Having investigated this error, the API documentation says it is caused by one of the following: - The network is not external, such as router:external=False. - The internal OpenStack Networking port is not associated with the floating IP address. - The requested floating IP address does not fall in the subnet range for the external network. - The fixed IP address is not valid. – Kunbi Jul 23 '20 at 12:35
  • hmmmm, it's hard to answer, without knowing your networking-setup. Do you have created your VM in a subnet, which is connected to the external network of the deployment by a virtual router, which is nessecary for a floating ip? – Tobias Jul 23 '20 at 14:09
  • yes, I believe so. Do you think that might be a problem? – Kunbi Jul 24 '20 at 21:06
  • If that's the case, then yes. When you want to connet a floatin-ip to a VM, then you have to bind your VM to a subnet, which is connected over a virtual neutron router. to the external network, where your floatin-ip-pool belongs to. When you bind a VM directly to your external network, your VM get a IP from the subnet of your external network and so the VM should be already reachable from the internet. Thats why you shouldn't connect VMs directly to the extnernal network. A normal user shouldn't be allowed to do something like this. – Tobias Jul 25 '20 at 16:24
  • Thank you. I am not too clued up with networking stuff, I only know that the person who installed the OpenStack infrastructure followed the Openstack/juju documentation (https://jaas.ai/openstack-base) and I remember it had some subnet configuration. So do you mean, I should first connect the VM to a subnet? Then is there something I need to do with the fixed IP it gets before assigning it a floating IP? – Kunbi Jul 26 '20 at 17:45
  • Like I already said: 1. create new network with subnet, 2. create router to connect the new subnet to the external network, 3. create VM, 4. get fixed-ip from VM, 5. get port-id based on the ip, 6. create the floating-ip. Steps 1 and 2 have to be done of course only one time. In your linked tutorial steps 1 and 2 are done in the second gray box in the section `Configure networking`. – Tobias Jul 26 '20 at 18:19
  • thanks. Yes, I am aware that steps 1 and 2 do not need to be done again. I only put the link to show you what was done. I am able to do up to step 5, it's when I try step 6, that I encounter the initial challenge. – Kunbi Jul 26 '20 at 21:10
  • hmmm, could you create a new question for this problem, with all addresses, IDs and other usefull information of all related networks, subnets, neutron-router, ports and VMs together with the body of your API-request, which you used to create the floating-ip? – Tobias Jul 26 '20 at 23:08
  • Hi @Tobias, please could you check my question at . Grateful for your response. – Kunbi Aug 18 '20 at 12:04
  • I have already seen your question, but I've absolute no experience with octavia. Sorry :( – Tobias Aug 18 '20 at 12:55
  • oh okay. Thank you. – Kunbi Aug 18 '20 at 14:11