Neutron Command Line API
The Neutron client is the command-line interface (CLI) for the OpenStack Network API and its extensions.
It is same as nova client and any other OpenStack APIs, you need to authenticate before you can use it. Please refer the Networking Getting Started article to see how to get authenticated.
Please also refer to Networking Getting Started for how to install the Neutron client.
The below shows some Neutron commands:
|list all networks that belong to a given tenant|
|list all security groups|
|create a security group|
|list all subnet that belong to a given tenant|
|delete a subnet|
|show information of a given subnet|
The below shows an example about how to create a subnet:
network name: network id or name this subnet belongs to, example: my-network
CIDR: CIDR of subnet to create, example: 192.168.1.0/24
name: name of the subnet, example: my-subnet
ip-version (4,6): IP version with default 4.
gateway: gateway IP of this subnet, example: 192.168.1.1
no-gateway: no distribution of gateway
dns-nameserver: DNS name server for this subnet (This option can be repeated), example: 192.168.0.1
disable-dhcp: Disable DHCP for this subnet
To create a subnet:
neutron subnet-create my-network 192.168.1.0/24 --gateway 192.168.1.1
You can execute
neutron help to see what commands are available and run
neutron help <command> find out more information about a command.
Neutron Python Client
You can also use Neutron python API to access and manage the networking.
Sample Python code:
from neutronclient.v2_0 import client username='adminUser' password='secretword' project_name='openstackDemo' auth_url='http://192.168.206.130:5000/v3/' neutron = client.Client(username=username, password=password, project_name=project_name, auth_url=auth_url) nets = neutron.list_networks() sub_nets = neutron.list_subnets()
The above authurl, user, password and tenant_name are only for demonstration purpose. Please refer to instruction for how to obtain authurl, user, password and tenant_name.
Some commands are listed as below:
|list all networks|
|list all sub networks|
|list all ports|
|create a new subnet|
|upload data to the container|
|update an exisitng network|
Please refer to the Neutron python client document for more information. You can also read the source file in /usr/lib/python2.7/dist-packages/neutronclient/v2_0/client.py (for Ubuntu) to get the completed list of what methods you can call.