gnocchixyz / python-gnocchiclient

Python client from Gnocchi
http://gnocchi.xyz/gnocchiclient
Apache License 2.0
13 stars 29 forks source link

gnocchi python api openstack authentication failed #103

Closed universcom closed 1 year ago

universcom commented 5 years ago

hi I want use python api for openstack keystone i use auth model keystone like:

from keystoneauth1 import loading from oslo_config import cfg from gnocchiclient import auth from gnocchiclient.v1 import client

conf = cfg.ConfigOpts() auth_plugin = loading.load_auth_from_conf_options(conf, "gnocchi_credentials") gnocchi = client.Client(session_options={'auth': auth_plugin}) gnocchi.resource.list("generic")

i get error:

oslo_config.cfg.NoSuchOptError: no such option gnocchi_credentials in group [DEFAULT]

please help me to run python api. it is very necessary for me. tanks a lot

tobias-urdin commented 1 year ago

Closing as this was never answered, sorry about that. Passing an alternative below for anybody landing here in the future.

from keystoneauth1.identity import v3
from keystoneauth1 import session
from gnocchiclient.client import Client

auth = v3.Password(auth_url=os.environ.get('OS_AUTH_URL'),
                   project_domain_name=os.environ.get('OS_PROJECT_DOMAIN_NAME'),
                   user_domain_name=os.environ.get('OS_USER_DOMAIN_NAME'),
                   username=os.environ.get('OS_USERNAME'),
                   project_name=os.environ.get('OS_PROJECT_NAME'),
                   password=os.environ.get('OS_PASSWORD'))

sess = session.Session(auth=auth)
gnocchi = Client('1', session=sess)
Nils98Ar commented 1 year ago

This way the credentials from /etc/openstack/clouds.yml and /etc/openstack/secure.yml are used:

import openstack
from keystoneauth1.identity import v3
from keystoneauth1 import session
from gnocchiclient.v1 import client

# Choose cloud
os_cloud = "admin"

# Login via /etc/openstack/clouds.yml and /etc/openstack/secure.yml
conn = openstack.connect(cloud=os_cloud)
auth = v3.Password(auth_url=conn.auth["auth_url"],
                   project_domain_name=conn.auth["project_domain_name"],
                   user_domain_name=conn.auth["user_domain_name"],
                   username=conn.auth["username"],
                   project_name=conn.auth["project_name"],
                   password=conn.auth["password"])
sess = session.Session(auth=auth)
gnocchi = client.Client(session=sess)

# Test request
gnocchi.resource.list("generic")