使用 openstack API 和 shell 脚本检索网络 ID

retrieve id of the network with openstack API and shell script

我需要检索使用 shell 脚本和 openstack API 创建的网络的 ID。有办法吗?

neutron net-create test-net --provider:network_type vlan --provider:physical_network physnet2 --provider:segmentation_id 22  
neutron subnet-create test-net --name test-subnet --allocation-pool start=10.153.9.20,end=10.153.9.34 --gateway 10.153.8.1 10.153.8.0/22

您可以 neutron net-list[1]tenant_id 作为参数,然后通过管道将对 grep 的响应通过其名称选择您想要的网络

neutron --os-tenant-id {tenant_id} net-list | grep {network_name}

你会得到这样的回应

| {network_id} | {network_name} | {subnets} |