ironicclient Python API

ironicclient python API 允许您访问 ironic,OpenStack 裸机配置服务。

例如,要操作节点,您将与 ironicclient.v1.node.Node 对象交互。您可以通过 ironicclient.v1.client.Client 对象的属性访问节点。

用法

获取 Client 对象

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

注意

显式实例化 ironicclient.v1.client.Client 可能会导致错误,因为它不会验证提供的参数,使用 ironicclient.client.get_client() 是获取客户端对象的首选方法。

可以使用两组不同的凭据

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

使用 ironic 端点和 auth token

可以使用 auth token 和 ironic 端点进行身份验证

* os_auth_token: authentication token (from Identity Service)
* ironic_url: ironic API endpoint, eg http://ironic.example.org:6385/v1

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

>>> from ironicclient import client
>>>
>>> kwargs = {'os_auth_token': '3bcc3d3a03f44e3d8377f9247b0ad155',
>>>           'ironic_url': 'http://ironic.example.org:6385/'}
>>> ironic = client.get_client(1, **kwargs)

使用 Identity Service (keystone) 凭据

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

* os_username: name of user
* os_password: user's password
* os_auth_url: Identity Service endpoint for authorization
* insecure: Boolean. If True, does not perform X.509 certificate
  validation when establishing SSL connection with identity
  service. default: False (optional)
* os_tenant_{name|id}: name or ID of tenant

在使用 Identity API v3 时,还需要以下参数

* os_user_domain_name: name of a domain the user belongs to,
  usually 'default'
* os_project_domain_name: name of a domain the project belongs to,
  usually 'default'

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

>>> from ironicclient import client
>>>
>>> kwargs = {'os_username': 'name',
>>>           'os_password': 'password',
>>>           'os_auth_url': 'http://keystone.example.org:5000/',
>>>           'os_project_name': 'project'}
>>> ironic = client.get_client(1, **kwargs)

执行 ironic 操作

一旦您拥有一个 ironicclient.v1.client.Client,您可以执行各种任务

>>> ironic.driver.list()  # list of drivers
>>> ironic.node.list()  # list of nodes
>>> ironic.node.get(node_uuid)  # information about a particular node

当 Client 需要传播异常时,通常会引发从 ironicclient.common.apiclient.exceptions.ClientException 派生的实例。

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

ironicclient 模块