獲取OpenStack Mitaka認(rèn)證的兩種方式

背景

隨著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))
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容