Openstack python-novaclient

Openstack python-novaclient

我正在尝试使用这个玩具代码来启动 python-novaclient 库

#!/usr/bin/python

from novaclient.client import Client


   nova = Client(2, "####", "####", "####" , "####:8774/v2.0")
   _test = nova.images.list()

   print _test

但我总是得到这个错误:

有人知道这可能是什么问题吗?

您正在使用 python-novaclient 作为一个库,它从来没有被设计成这样使用。不幸的是,人们将其用作库的 CLI。

试用官方 Python OpenStack SDK。

pip install openstacksdk

列出图片的代码。

import sys

from openstack import connection
from openstack import profile
from openstack import utils

utils.enable_logging(True, stream=sys.stdout)

prof = profile.Profile()
prof.set_region(prof.ALL, "RegionOne")

conn = connection.Connection(
    auth_url='https://my.identity.endpoint/v2.0/',
    profile=prof,
    username="my_username",
    password="my_password")

for image in conn.compute.images():
    print(image)

更多可能也有帮助的信息:

你只需要一个很好的例子,请参考:http://docs.openstack.org/developer/python-novaclient/api.html

>>> from novaclient import client
>>> nova = client.Client(VERSION, USERNAME, PASSWORD, PROJECT_ID, AUTH_URL)

特别是,如果你的用户名是admin,密码是password,项目名称是admin,keystone端点是http://127.0.0.1:5000,那么它应该是

>>> nova = client.Client(2, 'admin', 'password', 'admin', 'http://127.0.0.1:5000')

请注意,auth url 是 keystone 端点,而不是 nova 端点。