Examples of practical solutions using the REST API and cURL console utility¶
Changing the IP address assigned to the instance port¶
Note
Linking an IP address in Openstack is not done to the instance directly, but to the port that is assigned to it. To change the IP address with which the instance is accessed, therefore, you must change the IP address for the port.
Commands used:
Receive information on the project ports:
Description of syntax - https://developer.openstack.org/api-ref/network/v2/#list-ports
curl -s -H "X-Auth-Token: $OS_TOKEN" -H "Content-Type: application/json" https://api.sim-cloud.net:9696/v2.0/ports
- where
https://api.sim-cloud.net:9696 - is the access point for the Networking (Neutron) service
“/v2.0/ports” - are necessary parameters from the documentation of the OpenStack Networking API
Update the parameters of the port:
Description of syntax - https://developer.openstack.org/api-ref/network/v2/#update-port
curl -s -X PUT -H "X-Auth-Token: $OS_TOKEN" -H "Content-Type: application/json" https://api.sim-cloud.net:9696/v2.0/ports/{port_id} -d '{ key:value}' | python -mjson.tool
- where
https://api.sim-cloud.net:9696 - is the access point for the Networking (Neutron) service
“/v2.0/{port_id}” - are necessary parameters from the documentation of the OpenStack Networking API
“-d ‘{ key:value}’” - is a structure with the description of the new IP address for the port, according to the documentation of the OpenStack Networking API
Initial data:
- “demo” - is the project name
- 30.30.30.4 - is the current IP address
- 30.30.30.124 - is the new IP address to which we wish to change the current address
Procedure:
1. Obtain the token ID for the project as described above2. Obtain a list of ports for the project and their parameters$ curl -s -H "X-Auth-Token: $OS_TOKEN" -H "Content-Type: application/json" https://api.sim-cloud.net:9696/v2.0/ports | python -mjson.tool { "ports": [ ... { "admin_state_up": true, "allowed_address_pairs": [], ... "fixed_ips": [ { "ip_address": "30.30.30.4", "subnet_id": "f7e4b2c2-6340-46ac-b10e-c94de49746b1" } ], "id": "f0910640-08b6-4595-88cf-0ecc4ce66dbf", "mac_address": "fa:76:3e:30:63:2b", ... }, ... ] }
Choose the required data:
The ‘ip_address’ value (10.100.100.4) is our <IPaddress> The ‘ID’ value (c95d4d1d-233b-4322-8b3a-d77df89b3bf1) is our {port_id}3. Now armed with all necessary information, the port can be assigned the required IP:curl -s -X PUT -H "X-Auth-Token: $OS_TOKEN" -H "Content-Type: application/json" https://api.sim-cloud.net:9696/v2.0/ports/f0910640-08b6-4595-88cf-0ecc4ce66dbf -d '{ "port": { "fixed_ips": [{"ip_address": "30.30.30.124"}]}}' | python -mjson.tool { "port": { "admin_state_up": true, ... "fixed_ips": [ { "ip_address": "30.30.30.124", "subnet_id": "c949746de4b1-6340-46ac-b10e-f7b2ce42" } ], "id": "f0910640-08b6-4595-88cf-0ecc4ce66dbf", ... } }The new value can be seen in the response to our request. It can also be seen by repeating the command in point 2