简体   繁体   中英

Fetching floating IP on openstack VM

I am trying to automate a service on my VM (which is on openstack cloud) for which I need the floating IP of that machine. Is there a command or anything for that matter which can help me get it?

Just for clarification: When you way "you want to get" the floating IP is, you want to know from inside the instance the floating IP attached to it ?. If that's the case, just use the metadata service by either directly using "curl", or if you have the cloud-init tools installed on the instance, use the "ec2metadata" command.

If you instead want to auto-assign the FIP to the instance, the answer above is the right one.

Install che openstack cli. I used cli version openstack 2.6.0 .

First create a floating IP. You will need to give the name of your public network. In my case the name is public . If unsure about the name of the network where you can get a floating ip from check with

openstack network list 

Create the floating ip

$ openstack ip floating create public
+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| fixed_ip_address    | None                                 |
| floating_ip_address | 86.119.0.163                         |
| floating_network_id | 7313f148-f340-49b4-9d76-89de0702e801 |
| headers             |                                      |
| id                  | bba11a1b-9a31-4d67-a339-2fdbb3b74d11 |
| port_id             | None                                 |
| project_id          | 0009b5ca32594503b2d64ded05bbe0a8     |
| router_id           | None                                 |
| status              | DOWN                                 |
+---------------------+--------------------------------------+
$

Now that you have a floating IP you can associate it to the VM using the VM name. You can check the vm name with the command

openstack server list

Associate the floating IP

openstack ip floating add 86.119.0.163 vmname

If you do again openstack server list you will see that now the IP is listed associate to the VM.

I think you are interested now in

openstack server show vmname -f json

Will return a lot of information about the VM and also the addresses. Check the -f flag, there are more formatters than json

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM