我尝试从 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 客户端获取有关实例(运行/终止事件)的通知?