背景
隨著OpenStack不斷發(fā)展, 目前的MITAKA版本的keystone已經(jīng)棄用了第二版本的身份認(rèn)證API, 而且我在M版本下使用原來(lái)版本的keystoneclient時(shí), 發(fā)現(xiàn)提示如下
DeprecationWarning: keystoneclient auth plugins are deprecated as of the 2.1.0 release in favor of keystoneauth1 plugins. They will be removed in future releases.
因此, 在Mitaka版本中使用keystoneclient已不可取, 而且第三版的身份認(rèn)證API和第二代有比較大的不同.
Keystone第三版身份認(rèn)證相關(guān)參數(shù)
只涉及到
project_domain: 項(xiàng)目域
project_name:項(xiàng)目(租戶)
user_domain_name:用戶域
username:用戶名
password:密碼
auth_url:認(rèn)證地址, "http://controller:5000/v3/"
region: 區(qū)域, Regions之間完全隔離,但它們共享同一個(gè)Keystone和Dashboard服務(wù)
auth_plugin: 認(rèn)證方式, "password"
其中, 高亮部分為必須參數(shù),其余為可選參數(shù)
在代碼中直接指定相關(guān)參數(shù)
def create_connection(project_domain_name, user_domain_name, auth_url, region, project_name, username, password):
prof = profile.Profile()
prof.set_region(profile.Profile.ALL, region)
return connection.Connection(
profile=prof,
user_agent='Autumn',
project_domain_name=project_domain_name,
user_domain_name=user_domain_name,
auth_url=auth_url,
project_name=project_name,
username=username,
password=password
)
def list_images(conn):
print("List Images:")
for image in conn.image.images():
print(image)
if __name__ == '__main__':
auth_args = {
'project_domain_name':'default',
'user_domain_name':'default',
'auth_url': 'http://127.0.0.1:5000/v3',
'region':'RegionOne',
'project_name': 'admin',
'username': 'admin',
'password': 'password',
}
conn = create_connection(**auth_args)
list_images(conn)
從文件中給定相關(guān)參數(shù)
新建cloud.yaml, 并加載cloud.ymal
$ export OS_CLIENT_CONFIG_FILE=/yourPath/clouds.yaml
cloud.yaml
clouds:
test_cloud:
region_name: RegionOne
auth:
auth_url: http://127.0.0.1:5000/v3/
username: admin
password: password
project_name: admin
domain_name: default
TEST_CLOUD = os.getenv('OS_TEST_CLOUD', 'test_cloud')
class Opts(object):
def __init__(self, cloud_name='test_cloud', debug=False):
self.cloud = cloud_name
self.debug = debug
self.identity_api_version = '3'
opts = Opts(cloud_name=TEST_CLOUD)
occ = os_client_config.OpenStackConfig()
cloud = occ.get_one_cloud(opts.cloud, argparse=opts)
def list_images(conn):
print("List Images:")
for image in conn.image.images():
print(image)
list_images(connection.from_config(cloud_config=cloud, options=opts))