gpt4 book ai didi

python - OpenStack Ceilometer 客户端出现问题

转载 作者:太空宇宙 更新时间:2023-11-03 18:57:51 29 4
gpt4 key购买 nike

我尝试从 OpenStack 获取仪表和通知。为此,我想使用 Ceilometer (通过 ceilometerclient)。我编写了一些代码来测试这些可能性。

import keystoneclient.v2_0
import ceilometerclient.v2 as ceilometer

class CloudMessageHandler(object):

def __init__(self, params):

self._client = None
self._auth_data = self._get_token(params["auth"])
try:
print "auth_data = %s" % repr(self._auth_data)
self._client = ceilometer.Client(endpoint=self._auth_data['endpoint'],
token=self._auth_data['token'])
except:
raise Exception("Can't create Ceilometer client.")

def _get_token(self, params):
try:
ksclient = keystoneclient.v2_0.Client(username=params["username"],
password=params["password"],
tenant_id=params["tenant_id"],
tenant_name=params["tenant_name"],
auth_url=params["auth_url"])
token = ksclient.auth_token
endpoint = ksclient.service_catalog.url_for(service_type="metering",
endpoint_type=params["endpoint_type"])
return { "token" : token, "endpoint" : endpoint }
except IndexError as e:
raise Exception("Can't get token and endpoint through Keystone API.")

def test(self):
print "meters = %s" % self._client.meters.list()
print "resources = %s" % self._client.resources.list()
print "alarms = %s" % self._client.alarms.list()

我得到的输出:

auth_data = {'token': u'xxx', 'endpoint': u'http://ip:port'}
meters = []
resources = []
No handlers could be found for logger "ceilometerclient.common.http"
Traceback (most recent call last):
...
File "/usr/local/lib/python2.7/dist-packages/ceilometerclient/v2/alarms.py", line 53, in list
return self._list(options.build_url(self._path(), q))
File "/usr/local/lib/python2.7/dist-packages/ceilometerclient/common/base.py", line 57, in _list
resp, body = self.api.json_request('GET', url)
File "/usr/local/lib/python2.7/dist-packages/ceilometerclient/common/http.py", line 182, in json_request
resp, body_iter = self._http_request(url, method, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/ceilometerclient/common/http.py", line 165, in _http_request
raise exc.from_response(resp)
ceilometerclient.exc.HTTPNotFound: HTTPNotFound (HTTP 404)

怎么了?我也无法创建警报。谁能给我一个例子,如何通过 Ceilometer 客户端获取有关实例(运行/终止事件)的通知?

最佳答案

我尝试调试地平线,

from ceilometerclient.v2 import Client as ceil_client
from keystoneclient.v2_0.client import Client as KC


def get_token():
kc = KC(username="admin", password="111111", tenant_name="admin", auth_url="http://192.168.176.101:5000/v2.0")
token = kc.service_catalog.catalog['token']['id']
return token

ceil = ceil_client(endpoint='http://XXX.XXX.XXX.:8777', token=get_token)

它有效!Horizo​​n使用的端点端口是8777,我不知道你用的是什么,也许会对你有帮助!

关于python - OpenStack Ceilometer 客户端出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16882683/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com