Description

This article provides a configuration example for creating VNs without using WebUI, from REST API.

Solution

An example of how to create a virtual network using REST API is shown below. The created VN is named "VN-A" and has a subnet of 10.1.0.0/24 in project "demo". 

Create VN using REST API:

curl -X POST -H "Content-Type: application/json" -H "X-Auth-Token:$(openstack token issue | awk '/ id / {print $4}')" -d '{"virtual-network": {"parent_type": "project", "fq_name": ["default-domain", "demo", "VN-purple"], "network_ipam_refs": [{"attr": {"ipam_subnets": [{"subnet": {"ip_prefix": "10.1.0.0", "ip_prefix_len": 24}}]}, "to": ["default-domain", "default-project", "default-network-ipam"]}]}}' http://10.219.95.110:8082/virtual-networks | python -m json.tool
 
{
"virtual-network": {
"fq_name": [
"default-domain",
"demo",
"VN-purple"
],
"href": "http://10.219.95.110:8082/virtual-network/fa8e41bb-9807-4a2a-8b62-5f32ca5475a9",
"name": "VN-purple",
"parent_href": "http://10.219.95.110:8082/project/b67071a2-f890-4874-b7af-3640c927dabc",
"parent_type": "project",
"parent_uuid": "b67071a2-f890-4874-b7af-3640c927dabc",
"uuid": " fa8e41bb-9807-4a2a-8b62-5f32ca5475a9 "
}
}

Verification using the uuid in the above output:
curl -X GET -H "Content-Type: application/json; charset=UTF-8" -H "X-Auth-Token:$(openstack token issue | awk '/ id / {print $4} ')" http://10.219.95.110:8082/virtual-network/fa8e41bb-9807-4a2a-8b62-5f32ca5475a9 | python -m json.tool
 
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1629 100 1629 0 0 123k 0 --:--:-- --:--:-- --:--:-- 132k
 
{
"virtual-network": {
"display_name": "VN-purple",
"fq_name": [
"default-domain",
"demo",
"VN-purple"
],
"href": "http://10.219.95.110:8082/virtual-network/fa8e41bb-9807-4a2a-8b62-5f32ca5475a9",
"id_perms": {
"created": "2022-03-09T11:02:19.417045",
"creator": null,
"description": null,
"enable": true,
"last_modified": "2022-03-09T11:02:19.417045",
"permissions": {
"group": "cloud-admin-group",
"group_access": 7,
"other_access": 7,
"owner": "cloud-admin",
"owner_access": 7
},
"user_visible": true,
"uuid": {
"uuid_lslong": 10043694790737163689,
"uuid_mslong": 18054440230140201514
}
},
"name": "VN-purple",
"network_ipam_refs": [
{
"attr": {
"ipam_subnets": [
{
"default_gateway": "10.1.0.254",
"dns_server_address": "10.1.0.253",
"subnet": {
"ip_prefix": "10.1.0.0",
"ip_prefix_len": 24
},
"subnet_uuid": "588c8f14-4c53-433b-aa66-ed9bfc90eebb"
}
]
},
"href": "http://10.219.95.110:8082/network-ipam/b6aafe0d-1fd5-481e-993f-4eaa86e6ff3d",
"to": [
"default-domain",
"default-project",
"default-network-ipam"
],
"uuid": "b6aafe0d-1fd5-481e-993f-4eaa86e6ff3d"
}
],
"parent_href": "http://10.219.95.110:8082/project/b67071a2-f890-4874-b7af-3640c927dabc",
"parent_type": "project",
"parent_uuid": "b67071a2-f890-4874-b7af-3640c927dabc",
"perms2": {
"global_access": 0,
"owner": "b67071a2f8904874b7af3640c927dabc",
"owner_access": 7,
"share": []
},
"routing_instances": [
{
"href": "http://10.219.95.110:8082/routing-instance/50376248-6392-407a-a742-da8d78514944",
"to": [
"default-domain",
"demo",
"VN-purple",
"VN-purple"
],
"uuid": "50376248-6392-407a-a742-da8d78514944"
}
],
"uuid": "fa8e41bb-9807-4a2a-8b62-5f32ca5475a9",
"virtual_network_network_id": 17
}
}

Note: The above request is executed from OpenStack Controller aka a Kolla toolbox  in an Anisble based setup. In an RHOSP based setup, the same has to be run from Director or client facing the external API.
Refer to the REST API reference guide