watcherclient Python API

watcherclient python API 允许您访问 watcher,OpenStack TODEFINE 服务。

例如,要操作审计,您将与 watcherclient.v1.audit 对象交互。您可以通过 watcherclient.v1.client.Client 对象的属性访问审计。

用法

获取 Client 对象

首先,通过将您的凭据传递给 watcherclient.client.get_client() 来创建一个 watcherclient.v1.client.Client 实例。默认情况下,Watcher 系统配置为只有管理员(具有“admin”角色的用户)才能访问。

可以使用两组不同的凭据

* watcher endpoint and auth token
* Identity Service (keystone) credentials

使用 watcher 端点和认证令牌

可以使用认证令牌和 watcher 端点进行身份验证

* os_auth_token: authentication token (from Identity Service)
* watcher_url: watcher API endpoint, eg http://watcher.example.org:9322/v1

要创建客户端,可以使用如下 API

>>> from watcherclient import client
>>>
>>> kwargs = {'os_auth_token': '3bcc3d3a03f44e3d8377f9247b0ad155'
>>>           'watcher_url': 'http://watcher.example.org:9322/'}
>>> watcher = client.get_client(1, **kwargs)

使用身份服务 (keystone) 凭据

这些身份验证服务凭据可用于身份验证

* os_username: name of user
* os_password: user's password
* os_auth_url: Identity Service endpoint for authorization
* os_tenant_{name|id}: name or ID of tenant

要创建客户端,可以使用如下 API

>>> from watcherclient import client
>>>
>>> kwargs = {'os_username': 'name',
>>>           'os_password': 'password',
>>>           'os_auth_url': 'http://keystone.example.org:5000/',
>>>           'os_tenant_name': 'tenant'}
>>> watcher = client.get_client(1, **kwargs)

执行 watcher 操作

一旦您拥有 watcher Client,您就可以执行各种任务

>>> watcher.action.list()  # list of actions
>>> watcher.action_plan.list()  # list of action_plan
>>> watcher.audit.get(audit_uuid_or_name)  # information about a particular audit

Client 需要传播异常时,它通常会引发 watcherclient.exceptions 中列出的实例。

有关更多详细信息,请参阅模块本身。

watcherclient 模块