openstack-manuals/doc/user-guide/section_sdk_auth_neutron.xml
Lorin Hochstein 689de3f4e8 Add initial Python SDK docs to user guide
Initial addition of Python SDK content to user's guide. Describes
how an end-user can employ the Python bindings to automate tasks.

This initial commit adds info on:
 - How to authenticate with Identity, Commpute, Image, and Network
   clients
 - How to manage images

Change-Id: Ie8c4120acc7739c0bc4bddd99ffdbfbfbe241e0f
2013-12-30 11:02:57 -06:00

32 lines
1.6 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<section xmlns="http://docbook.org/ns/docbook"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0"
xml:id="sdk_auth_neutron">
<title>Authenticate against a Networking endpoint</title>
<para>To authenticate against a Networking endpoint, instantiate a
<classname>neutronclient.v_2_0.client.Client</classname>
object:</para>
<programlisting language="python">from os import environ as env
from neutronclient.v2_0 import client as neutronclient
neutron = neutronclient.Client(auth_url=env['OS_AUTH_URL'],
username=env['OS_USERNAME'],
password=env['OS_PASSWORD'],
tenant_name=env['OS_TENANT_NAME'],
region_name=env['OS_REGION_NAME'])</programlisting>
<para>You can also authenticate by explicitly specifying the
endpoint and token:</para>
<programlisting language="python">from os import environ as env
import keystoneclient.v2_0.client as ksclient
from neutronclient.v2_0 import client as neutronclient
keystone = ksclient.Client(auth_url=env['OS_AUTH_URL'],
username=env['OS_USERNAME'],
password=env['OS_PASSWORD'],
tenant_name=env['OS_TENANT_NAME'],
region_name=env['OS_REGION_NAME'])
endpoint_url = keystone.service_catalog.url_for(service_type='network')
token = keystone.auth_token
neutron = neutronclient.Client(endpoint_url=endpoint_url, token=token)</programlisting>
</section>