Authenticate

翻译 2015年11月18日 10:50:35

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

相关文章推荐

Cvsnt 的问题authenticate

  • 2008年12月23日 21:38
  • 52B
  • 下载

www-authenticate与BASE-64认证技术

www-authenticate是一种简单的用户身份认证技术。很多验证都采用这种验证方式,尤其在嵌入式领域中。优点:方便缺点:这种认证方式在传输过程中采用的用户名密码加密方式为BASE-64,其解码过...
  • undoner
  • undoner
  • 2015年08月28日 12:53
  • 727

MIDP 2.0_Certification_Authenticate

  • 2013年01月17日 23:03
  • 618KB
  • 下载

【HTTP】http 401Basic验证和WWW-Authenticate、Authorization

http 401Basic验证和WWW-Authenticate、Authorization

用来 authenticate 的 Directives

authenticate 这个Directives   使用了http的 WWW-Authenticate 来实现认证的功能,这个没怎用,百度了下 http://blog.163.com/h...

java.lang.SecurityException: JCE cannot authenticate the provider BC

JCE cannot authenticate the provider BC

JCE cannot authenticate the provider CryptixCrypto

PGP项目结构目录: PGP解密工具类: import java.io.ByteArrayInputStream; import java.io.IOException; import...

spring--data-mongondb ...CannotGetMongoDbConnectionException: Failed to authenticate to database

HTTP Status 500 - Request processing failed; nested exception is org.springframework.data.mongodb.Ca...

IOS: How to authenticate the GKLocalPlayer on my 'third party server'.

参考:http://stackoverflow.com/questions/17408729/how-to-authenticate-the-gklocalplayer-on-my-third-par...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Authenticate
举报原因:
原因补充:

(最多只允许输入30个字)