简体   繁体   English

OpenStack Python-novaclient

[英]Openstack python-novaclient

I'm trying this toy code to initiate myself to the python-novaclient lib 我正在尝试此玩具代码以将自己初始化为python-novaclient lib

#!/usr/bin/python

from novaclient.client import Client


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

   print _test

but I always get this error: 但我总是得到这个错误:

在此处输入图片说明

does anyone know what kind of problem this could be? 有谁知道这可能是什么问题?

You're using the python-novaclient as a library and it was never designed to be used that way. 您将python-novaclient用作库,并且从未设计过以这种方式使用它。 It's a CLI that people unfortunately use as a library. 这是一个让人遗憾地用作库的CLI。

Give the official Python OpenStack SDK a try. 尝试使用官方的Python OpenStack SDK。

pip install openstacksdk

The code for listing images. 列出图像的代码。

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)

More info that might be helpful too: 更多信息可能也有帮助:

you just need a good example, please refer to: http://docs.openstack.org/developer/python-novaclient/api.html 您只需要一个很好的例子,请参考: http : //docs.openstack.org/developer/python-novaclient/api.html

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

particularly, if your username is admin, password is password, project name is admin, keystone endpoint is http://127.0.0.1:5000 , then it should be 特别是,如果您的用户名是admin,密码是password,项目名称是admin,keystone端点是http://127.0.0.1:5000 ,则它应该是

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

note that auth url is keystone endpoint, NOT nova endpoint. 请注意,auth url是主要终结点,而不是nova终结点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM