关闭

Authenticate

112人阅读 评论(0) 收藏 举报
分类:

Authenticate against an Identity endpoint

To authenticate against the Identity v2.0 endpoint, instantiate a keystoneclient.v_20.client.Client object:

为通过 Identity v2.0 endpoint 认证,需要创建一个 keystoneclient.v_20.client.Client 对象。

from os import environ as env
import keystoneclient.v2_0.client as ksclient
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'])

After you instantiate a Client object, you can retrieve the token by accessing itsauth_token attribute object:

可以查看token通过上面创建的对象。

print keystone.auth_token

Authenticate against an Image service endpoint

To authenticate against an Image service endpoint, instantiate aglanceclient.v2.client.Client object:

通过Image服务认证,需要创建 glanceclient.v2.client.Client 对象。

from os import environ as env
import glanceclient.v2.client as glclient
import keystoneclient.v2_0.client as ksclient

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'])
glance_endpoint = keystone.service_catalog.url_for(service_type='image')
glance = glclient.Client(glance_endpoint, token=keystone.auth_token)

Authenticate against a Compute endpoint

To authenticate against a Compute endpoint, instantiate anovaclient.v_1_1.client.Client object:

<span style="font-size:14px;">from os import environ as env
import novaclient.v1_1.client as nvclient

nova = nvclient.Client(auth_url=env['OS_AUTH_URL'],
                       username=env['OS_USERNAME'],
                       api_key=env['OS_PASSWORD'],
                       project_id=env['OS_TENANT_NAME'],
                       region_name=env['OS_REGION_NAME'])</span>

Alternatively, you can instantiate a novaclient.client.Client object and pass the version number:

或者,创建不写版本号 novaclient.client.Client对象

from os import environ as env
import novaclient.client
nova = novaclient.client.Client("1.1", auth_url=env['OS_AUTH_URL'],
                                username=env['OS_USERNAME'],
                                api_key=env['OS_PASSWORD'],
                                project_id=env['OS_TENANT_NAME'],
                                region_name=env['OS_REGION_NAME'])

Compute 的验证版本是V1.1,这个版本太老,今后将不支持使用,所以运行会有如下警告:

python auth_compute.py 
Version 1.1 is deprecated, using alternative version 2 instead. 

解决方法:查看现有的版本号,改上面的版本号即可

Authenticate against a Networking endpoint

To authenticate against a Networking endpoint, instantiate a neutronclient.v_2_0.client.Client object:

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'])

You can also authenticate by explicitly specifying the endpoint and token:

或者明确的指定 endpoint 和 token。

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)



详情见:

http://docs.openstack.org/user-guide/sdk_authenticate_against_identity_endpoint.html

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:326次
    • 积分:53
    • 等级:
    • 排名:千里之外
    • 原创:1篇
    • 转载:0篇
    • 译文:4篇
    • 评论:0条
    文章存档