OpenStack and in particular the compute service, Nova, has a useful rebuild function that allows you to rebuild an instance from a fresh image while maintaining the same fixed and floating IP addresses, amongst other metadata.
However if you have a shared storage back end, such as Ceph, you're out of luck as this function is not for you.
Fortunately, there is another way.
Note the fixed IP address of the instance that you wish to rebuild and the network ID:
$ nova show demoinstance0 | grep network
| DemoTutorial network | 192.168.24.14, 216.58.220.133 |
$ export FIXED_IP=192.168.24.14
$ neutron floatingip-list | grep 216.58.220.133
| ee7ecd21-bd93-4f89-a220-b00b04ef6753 | | 216.58.220.133 |
$ export FLOATIP_ID=ee7ecd21-bd93-4f89-a220-b00b04ef6753
$ neutron net-show DemoTutorial | grep " id "
| id | 9068dff2-9f7e-4a72-9607-0e1421a78d0d |
$ export OS_NET=9068dff2-9f7e-4a72-9607-0e1421a78d0d
You now need to delete the instance that you wish to rebuild:
$ nova delete demoinstance0
Request to delete server demoinstance0 has been accepted.
Now you need to re-create the port and re-assign the floating IP, if it had one:
$ neutron port-create --name demoinstance0 --fixed-ip ip_address=$FIXED_IP $OS_NET
Created a new port:
+-----------------------+---------------------------------------------------------------------------------------+
| Field | Value |
+-----------------------+---------------------------------------------------------------------------------------+
| admin_state_up | True |
| allowed_address_pairs | |
| binding:vnic_type | normal |
| device_id | |
| device_owner | |
| fixed_ips | {"subnet_id": "eb5db27f-edad-480e-92cb-1f8fec8848a8", "ip_address": "192.168.24.14"} |
| id | c1927578-451b-4682-8888-55c7163898a4 |
| mac_address | fa:16:3e:5a:39:67 |
| name | demoinstance0 |
| network_id | 9068dff2-9f7e-4a72-9607-0e1421a78d0d |
| security_groups | 5898c15a-4670-429b-a414-9f59671c4d8b |
| status | DOWN |
| tenant_id | gsu7j52c50804cf3aad71b92e6ced65e |
+-----------------------+---------------------------------------------------------------------------------------+
$ export OS_PORT=c1927578-451b-4682-8888-55c7163898a4
$ neutron floatingip-associate $FLOATIP_ID $OS_PORT
Associated floating IP ee7ecd21-bd93-4f89-a220-b00b04ef6753
$ neutron floatingip-list | grep $FIXED_IP
| ee7ecd21-bd93-4f89-a220-b00b04ef6753 | 192.168.24.14 | 216.58.220.133 | c1927578-451b-4682-8888-55c7163898a4 |
Now you need to boot the instance again and specify port you created:
$ nova boot --flavor=m1.tiny --image=MyImage --nic port-id=$OS_PORT demoinstance0
$ nova show demoinstance0 | grep network
| DemoTutorial network | 192.168.24.14, 216.58.220.133 |
Now your rebuild has been completed, you've got your old IPs back and you're done. Enjoy :-)