openstack-manuals/doc/user-guide/section_sdk_auth_neutron.xml
Christian Berendt 6be4f5775f Unified the syntax of the XML root element (user-guide)
The XML root element of Docbook XML files should match the following
format:

<ELEMENT 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="THE_XML_ID_OF_THE_ELEMENT">

Change-Id: Ic59684221ba99632c71e3f9b5f97ec74f56793a4
2014-07-09 19:51:07 +02:00

33 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>