OpenStack Neutron Client (Deprecated)

11.8.0 · deprecated · verified Wed Apr 15

python-neutronclient is a client library for the OpenStack Networking (Neutron) API. It provides Python API bindings and previously included a command-line interface. As of version 11.8.0, the project is deprecated; its CLI code has been removed, and no new features will be added. All new development and migrations under OpenStack governance are directed towards using OpenStackSDK and OpenStack Client.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with OpenStack Keystone using environment variables and then initialize the Neutron client to list networks. It uses `keystoneauth1` for robust session management.

import os
from keystoneauth1 import identity
from keystoneauth1 import session
from neutronclient.v2_0 import client

# Set these environment variables or replace with actual values
OS_AUTH_URL = os.environ.get('OS_AUTH_URL', 'http://auth.example.com:5000/v3')
OS_USERNAME = os.environ.get('OS_USERNAME', 'your_username')
OS_PASSWORD = os.environ.get('OS_PASSWORD', 'your_password')
OS_PROJECT_NAME = os.environ.get('OS_PROJECT_NAME', 'your_project_name')
OS_USER_DOMAIN_NAME = os.environ.get('OS_USER_DOMAIN_NAME', 'Default')
OS_PROJECT_DOMAIN_NAME = os.environ.get('OS_PROJECT_DOMAIN_NAME', 'Default')

# Authenticate using Keystone v3 password flow
auth = identity.Password(
    auth_url=OS_AUTH_URL,
    username=OS_USERNAME,
    password=OS_PASSWORD,
    project_name=OS_PROJECT_NAME,
    user_domain_name=OS_USER_DOMAIN_NAME,
    project_domain_name=OS_PROJECT_DOMAIN_NAME
)
sess = session.Session(auth=auth)

# Create a Neutron client instance
neutron_client = client.Client(session=sess)

# Example: List networks
try:
    networks = neutron_client.list_networks()
    print("Networks:")
    for net in networks['networks']:
        print(f"  - {net['name']} ({net['id']})")
except Exception as e:
    print(f"Error listing networks: {e}")

view raw JSON →