Change-Id: Ia74056fddf413f1f2ee03fa9df6431a25b0bca28 Closes-Bug: #1472841
3.4 KiB
Authenticate against a Compute endpoint
To authenticate against a Compute endpoint, instantiate a novaclient.v_1_1.client.Client object:
from os import environ as env
import novaclient.v1_1.client as nvclient
= nvclient.Client(auth_url=env['OS_AUTH_URL'],
nova =env['OS_USERNAME'],
username=env['OS_PASSWORD'],
api_key=env['OS_TENANT_NAME'],
project_id=env['OS_REGION_NAME']) region_name
Alternatively, you can instantiate a
novaclient.client.Client
object and pass the version
number:
from os import environ as env
import novaclient.client
= novaclient.client.Client("1.1", auth_url=env['OS_AUTH_URL'],
nova =env['OS_USERNAME'],
username=env['OS_PASSWORD'],
api_key=env['OS_TENANT_NAME'],
project_id=env['OS_REGION_NAME']) region_name
If you authenticate against an endpoint that uses a custom authentication back end, you must load the authentication plug-in and pass it to the constructor.
The Rackspace public cloud is an OpenStack deployment that uses a
custom authentication back end. To authenticate against this cloud, you
must install the rackspace-novaclient
library that contains the Rackspace authentication plug-in, called
rackspace
. The following Python code shows the additional
modifications required to instantiate a Client
object that
can authenticate against the Rackspace custom authentication back
end.
import novaclient.auth_plugin
import novaclient.v1_1.client as nvclient
from os import environ as env
= 'rackspace'
auth_system = novaclient.auth_plugin.load_plugin('rackspace')
auth_plugin = nvclient.Client(auth_url=env['OS_AUTH_URL'],
nova =env['OS_USERNAME'],
username=env['OS_PASSWORD'],
api_key=env['OS_TENANT_NAME'],
project_id=env['OS_REGION_NAME'],
region_name='rackspace',
auth_system=auth_plugin) auth_plugin
If you set the OS_AUTH_SYSTEM
environment variable,
check for this variable in your Python script to determine whether you
need to load a custom authentication back end:
import novaclient.auth_plugin
import novaclient.v1_1.client as nvclient
from os import environ as env
= env.get('OS_AUTH_SYSTEM', 'keystone')
auth_system if auth_system != "keystone":
= novaclient.auth_plugin.load_plugin(auth_system)
auth_plugin else:
= None
auth_plugin = nvclient.Client(auth_url=env['OS_AUTH_URL'],
nova =env['OS_USERNAME'],
username=env['OS_PASSWORD'],
api_key=env['OS_TENANT_NAME'],
project_id=env['OS_REGION_NAME'],
region_name=auth_system,
auth_system=auth_plugin) auth_plugin