In Openstack flavors define the size of a virtual server that can be launched. It includes compute, memory, and storage capacity of a virtual server. A flavor consists of many parameters of which the following are required:
- Flavor ID (required) – If not specified, an auto-generated ID shall be assigned
- Name (required)
- vCPUs (required)
- Memory in MB (required)
- Disk in GB (required)
In this tutorial, I’ll be explaining how to create/list/delete flavors in OpenStack using APIs.
How to create/list/delete flavors using OpenStack API
Before creating a flavor in OpenStack via API, well you must generate API tokens. If you haven’t, then head on to this article and create one using the cURL command. Once the tokens are generated, you can create flavors via cURL. To do that, let us consider a demo environment I had set up for the series of articles on OpenStack APIs.
Here is the demo API endpoint to create a flavor: http://192.168.30.10:8774/v2.1/flavors
I will be using OpenStack Version: 4.0.2
Create a flavor using OpenStack API
You can create a flavor using the following command:
$ curl -s -X POST http://192.168.30.10:8774/v2.1/flavors -H "Accept: application/json" -H "Content-Type: application/json" -H "X-Auth-Token:$TOKEN" -d '{"flavor": {"vcpus": 1, "disk": 10, "name": "tg", "os-flavor-access:is_public": true, "ram": 256}}' | python -m json.tool
Output:
{ "flavor": { "OS-FLV-DISABLED:disabled": false, "OS-FLV-EXT-DATA:ephemeral": 0, "disk": 10, "id": "54eb939a-a39a-40ae-b50c-ed69b9f565ba", "links": [ { "href": "http://192.168.30.10:8774/v2.1/flavors/54eb939a-a39a-40ae-b50c-ed69b9f565ba", "rel": "self" }, { "href": "http://192.168.30.10:8774/flavors/54eb939a-a39a-40ae-b50c-ed69b9f565ba", "rel": "bookmark" } ], "name": "tg", "os-flavor-access:is_public": true, "ram": 256, "rxtx_factor": 1.0, "swap": "", "vcpus": 1 } }
List all flavors using OpenStack API
Run the below cURL
command to list all the flavors available for the user:
$ curl -s -X GET http://192.168.30.10:8774/v2.1/flavors -H "Accept: application/json" -H "X-Auth-Token: $TOKEN" | python -m json.tool
Output:
{ "flavors": [ { "id": "0", "links": [ { "href": "http://192.168.30.10:8774/v2.1/flavors/0", "rel": "self" }, { "href": "http://192.168.30.10:8774/flavors/0", "rel": "bookmark" } ], "name": "m1.small" }, ... ... ... { "id": "54eb939a-a39a-40ae-b50c-ed69b9f565ba", "links": [ { "href": "http://192.168.30.10:8774/v2.1/flavors/54eb939a-a39a-40ae-b50c-ed69b9f565ba", "rel": "self" }, { "href": "http://192.168.30.10:8774/flavors/54eb939a-a39a-40ae-b50c-ed69b9f565ba", "rel": "bookmark" } ], "name": "tg" } ] }
List a flavor based on ID using OpenStack API
Run the below cURL command to list a specific flavor based on ID:
$ curl -s -X GET http://192.168.30.10:8774/v2.1/flavors/<ID> -H "Accept: application/json" -H "X-Auth-Token: $TOKEN" | python -m json.tool
Where <ID> is the flavor ID.
Output:
{ "flavor": { "OS-FLV-DISABLED:disabled": false, "OS-FLV-EXT-DATA:ephemeral": 0, "disk": 20, "id": "0", "links": [ { "href": "http://192.168.30.10:8774/v2.1/flavors/0", "rel": "self" }, { "href": "http://192.168.30.10:8774/flavors/0", "rel": "bookmark" } ], "name": "m1.small", "os-flavor-access:is_public": true, "ram": 2048, "rxtx_factor": 1.0, "swap": "", "vcpus": 1 } }
Delete a flavor using OpenStack API
Run the below cURL
command to delete a flavor based on ID:
$ curl -s -X DELETE http://192.168.30.10:8774/v2.1/flavors/<ID> -H "Accept: application/json" -H "X-Auth-Token:$TOKEN"
Where <ID> is the flavor ID.
Output: Nothing
Refer to OpenStack API documentation for more information. That’s it! Meet you in the next tutorial.