I'm trying this toy code to initiate myself to the 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. It's a CLI that people unfortunately use as a library.
Give the official Python OpenStack SDK a try.
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
>>> 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
>>> nova = client.Client(2, 'admin', 'password', 'admin', 'http://127.0.0.1:5000')
note that auth url is keystone endpoint, NOT nova endpoint.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.