Monday, 29 February 2016

Keep reserve an existing floating IP and Fixed IP for building a new instance with an another flavor / an image

In some cases it may require to keep reserve an existing  floating IP and Fixed IP for building a new instance with an another flavor / an image.  
Assume the below instance with name "test-fip" having one fixed IP and one Floating IP. We can create another instance with same IP(s) after deleting this instance or removing the network.
$ nova list | grep test-fip 
9xxxxxx-38fd-42b3-a391-xxxxxxxb
test-fip
ACTIVE
Running
prasanta-network=192.168.198.36, 10.63.68.127
$nova show test-fip | grep network
prasanta-network network
192.168.198.36, 9.62.66.127
$ export FIXED_IP=192.168.198.36
$ neutron floatingip-list | grep 9.62.66.127
833ddf95-53b3-4a1d-a5d1-525273bd50fc
192.168.198.36
9.62.66.127
8cd3bbd5-295c-4758-adf2-ccf94f5bba5e
$export NEW_PORT_ID=8ba150e4-67d6-40d2-9462-92922a52640b
$ neutron floatingip-associate $FLOAT_IP_ID $NEW_PORT_ID
Associated floating IP 833ddf95-53b3-4a1d-a5d1-525273bd50fc
$ neutron floatingip-list | grep 192.168.198.36
833ddf95-53b3-4a1d-a5d1-525273bd50fc
192.168.198.36
9.62.66.127
8ba150e4-67d6-40d2-9462-92922a52640b
=833ddf95-53b3-4a1d-a5d1-525273bd50fc
$neutron net-show " prasanta-network" | grep -i id
id
57bb4cc6-3d07-49c2-83d3-f6f2653cd56d
$ export NETWORK_ID=57bb4cc6-3d07-49c2-83d3-f6f2653cd56d
$nova delete 90e7a71d-38fd-42b3-a391-f065fff7587b
Request to delete server 90e7a71d-38fd-42b3-a391-f065fff7587b has been accepted.

$ neutron port-create --name new-test-fip --fixed-ip ip_address=$FIXED_IP $NETWORK_ID
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": "96xxxx-3291-4cb6-9fa3-9xxxxx78", "ip_address": "192.168.198.36"} |
| id                    | 89xxxxx-67d6-40d2-9462-9xxxx6                                                  |
| mac_address           | fa:16:3e:95:06:76                                                                     |
| name                  | new-test-fip                                                                         |
| network_id            | 57bb4cc6-3d07-49c2-83d3-f6f2653cd56d                                                  |
| security_groups       | b3240dd7-20af-444a-8e4e-442907851396                                                  |
| status                | DOWN                                                                                  |
| tenant_id             | xxxxxxxxxx                                                      |
+-----------------------+---------------------------------------------------------------------------------------+
$export NEW_PORT_ID=8ba150e4-67d6-40d2-9462-92922a52640b
$ neutron floatingip-associate $FLOAT_IP_ID $NEW_PORT_ID
Associated floating IP 833ddf95-53b3-4a1d-a5d1-525273bd50fc
$ neutron floatingip-list | grep 192.168.198.36
833ddf95-53b3-4a1d-a5d1-525273bd50fc
192.168.198.36
9.62.66.127
8ba150e4-67d6-40d2-9462-92922a52640b
Build a new instance as below.
$nova boot --image 91dc5e1c-ca5d-40b2-a70f-bb90211c0e96 --flavor 09d05478-66e2-42ca-94e5-0dd4ef218090 --nic port-id=$NEW_PORT_ID new-test-fip
$nova show new-test-fip | grep network
prasanta-network network
192.168.198.36, 9.62.66.127

No comments:

Prasanta Kumar Behera. Mob- 8147470101