API 指南
使用 Red Hat Satellite Representational State Transfer (REST) API 的指南
Red Hat Satellite Documentation Team
satellite-doc-list@redhat.com
摘要
向红帽文档提供反馈
我们感谢您对文档提供反馈信息。请让我们了解如何改进文档。
您可以通过在 Bugzilla 中记录一个 ticket 来提交反馈:
- 导航到 Bugzilla 网站。
-
在 Component 字段中,使用
Documentation
。 - 在 Description 字段中,输入您要改进的建议。包括文档相关部分的链接。
- 点 Submit Bug。
第 1 章 简介
Red Hat Satellite 提供了一个代表性状态传输(REST) API。API 为软件开发人员和系统管理员提供控制标准 Web 界面之外的 Red Hat Satellite 环境。REST API 对于希望将 Red Hat Satellite 与通过 HTTP 访问 API 的自定义脚本或外部应用程序集成的开发人员和管理员有用。
1.1. Red Hat Satellite API 概述
使用 REST API 的优点包括:
- 广泛的客户端支持 - 任何支持 HTTP 协议的编程语言、框架或系统都可以使用 API。
- 自我处理 - 客户端应用程序需要对 Red Hat Satellite 基础架构有最少的了解,因为用户在运行时发现许多详细信息。
- 基于资源的模型 - 基于资源的 REST 模型提供了管理虚拟化平台的自然方法。
您可以使用 REST API 执行以下任务:
- 与企业 IT 系统集成。
- 与第三方应用程序集成。
- 执行自动化维护或错误检查任务。
- 使用脚本自动执行重复性任务。
当您准备升级 Satellite 服务器时,请确保使用包含 Satellite API 命令的任何脚本都是最新的。API 命令因 Satellite 版本而异。
1.2. Satellite API 与hammer CLI 工具的比较
对于许多任务,您可以使用hammer 和 Satellite API。您可以使用 hammer 作为 Satellite API 的人类可读接口。例如,要在脚本中应用 API 调用前测试对 API 调用的响应,请使用 --debug
选项来检查hammer 问题的 API 调用: hammer --debug organization list
。
在后台,每个hammer 命令首先建立绑定到 API 的绑定,然后发送请求。当按顺序执行大量hammer 命令时,这可能会产生性能影响。相反,使用 API 命令的脚本直接与 Satellite API 通信。
请注意,您必须手动更新使用 API 命令的脚本,而hammer 会自动反映 API 中的更改。有关更多信息,请参阅 Hammer CLI 指南。
第 2 章 API 参考
您的 Satellite 服务器上提供了完整的 API 参考: https://satellite.example.com/apidoc/v2.html
。请注意,即使 Satellite 6 API 的版本 1 和 2 版本可用,红帽只支持版本 2。
2.1. 了解 API 语法
以下示例请求使用 python3
来格式化 Satellite 服务器中的 respone。在 RHEL 7 和一些较旧的系统中,您必须使用 python
而不是 python3
。
内置 API 引用显示 API 路由或路径,前面带有 HTTP 动词:
HTTP_VERB API_ROUTE
要使用 API,请使用 curl
命令语法和参考文档中的 API 路由构建命令:
$ curl --request HTTP_VERB \ 1 --insecure \ 2 --user sat_username:sat_password \ 3 --data @file.json \ 4 --header "Accept:application/json" \ 5 --header "Content-Type:application/json" \ 6 --output file 7 API_ROUTE \ 8 | python3 -m json.tool 9
- 1
- 要将
curl
用于 API 调用,请使用--request
选项指定 HTTP 动词。例如,--request POST
。 - 2
- 添加
--insecure
选项来跳过 SSL 对等证书验证检查。 - 3
- 使用
--user
选项提供用户凭据。 - 4
- 5 6
- 7
- 从 Satellite 服务器下载内容时,请使用
--output
选项指定输出文件。 - 8
- 使用以下格式的 API 路由:
https://satellite.example.com/katello/api/activation_keys
。在 Satellite 6 中,API 的版本 2 是默认值。因此,不需要在 URL 中使用v2
进行 API 调用。 - 9
- 将输出重定向到 Python
json.tool
模块,以便更轻松地读取输出。
2.1.1. 使用 GET HTTP Verb
使用 GET HTTP 动词从 API 中获取有关现有条目或资源的数据。
示例
这个示例请求 Satellite 主机的数量:
请求示例:
$ curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/hosts | python3 -m json.tool
响应示例:
{
"total": 2,
"subtotal": 2,
"page": 1,
"per_page": 20,
"search": null,
"sort": {
"by": null,
"order": null
},
"results":
output truncated
API 的响应表示总有两个结果,这是结果的第一个页面,每个页面的最大结果设置为 20。更多信息请参阅 第 2.2 节 “了解 JSON 响应格式”。
2.1.2. 使用 POST HTTP Verb
使用 POST HTTP 动词向 API 提交数据,以创建条目或资源。您必须使用 JSON 格式提交数据。更多信息请参阅 第 4.1.1 节 “将 JSON 数据传递给 API 请求”。
示例
这个示例创建了一个激活码。
创建包含以下内容的测试文件,如
activation-key.json
:{"organization_id":1, "name":"TestKey", "description":"Just for testing"}
通过应用
activation-key.json
文件中的数据来创建激活码:请求示例:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" --request POST \ --user sat_username:sat_password --insecure \ --data @activation-key.json \ https://satellite.example.com/katello/api/activation_keys \ | python3 -m json.tool
响应示例:
{ "id": 2, "name": "TestKey", "description": "Just for testing", "unlimited_hosts": true, "auto_attach": true, "content_view_id": null, "environment_id": null, "usage_count": 0, "user_id": 3, "max_hosts": null, "release_version": null, "service_level": null, "content_overrides": [ ], "organization": { "name": "Default Organization", "label": "Default_Organization", "id": 1 }, "created_at": "2017-02-16 12:37:47 UTC", "updated_at": "2017-02-16 12:37:48 UTC", "content_view": null, "environment": null, "products": null, "host_collections": [ ], "permissions": { "view_activation_keys": true, "edit_activation_keys": true, "destroy_activation_keys": true } }
- 验证是否存在新的激活码。在 Satellite Web UI 中,导航到 Content > Activation keys 来查看您的激活码。
2.1.3. 使用 PUT HTTP Verb
使用 PUT HTTP 动词更改现有值或附加到现有资源。您必须使用 JSON 格式提交数据。更多信息请参阅 第 4.1.1 节 “将 JSON 数据传递给 API 请求”。
示例
本例更新了上例中创建的 TestKey
激活码。
编辑之前创建的
activation-key.json
文件,如下所示:{"organization_id":1, "name":"TestKey", "description":"Just for testing","max_hosts":"10" }
应用 JSON 文件中的更改:
请求示例:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" --request PUT \ --user sat_username:sat_password --insecure \ --data @activation-key.json \ https://satellite.example.com/katello/api/activation_keys/2 \ | python3 -m json.tool
响应示例:
{ "id": 2, "name": "TestKey", "description": "Just for testing", "unlimited_hosts": false, "auto_attach": true, "content_view_id": null, "environment_id": null, "usage_count": 0, "user_id": 3, "max_hosts": 10, "release_version": null, "service_level": null, "content_overrides": [ ], "organization": { "name": "Default Organization", "label": "Default_Organization", "id": 1 }, "created_at": "2017-02-16 12:37:47 UTC", "updated_at": "2017-02-16 12:46:17 UTC", "content_view": null, "environment": null, "products": null, "host_collections": [ ], "permissions": { "view_activation_keys": true, "edit_activation_keys": true, "destroy_activation_keys": true } }
- 在 Satellite Web UI 中,导航到 Content > Activation keys 来验证更改。
2.1.4. 使用 DELETE HTTP Verb
要删除资源,请使用带有 API 路由的 DELETE 动词,其中包含您要删除的资源 ID。
示例
这个示例删除 ID 为 2 的 TestKey
激活码:
请求示例:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" --request DELETE \ --user sat_username:sat_password --insecure \ https://satellite.example.com/katello/api/activation_keys/2 \ | python3 -m json.tool
响应示例:
output omitted "started_at": "2017-02-16 12:58:17 UTC", "ended_at": "2017-02-16 12:58:18 UTC", "state": "stopped", "result": "success", "progress": 1.0, "input": { "activation_key": { "id": 2, "name": "TestKey" output truncated
2.1.5. 与 API 参考相关的 API 错误消息
API 使用 RAILs 格式来指示错误:
Nested_Resource.Attribute_Name
这会转换为 API 引用中使用的以下格式:
Resource[Nested_Resource_attributes][Attribute_Name_id]
2.2. 了解 JSON 响应格式
对 API 的调用返回 JSON 格式的结果。API 调用返回单选项响应或响应集合的结果。
以下示例请求使用 python3
来格式化 Satellite 服务器中的 respone。在 RHEL 7 和一些较旧的系统中,您必须使用 python
而不是 python3
。
单对象的 JSON 响应格式
您可以使用单对象 JSON 响应来使用单个对象。对单个对象的 API 请求需要对象的唯一标识符 :id
。
这是 ID 为 23 的 Satellite 域的单对象请求格式示例:
请求示例:
$ curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/domains/23 | python3 -m json.tool
响应示例:
{ "id": 23, "name": "qa.lab.example.com", "fullname": "QA", "dns_id": 10, "created_at": "2013-08-13T09:02:31Z", "updated_at": "2013-08-13T09:02:31Z" }
集合的 JSON 响应格式
集合是对象列表,如主机和域。集合 JSON 响应的格式由 metadata 字段和 results 部分组成。
这是 Satellite 域列表的集合请求格式示例:
请求示例:
$ curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/domains | python3 -m json.tool
响应示例:
{ "total": 3, "subtotal": 3, "page": 1, "per_page": 20, "search": null, "sort": { "by": null, "order": null }, "results": [ { "id": 23, "name": "qa.lab.example.com", "fullname": "QA", "dns_id": 10, "created_at": "2013-08-13T09:02:31Z", "updated_at": "2013-08-13T09:02:31Z" }, { "id": 25, "name": "sat.lab.example.com", "fullname": "SATLAB", "dns_id": 8, "created_at": "2013-08-13T08:32:48Z", "updated_at": "2013-08-14T07:04:03Z" }, { "id": 32, "name": "hr.lab.example.com", "fullname": "HR", "dns_id": 8, "created_at": "2013-08-16T08:32:48Z", "updated_at": "2013-08-16T07:04:03Z" } ] }
响应元数据字段
API 响应使用以下元数据字段:
-
total
- 没有搜索参数的对象总数。 -
subtotal
- 使用给定搜索参数返回的对象数量。如果没有搜索,则 subtotal 等于 total。 -
Page
- 页面号。 -
per_page
- 每个页面返回的最大对象数。 -
Limit
- 在集合响应中返回的指定对象数量。 -
offset
- 返回集合前跳过的对象数量。 -
search
- 基于scoped_scoped
语法的搜索字符串。 排序
-
by
- 根据 API 排序集合的字段指定。 -
order
- 排序顺序,ASC 代表升序,也可以是 DESC (降序)。
-
-
结果
- 对象的集合。
第 3 章 身份验证 API 调用
与 Satellite API 交互需要与 Satellite 服务器 CA 证书进行 SSL 身份验证,并使用有效的 Satellite 用户凭据进行身份验证。本章概述了您可以使用的身份验证方法。
3.1. SSL 身份验证概述
Red Hat Satellite 使用 HTTPS,它提供了与 Red Hat Satellite Server 通信时的加密和身份验证程度。Satellite 6.11 不支持非 SSL 通信。
每个 Red Hat Satellite 服务器都使用自签名证书。此证书充当服务器证书,以验证加密密钥和证书颁发机构(CA),以信任 Satellite 服务器的身份。
3.1.1. 配置 SSL 身份验证
使用以下步骤为向 Satellite 服务器的 API 请求配置 SSL 身份验证。
流程
使用以下选项之一从您要与之通信的 Satellite 服务器获取证书:
如果您从远程服务器执行命令,请使用 SSH 获取证书:
$ scp root@satellite.example.com:/var/www/html/pub/katello-server-ca.crt /etc/pki/ca-trust/source/anchors/satellite.example.com-katello-server-ca.crt
如果您直接在 Satellite 服务器上执行命令,请将证书复制到
/etc/pki/ca-trust/source/anchors
目录中:$ cp /var/www/html/pub/katello-server-ca.crt /etc/pki/ca-trust/source/anchors/satellite.example.com-katello-server-ca.crt
将证书添加到可信 CA 列表中:
update-ca-trust extract
验证
输入没有
--cacert
选项的 API 请求来验证 NSS 数据库中是否存在证书:$ curl --request GET \ --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts
3.2. HTTP 身份验证概述
对 Satellite API 的所有请求都需要有效的 Satellite 用户名和密码。API 使用 HTTP 基本身份验证对这些凭证进行编码,并添加到 Authorization
标头中。有关基本身份验证的更多信息,请参阅 RFC 2617 HTTP 身份验证: Basic 和 Digest 访问身份验证。如果请求不包含适当的 Authorization
标头,API 会返回 401 Authorization Required
错误
基本身份验证涉及潜在的敏感信息,例如,它会以纯文本形式发送密码。REST API 需要 HTTPS 来传输纯文本请求的传输级别。
有些 base64 库将编码的凭据分成多行,并使用换行符终止每行。这将导致标头无效,并导致请求出现问题。Authorization 标头要求编码的凭证位于标头中的一行中。
3.3. 个人访问令牌身份验证概述
Red Hat Satellite 支持可用于验证 API 请求的个人访问令牌,而不使用您的密码。您可以为个人访问令牌设置过期日期,如果您决定应在过期日期前过期,可以撤销它。
3.3.1. 创建个人访问令牌
使用这个流程创建个人访问令牌。
流程
- 在 Satellite Web UI 中,导航到 Administer > Users。
- 选择您要为其创建个人访问令牌的用户。
- 在 个人访问令牌 选项卡中,单击 Add Personal Access Token。
- 输入个人访问令牌的名称。
- 可选: 选择 过期日期来设置过期日期。如果您没有设置过期日期,您的个人访问令牌将永远不会过期,除非撤销。
点 Submit。现在,您已在个人访问令牌 选项卡中有 个人访问令牌。
重要确保存储您的个人访问令牌,因为您将无法在页面离开或创建新的个人访问令牌后再次访问它。您可以点 Copy to clipboard 复制个人访问令牌。
验证
向 Satellite 服务器发出 API 请求,并使用您的个人访问令牌进行身份验证:
# curl https://satellite.example.com/api/status --user My_Username:My_Personal_Access_Token
您应该收到状态为
200
的响应,例如:{"satellite_version":"6.11.0","result":"ok","status":200,"version":"3.5.1.10","api_version":2}
如果您返回 个人访问令牌 选项卡,您可以看到个人访问令牌旁的更新的 Last Used 时间。
3.3.2. 撤销个人访问令牌
使用这个流程在过期日期前撤销个人访问令牌。
流程
- 在 Satellite Web UI 中,导航到 Administer > Users。
- 选择您要撤销个人访问令牌的用户。
- 在 个人访问令牌 选项卡中,找到您要撤销的个人访问令牌。
- 在您要撤销的个人访问令牌旁边的 Actions 列中点 Revoke。
验证
向 Satellite 服务器发出 API 请求,并尝试使用撤销的个人访问令牌进行身份验证:
# curl https://satellite.example.com/api/status --user My_Username:My_Personal_Access_Token
您会收到以下出错信息:
{ "error": {"message":"Unable to authenticate user My_Username"} }
3.4. OAuth 身份验证概述
作为基本身份验证的替代选择,您可以使用有限的 OAuth 1.0 身份验证。这有时被称为协议版本 1.0a 中的 1 委派 OAuth。
要查看 OAuth 设置,在 Satellite Web UI 中导航至 Administer > Settings > Authentication。OAuth 使用者密钥是 所有 OAuth 客户端要使用的令牌。
Satellite 将 OAuth 设置存储在 /etc/foreman/settings.yaml
文件中。使用 satellite-installer
脚本配置这些设置,因为 Satellite 会升级时覆盖此文件的任何手动更改。
3.4.1. 配置 OAuth
要更改 OAuth 设置,请使用所需选项输入 satellite-installer
。输入以下命令列出所有与 OAuth 相关的安装程序选项:
# satellite-installer --full-help | grep oauth
启用 OAuth 映射
默认情况下,Satellite 将所有 OAuth API 请求授权为内置的匿名 API 管理员帐户。因此,API 响应包括所有 Satellite 数据。但是,您还可以指定向该用户发出请求并限制对数据访问权限的 Foreman 用户。
要启用 OAuth 用户映射,请输入以下命令:
# satellite-installer --foreman-oauth-map-users true
Satellite 不在 OAuth 请求中签署标头。具有有效消费者密钥的任何人都可以模拟任何 Foreman 用户。
3.4.2. OAuth 请求格式
使用 OAuth 客户端库构建所有 OAuth 参数。每个 OAuth API 请求都需要带有现有 Foreman 用户和 Authorization
标头的 FOREMAN-USER
标头,格式为:
--header 'FOREMAN-USER: sat_username' \ --header 'Authorization: OAuth oauth_version="1.0",oauth_consumer_key="secretkey",oauth_signature_method="hmac-sha1",oauth_timestamp=1321473112,oauth_signature=Il8hR8/ogj/XVuOqMPB9qNjSy6E='
示例
本例列出了使用 OAuth 进行身份验证的架构。请求使用 FOREMAN-USER
标头中的 sat_username 用户名。将 --foreman-oauth-map-users
设置为 true
时,响应仅包含用户可访问的架构。签名反映了每个参数、HTTP 方法和 URI 更改。
请求示例:
$ curl 'https://satellite.example.com/api/architectures' \ --header 'Content-Type: application/json' \ --header 'Accept:application/json' \ --header 'FOREMAN-USER: sat_username' \ --header 'Authorization: OAuth oauth_version="1.0",oauth_consumer_key="secretkey",oauth_signature_method="hmac-sha1",oauth_timestamp=1321473112,oauth_signature=Il8hR8/ogj/XVuOqMPB9qNjSy6E='
第 4 章 不同语言中的 API 请求
本章概述了使用 curl、Ruby 和 Python 将 API 请求发送到 Red Hat Satellite,并提供示例。
4.1. 使用 curl 的 API 请求
本节概述了如何将 curl
与 Satellite API 搭配使用来执行各种任务。
Red Hat Satellite 需要使用 HTTPS,默认情况下为主机识别证书。如果您还没有添加 Satellite 服务器证书,如 第 3.1 节 “SSL 身份验证概述” 所述,您可以使用 --insecure
选项来绕过证书检查。
对于用户身份验证,您可以使用 --user
选项以 --user username:password格式提供
Satellite 用户凭据,或者如果您不包含密码,则命令会提示您输入它。要降低安全风险,请不要将密码包含在命令中,因为它随后成为 shell 历史记录的一部分。本节中的示例仅对简单起见的密码。
请注意,如果您使用 --silent
选项,curl
不会显示进度分析器或任何错误消息。
本章中的示例使用 Python json.tool
模块格式化输出。
4.1.1. 将 JSON 数据传递给 API 请求
您可以使用 API 请求将数据传递给 Satellite 服务器。数据必须采用 JSON 格式。当使用 --data
选项指定 JSON 数据时,您必须使用 --header
选项设置以下 HTTP 标头:
--header "Accept:application/json" \ --header "Content-Type:application/json"
使用以下选项之一在 --data
选项中包含数据:
带引号 JSON 格式的数据,用大括号
{}
括起。为 JSON 类型参数传递值时,您必须转义引号"
,使用反斜杠\
。例如,在大括号中,您必须将"Example JSON 变量"格式化为
\"Example JSON Variable\"
:--data {"id":44, "smart_class_parameter":{"override":"true", "parameter_type":"json", "default_value":"{\"GRUB_CMDLINE_LINUX\": {\"audit\":\"1\",\"crashkernel\":\"true\"}}"}}
未加引号的 JSON 格式数据包含在文件中,由
@
符号和文件名指定。例如:--data @file.json
将外部文件用于 JSON 格式的数据有以下优点:
- 您可以使用您首选的文本编辑器。
- 您可以使用语法检查程序来查找并避免错误。
- 您可以使用工具来检查 JSON 数据的有效性或重新格式化它。
验证 JSON 文件
使用 json_verify
工具检查 JSON 文件的有效性:
$ json_verify < test_file.json
4.1.2. 检索资源列表
本节概述了如何将 curl
与 Satellite 6 API 搭配使用,以从 Satellite 部署中请求信息。这些示例包括请求和响应。预期每个部署的结果会有所不同。
以下示例请求使用 python3
来格式化 Satellite 服务器中的 respone。在 RHEL 7 和一些较旧的系统中,您必须使用 python
而不是 python3
。
列出用户
本例是返回 Satellite 资源列表的基本请求,本例中为 Satellite 用户。此类请求返回元数据中包含的数据列表,而其他请求类型仅返回实际对象。
请求示例:
$ curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/users | python3 -m json.tool
响应示例:
{ "page": 1, "per_page": 20, "results": [ { "admin": false, "auth_source_id": 1, "auth_source_name": "Internal", "created_at": "2018-09-21 08:59:22 UTC", "default_location": null, "default_organization": null, "description": "", "effective_admin": false, "firstname": "", "id": 5, "last_login_on": "2018-09-21 09:03:25 UTC", "lastname": "", "locale": null, "locations": [], "login": "test", "mail": "example@domain.com", "organizations": [ { "id": 1, "name": "Default Organization" } ], "ssh_keys": [], "timezone": null, "updated_at": "2018-09-21 09:04:45 UTC" }, { "admin": true, "auth_source_id": 1, "auth_source_name": "Internal", "created_at": "2018-09-20 07:09:41 UTC", "default_location": null, "default_organization": { "description": null, "id": 1, "name": "Default Organization", "title": "Default Organization" }, "description": "", "effective_admin": true, "firstname": "Admin", "id": 4, "last_login_on": "2018-12-07 07:31:09 UTC", "lastname": "User", "locale": null, "locations": [ { "id": 2, "name": "Default Location" } ], "login": "admin", "mail": "root@example.com", "organizations": [ { "id": 1, "name": "Default Organization" } ], "ssh_keys": [], "timezone": null, "updated_at": "2018-11-14 08:19:46 UTC" } ], "search": null, "sort": { "by": null, "order": null }, "subtotal": 2, "total": 2 }
4.1.3. 创建和修改资源
本节概述了如何将 curl
与 Satellite 6 API 搭配使用,以操作 Satellite 服务器上的资源。这些 API 调用要求您通过 API 调用以 json
格式传递数据。更多信息请参阅 第 4.1.1 节 “将 JSON 数据传递给 API 请求”。
创建用户
这个示例使用 --data
选项创建用户以提供所需信息。
请求示例:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" --request POST \ --user sat_username:sat_password --insecure \ --data "{\"firstname\":\"Test Name\",\"mail\":\"test@example.com\",\"login\":\"test_user\",\"password\":\"password123\",\"auth_source_id\":1}" \ https://satellite.example.com/api/users | python3 -m json.tool
修改用户
这个示例修改 创建用户 中创建的 test_user
的名字和登录。
请求示例:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" --request PUT \ --user sat_username:sat_password --insecure \ --data "{\"firstname\":\"New Test Name\",\"mail\":\"test@example.com\",\"login\":\"new_test_user\",\"password\":\"password123\",\"auth_source_id\":1}" \ https://satellite.example.com/api/users/8 | python3 -m json.tool
4.2. 使用 Ruby 的 API 请求
本节概述了如何将 Ruby 与 Satellite API 搭配使用来执行各种任务。
这些是脚本和命令示例。在使用之前,请确保仔细检查这些脚本,并替换任何变量、用户名、密码和其他信息,以适应您自己的部署。
4.2.1. 使用 Ruby 创建对象
此脚本连接到 Red Hat Satellite 6 API 并创建一个机构,然后在机构中创建三个环境。如果组织已存在,该脚本将使用该机构。如果机构中已存在任何环境,该脚本将引发错误并退出。
#!/usr/bin/ruby require 'rest-client' require 'json' url = 'https://satellite.example.com/api/v2/' katello_url = "#{url}/katello/api/v2/" $username = 'admin' $password = 'changeme' org_name = "MyOrg" environments = [ "Development", "Testing", "Production" ] # Performs a GET using the passed URL location def get_json(location) response = RestClient::Request.new( :method => :get, :url => location, :user => $username, :password => $password, :headers => { :accept => :json, :content_type => :json } ).execute JSON.parse(response.to_str) end # Performs a POST and passes the data to the URL location def post_json(location, json_data) response = RestClient::Request.new( :method => :post, :url => location, :user => $username, :password => $password, :headers => { :accept => :json, :content_type => :json}, :payload => json_data ).execute JSON.parse(response.to_str) end # Creates a hash with ids mapping to names for an array of records def id_name_map(records) records.inject({}) do |map, record| map.update(record['id'] => record['name']) end end # Get list of existing organizations orgs = get_json("#{katello_url}/organizations") org_list = id_name_map(orgs['results']) if !org_list.has_value?(org_name) # If our organization is not found, create it puts "Creating organization: \t#{org_name}" org_id = post_json("#{katello_url}/organizations", JSON.generate({"name"=> org_name}))["id"] else # Our organization exists, so let's grab it org_id = org_list.key(org_name) puts "Organization \"#{org_name}\" exists" end # Get list of organization's lifecycle environments envs = get_json("#{katello_url}/organizations/#{org_id}/environments") env_list = id_name_map(envs['results']) prior_env_id = env_list.key("Library") # Exit the script if at least one life cycle environment already exists environments.each do |e| if env_list.has_value?(e) puts "ERROR: One of the Environments is not unique to organization" exit end end # Create life cycle environments environments.each do |environment| puts "Creating environment: \t#{environment}" prior_env_id = post_json("#{katello_url}/organizations/#{org_id}/environments", JSON.generate({"name" => environment, "organization_id" => org_id, "prior_id" => prior_env_id}))["id"] end
4.2.2. 将 Apipie Bindings 与 Ruby 一起使用
APIpie 绑定是用于 apipie record API 调用的 Ruby 绑定。它们从 Satellite 获取和缓存 API 定义,然后根据需要生成 API 调用。本例创建一个组织,然后在机构中创建三个环境。如果组织已存在,该脚本将使用该机构。如果机构中已存在任何环境,该脚本将引发错误并退出。
#!/usr/bin/tfm-ruby require 'apipie-bindings' org_name = "MyOrg" environments = [ "Development", "Testing", "Production" ] # Create an instance of apipie bindings @api = ApipieBindings::API.new({ :uri => 'https://satellite.example.com/', :username => 'admin', :password => 'changeme', :api_version => 2 }) # Performs an API call with default options def call_api(resource_name, action_name, params = {}) http_headers = {} apipie_options = { :skip_validation => true } @api.resource(resource_name).call(action_name, params, http_headers, apipie_options) end # Creates a hash with IDs mapping to names for an array of records def id_name_map(records) records.inject({}) do |map, record| map.update(record['id'] => record['name']) end end # Get list of existing organizations orgs = call_api(:organizations, :index) org_list = id_name_map(orgs['results']) if !org_list.has_value?(org_name) # If our organization is not found, create it puts "Creating organization: \t#{org_name}" org_id = call_api(:organizations, :create, {'organization' => { :name => org_name }})['id'] else # Our organization exists, so let's grab it org_id = org_list.key(org_name) puts "Organization \"#{org_name}\" exists" end # Get list of organization's life cycle environments envs = call_api(:lifecycle_environments, :index, {'organization_id' => org_id}) env_list = id_name_map(envs['results']) prior_env_id = env_list.key("Library") # Exit the script if at least one life cycle environment already exists environments.each do |e| if env_list.has_value?(e) puts "ERROR: One of the Environments is not unique to organization" exit end end # Create life cycle environments environments.each do |environment| puts "Creating environment: \t#{environment}" prior_env_id = call_api(:lifecycle_environments, :create, {"name" => environment, "organization_id" => org_id, "prior_id" => prior_env_id })['id'] end
4.3. 使用 Python 的 API 请求
本节概述了如何将 Python 与 Satellite API 搭配使用来执行各种任务。
这些是脚本和命令示例。在使用之前,请确保仔细检查这些脚本,并替换任何变量、用户名、密码和其他信息,以适应您自己的部署。
本节中的示例脚本不使用 SSL 验证与 REST API 交互。
4.3.1. 使用 Python 创建对象
此脚本连接到 Red Hat Satellite 6 API 并创建一个机构,然后在机构中创建三个环境。如果组织已存在,该脚本将使用该机构。如果机构中已存在任何环境,该脚本将引发错误并退出。
Python 2 示例
#!/usr/bin/python import json import sys try: import requests except ImportError: print "Please install the python-requests module." sys.exit(-1) # URL to your Satellite 6 server URL = "https://satellite.example.com" # URL for the API to your deployed Satellite 6 server SAT_API = "%s/katello/api/v2/" % URL # Katello-specific API KATELLO_API = "%s/katello/api/" % URL POST_HEADERS = {'content-type': 'application/json'} # Default credentials to login to Satellite 6 USERNAME = "admin" PASSWORD = "changeme" # Ignore SSL for now SSL_VERIFY = False # Name of the organization to be either created or used ORG_NAME = "MyOrg" # Name for life cycle environments to be either created or used ENVIRONMENTS = ["Development", "Testing", "Production"] def get_json(location): """ Performs a GET using the passed URL location """ r = requests.get(location, auth=(USERNAME, PASSWORD), verify=SSL_VERIFY) return r.json() def post_json(location, json_data): """ Performs a POST and passes the data to the URL location """ result = requests.post( location, data=json_data, auth=(USERNAME, PASSWORD), verify=SSL_VERIFY, headers=POST_HEADERS) return result.json() def main(): """ Main routine that creates or re-uses an organization and life cycle environments. If life cycle environments already exist, exit out. """ # Check if our organization already exists org = get_json(SAT_API + "organizations/" + ORG_NAME) # If our organization is not found, create it if org.get('error', None): org_id = post_json( SAT_API + "organizations/", json.dumps({"name": ORG_NAME}))["id"] print "Creating organization: \t" + ORG_NAME else: # Our organization exists, so let's grab it org_id = org['id'] print "Organization '%s' exists." % ORG_NAME # Now, let's fetch all available life cycle environments for this org... envs = get_json( SAT_API + "organizations/" + str(org_id) + "/environments/") # ... and add them to a dictionary, with respective 'Prior' environment prior_env_id = 0 env_list = {} for env in envs['results']: env_list[env['id']] = env['name'] prior_env_id = env['id'] if env['name'] == "Library" else prior_env_id # Exit the script if at least one life cycle environment already exists if all(environment in env_list.values() for environment in ENVIRONMENTS): print "ERROR: One of the Environments is not unique to organization" sys.exit(-1) # Create life cycle environments for environment in ENVIRONMENTS: new_env_id = post_json( SAT_API + "organizations/" + str(org_id) + "/environments/", json.dumps( { "name": environment, "organization_id": org_id, "prior": prior_env_id} ))["id"] print "Creating environment: \t" + environment prior_env_id = new_env_id if __name__ == "__main__": main()
4.3.2. 使用 Python 从 API 请求信息
这是将 Python 用于各种 API 请求的示例脚本。
Python 2 示例
#!/usr/bin/python import json import sys try: import requests except ImportError: print "Please install the python-requests module." sys.exit(-1) SAT_API = 'https://satellite.example.com/api/v2/' USERNAME = "admin" PASSWORD = "password" SSL_VERIFY = False # Ignore SSL for now def get_json(url): # Performs a GET using the passed URL location r = requests.get(url, auth=(USERNAME, PASSWORD), verify=SSL_VERIFY) return r.json() def get_results(url): jsn = get_json(url) if jsn.get('error'): print "Error: " + jsn['error']['message'] else: if jsn.get('results'): return jsn['results'] elif 'results' not in jsn: return jsn else: print "No results found" return None def display_all_results(url): results = get_results(url) if results: print json.dumps(results, indent=4, sort_keys=True) def display_info_for_hosts(url): hosts = get_results(url) if hosts: for host in hosts: print "ID: %-10d Name: %-30s IP: %-20s OS: %-30s" % (host['id'], host['name'], host['ip'], host['operatingsystem_name']) def main(): host = 'satellite.example.com' print "Displaying all info for host %s ..." % host display_all_results(SAT_API + 'hosts/' + host) print "Displaying all facts for host %s ..." % host display_all_results(SAT_API + 'hosts/%s/facts' % host) host_pattern = 'example' print "Displaying basic info for hosts matching pattern '%s'..." % host_pattern display_info_for_hosts(SAT_API + 'hosts?search=' + host_pattern) environment = 'production' print "Displaying basic info for hosts in environment %s..." % environment display_info_for_hosts(SAT_API + 'hosts?search=environment=' + environment) model = 'RHEV Hypervisor' print "Displaying basic info for hosts with model name %s..." % model display_info_for_hosts(SAT_API + 'hosts?search=model="' + model + '"') if __name__ == "__main__": main()
Python 3 示例
#!/usr/bin/env python3 import json import sys try: import requests except ImportError: print("Please install the python-requests module.") sys.exit(-1) SAT = "satellite.example.com" # URL for the API to your deployed Satellite 6 server SAT_API = f"https://{SAT}/api/" KATELLO_API = f"https://{SAT}/katello/api/v2/" POST_HEADERS = {'content-type': 'application/json'} # Default credentials to login to Satellite 6 USERNAME = "admin" PASSWORD = "password" # Ignore SSL for now SSL_VERIFY = False #SSL_VERIFY = "./path/to/CA-certificate.crt" # Put the path to your CA certificate here to allow SSL_VERIFY def get_json(url): # Performs a GET using the passed URL location r = requests.get(url, auth=(USERNAME, PASSWORD), verify=SSL_VERIFY) return r.json() def get_results(url): jsn = get_json(url) if jsn.get('error'): print("Error: " + jsn['error']['message']) else: if jsn.get('results'): return jsn['results'] elif 'results' not in jsn: return jsn else: print("No results found") return None def display_all_results(url): results = get_results(url) if results: print(json.dumps(results, indent=4, sort_keys=True)) def display_info_for_hosts(url): hosts = get_results(url) if hosts: print(f"{'ID':10}{'Name':40}{'IP':30}{'Operating System':30}") for host in hosts: print(f"{str(host['id']):10}{host['name']:40}{str(host['ip']):30}{str(host['operatingsystem_name']):30}") def display_info_for_subs(url): subs = get_results(url) if subs: print(f"{'ID':10}{'Name':90}{'Start Date':30}") for sub in subs: print(f"{str(sub['id']):10}{sub['name']:90}{str(sub['start_date']):30}") def main(): host = SAT print(f"Displaying all info for host {host} ...") display_all_results(SAT_API + 'hosts/' + host) print(f"Displaying all facts for host {host} ...") display_all_results(SAT_API + f'hosts/{host}/facts') host_pattern = 'example' print(f"Displaying basic info for hosts matching pattern '{host_pattern}'...") display_info_for_hosts(SAT_API + 'hosts?per_page=1&search=name~' + host_pattern) print(f"Displaying basic info for subscriptions") display_info_for_subs(KATELLO_API + 'subscriptions') environment = 'production' print(f"Displaying basic info for hosts in environment {environment}...") display_info_for_hosts(SAT_API + 'hosts?search=environment=' + environment) if __name__ == "__main__": main()
第 5 章 使用 Red Hat Satellite API
本章提供了一些示例,了解如何使用 Red Hat Satellite API 执行不同的任务。您可以在端口 443 上通过 HTTPS 在 Satellite 服务器上使用 API,或通过端口 8443 上的 HTTPS 在 Capsule 服务器上使用 API。
您可以在脚本本身内处理这些不同的端口要求。例如,在 Ruby 中,您可以指定 Satellite 和 Capsule URL,如下所示:
url = 'https://satellite.example.com/api/v2/' capsule_url = 'https://capsule.example.com:8443/api/v2/' katello_url = 'https://satellite.example.com/katello/api/v2/'
对于订阅 Satellite 服务器或 Capsule 服务器的主机,您可以在 [server]
部分的端口条目中确定从 /etc/rhsm/rhsm.conf 文件访问 API 所需的正确端口。您可以使用这些值来完全自动化脚本,删除任何需要验证要使用的端口。
本章使用 curl
发送 API 请求。更多信息请参阅 第 4.1 节 “使用 curl 的 API 请求”。
本章中的示例使用 Python json.tool
模块格式化输出。
5.1. 使用主机
以下示例请求使用 python3
来格式化 Satellite 服务器中的 respone。在 RHEL 7 和一些较旧的系统中,您必须使用 python
而不是 python3
。
列出主机
本例返回 Satellite 主机的列表。
请求示例:
$ curl -request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts | python3 -m json.tool
响应示例:
{ ... "total" => 2, "subtotal" => 2, "page" => 1, "per_page" => 1000, "search" => nil, "sort" => { "by" => nil, "order" => nil }, "results" => [ ... }
为主机请求信息
此请求返回主机 satellite.example.com
的信息。
请求示例:
$ curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts/satellite.example.com \ | python3 -m json.tool
响应示例:
{
"all_puppetclasses": [],
"architecture_id": 1,
"architecture_name": "x86_64",
"build": false,
"capabilities": [
"build"
],
"certname": "satellite.example.com",
"comment": null,
"compute_profile_id": null,
...
}
列出主机事实
此请求返回主机 satellite.example.com
的所有事实。
请求示例:
$ curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts/satellite.example.com/facts \ | python3 -m json.tool
响应示例:
{
...
"results": {
"satellite.example.com": {
"augeasversion": "1.0.0",
"bios_release_date": "01/01/2007",
"bios_version": "0.5.1",
"blockdevice_sr0_size": "1073741312",
"facterversion": "1.7.6",
...
}
搜索具有匹配模式的主机
此查询返回与模式 "example" 匹配的所有主机。
请求示例:
$ curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts?search=example \ | python3 -m json.tool
响应示例:
{
...
"results": [
{
"name": "satellite.example.com",
...
}
],
"search": "example",
...
}
搜索环境中的主机
此查询会返回生产环境
中的所有主机。
请求示例:
$ curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts?search=environment=production \ | python3 -m json.tool
响应示例:
{
...
"results": [
{
"environment_name": "production",
"name": "satellite.example.com",
...
}
],
"search": "environment=production",
...
}
搜索具有特定事实值的主机
此查询会返回除名为 RHEV Hypervisor
的所有主机。
请求示例:
$ curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts?search=model=\"RHEV+Hypervisor\" \ | python3 -m json.tool
响应示例:
{
...
"results": [
{
"model_id": 1,
"model_name": "RHEV Hypervisor",
"name": "satellite.example.com",
...
}
],
"search": "model=\"RHEV Hypervisor\"",
...
}
删除主机
此请求删除名为 host1.example.com 的主机。
请求示例:
$ curl --request DELETE --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts/host1.example.com \ | python3 -m json.tool
下载完整引导磁盘镜像
此请求通过其 ID 为主机下载完整的引导磁盘镜像。
请求示例:
$ curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/bootdisk/hosts/host_ID?full=true \ --output image.iso
5.2. 使用生命周期阶段
Satellite 将应用程序生命周期分为生命周期,它们代表了应用程序生命周期的每个阶段。生命周期阶段从环境路径链接到。要使用 API 创建链接的生命周期阶段,请使用 prior_id
参数。
您可以在 https://satellite.example.com/apidoc/v2/lifecycle_environments.html
中找到对生命周期阶段的内置 API 引用。API 路由包括 /katello/api/environments
和 /katello/api/organizations/:organization_id/environments
。
以下示例请求使用 python3
来格式化 Satellite 服务器中的 respone。在 RHEL 7 和一些较旧的系统中,您必须使用 python
而不是 python3
。
列出生命周期阶段
使用此 API 调用列出 Satellite 上针对 ID 为 1
的默认组织的所有当前生命周期环境。
请求示例:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" \ --request GET --user sat_username:sat_password --insecure \ https://satellite.example.com/katello/api/organizations/1/environments \ | python3 -m json.tool`
响应示例:
output omitted "description": null, "id": 1, "label": "Library", "library": true, "name": "Library", "organization": { "id": 1, "label": "Default_Organization", "name": "Default Organization" }, "permissions": { "destroy_lifecycle_environments": false, "edit_lifecycle_environments": true, "promote_or_remove_content_views_to_environments": true, "view_lifecycle_environments": true }, "prior": null, "successor": null, output truncated
创建链接的生命周期环境
使用此示例创建生命周期阶段的路径。
此流程使用默认 ID 为 1
的库环境,作为创建生命周期阶段的起点。
选择您要用作起点的现有生命周期阶段。使用其 ID 列出环境,本例中为 ID 为
1
的环境:请求示例:
$ curl --request GET --user sat_username:sat_password --insecure \ https://satellite.example.com/katello/api/environments/1 \ | python3 -m json.tool
响应示例:
output omitted "id": 1, "label": "Library", output omitted "prior": null, "successor": null, output truncated
创建包含以下内容的 JSON 文件,
如 lifecycle-cycle.json
:{"organization_id":1,"label":"api-dev","name":"API Development","prior":1}
将之前的选项设置为
1
,
创建生命周期环境。请求示例:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" \ --request POST --user sat_username:sat_password --insecure \ --data @life-cycle.json \ https://satellite.example.com/katello/api/environments \ | python3 -m json.tool
响应示例:
output omitted "description": null, "id": 2, "label": "api-dev", "library": false, "name": "API Development", "organization": { "id": 1, "label": "Default_Organization", "name": "Default Organization" }, "permissions": { "destroy_lifecycle_environments": true, "edit_lifecycle_environments": true, "promote_or_remove_content_views_to_environments": true, "view_lifecycle_environments": true }, "prior": { "id": 1, "name": "Library" }, output truncated
在命令输出中,您可以看到此生命周期环境的 ID 为
2
,并且之前的生命周期阶段为1
。使用 ID 为2
的生命周期阶段,创建此环境的成功者。编辑之前创建的 Life
-cycle.json
文件,更新标签
、name
和之前
的值。{"organization_id":1,"label":"api-qa","name":"API QA","prior":2}
创建一个生命周期环境,
使用之前
选项设置为2
。请求示例:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" \ --request POST --user sat_username:sat_password --insecure \ --data @life-cycle.json \ https://satellite.example.com/katello/api/environments \ | python3 -m json.tool
响应示例:
output omitted "description": null, "id": 3, "label": "api-qa", "library": false, "name": "API QA", "organization": { "id": 1, "label": "Default_Organization", "name": "Default Organization" }, "permissions": { "destroy_lifecycle_environments": true, "edit_lifecycle_environments": true, "promote_or_remove_content_views_to_environments": true, "view_lifecycle_environments": true }, "prior": { "id": 2, "name": "API Development" }, "successor": null, output truncated
在命令输出中,您可以看到此生命周期环境的 ID 为
3
,并且之前的生命周期阶段为2
。
更新生命周期阶段
您可以使用 PUT 命令更新生命周期阶段。
这个示例请求更新了 ID 为 3
的生命周期阶段的描述。
请求示例:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" \ --request POST --user sat_username:sat_password --insecure \ --data '{"description":"Quality Acceptance Testing"}' \ https://satellite.example.com/katello/api/environments/3 \ | python3 -m json.tool
响应示例:
output omitted "description": "Quality Acceptance Testing", "id": 3, "label": "api-qa", "library": false, "name": "API QA", "organization": { "id": 1, "label": "Default_Organization", "name": "Default Organization" }, "permissions": { "destroy_lifecycle_environments": true, "edit_lifecycle_environments": true, "promote_or_remove_content_views_to_environments": true, "view_lifecycle_environments": true }, "prior": { "id": 2, "name": "API Development" }, output truncated
删除生命周期阶段
您可以删除一个没有后续者的生命周期环境。因此,使用以下格式的命令以相反的顺序删除它们:
请求示例:
$ curl --request DELETE --user sat_username:sat_password --insecure \ https://satellite.example.com/katello/api/environments/:id
5.3. 将内容上传到 Satellite 服务器
本节概述了如何使用 Satellite 6 API 将大型文件上传到 Satellite 服务器。这个过程涉及四个步骤:
- 创建上传请求。
- 上传内容。
- 导入内容。
- 删除上传请求。
上传的最大文件大小为 2MB。有关上传更大的内容的详情,请参考 上传内容大于 2 MB。
流程
为变量
name
分配软件包名称:请求示例:
$ export name=jq-1.6-2.el7.x86_64.rpm
将文件的校验和分配给变量
checksum
:请求示例:
$ export checksum=$(sha256sum $name|cut -c 1-65)
将文件大小分配给变量
大小
:请求示例:
$ export size=$(du -bs $name|cut -f 1)
以下命令创建新的上传请求,并使用
大小和
校验和
返回请求的上传 ID。请求示例:
$ curl -H 'Content-Type: application/json' -X POST -k \ -u sat_username:sat_password -d "{\"size\": \"$size\", \ \"checksum\":\"$checksum\"}" \ https://$(hostname -f)/katello/api/v2/repositories/76/content_uploads
其中 76,本例中为 Repository ID。
请求示例:
{"upload_id":"37eb5900-597e-4ac3-9bc5-2250c302fdc4"}
将上传 ID 分配给变量
upload_id
:请求示例:
$ export upload_id=37eb5900-597e-4ac3-9bc5-2250c302fdc4
分配您要上传到变量
路径的软件包路径
:$ export path=/root/jq/jq-1.6-2.el7.x86_64.rpm
上传您的内容。在上传数据时,请确保使用正确的 MIME 类型。API 对 Satellite 6 的大多数请求使用 application/json MIME 类型。组合 upload_id、MIME 类型和其他参数来上传内容。
请求示例:
$ curl -u sat_username:sat_password -H Accept:application/json -H \ Content-Type:multipart/form-data -X PUT --data-urlencode size=$size --data-urlencode offset=0 \ --data-urlencode content@${path} \ https://$(hostname -f)/katello/api/v2/repositories/76/content_uploads/$upload_id
将内容上传到 Satellite 服务器后,您需要将其导入到适当的存储库中。完成此步骤前,Satellite 服务器不会检测新内容。
请求示例:
$ curl -H "Content-Type:application/json" -X PUT -u \ sat_username:sat_password -k -d \ "{\"uploads\":[{\"id\": \"$upload_id\", \"name\": \"$name\", \ \"checksum\": \"$checksum\" }]}" \ https://$(hostname -f)/katello/api/v2/repositories/76/import_uploads
成功上传并导入内容后,您可以删除上传请求。这会释放在上传过程中使用的任何临时磁盘空间。
请求示例:
$ curl -H 'Content-Type: application/json' -X DELETE -k \ -u sat_username:sat_password -d "{}" \ https://$(hostname -f)/katello/api/v2/repositories/76/content_uploads/$upload_id
上传内容大于 2 MB
以下示例演示了如何将大型文件分成块,创建上传请求,上传单个文件,将它们导入到 Satellite,然后删除上传请求。请注意,本例使用示例内容、主机名、用户名、存储库 ID 和文件名。
为变量
name
分配软件包名称:$ export name=bpftool-3.10.0-1160.2.1.el7.centos.plus.x86_64.rpm
将文件的校验和分配给变量
checksum
:$ export checksum=$(sha256sum $name|cut -c 1-65)
将文件大小分配给变量
大小
:$ export size=$(du -bs $name|cut -f 1)
以下命令创建新的上传请求,并使用
大小和
校验和
返回请求的上传 ID。请求示例:
$ curl -H 'Content-Type: application/json' -X POST -k \ -u sat_username:sat_password -d "{\"size\": \"$size\", \ \"checksum\":\"$checksum\"}" \ https://$(hostname -f)/katello/api/v2/repositories/76/content_uploads
其中 76,本例中为 Repository ID。
输出示例
{"upload_id":"37eb5900-597e-4ac3-9bc5-2250c302fdc4"}
将上传 ID 分配给变量
upload_id
:$ export upload_id=37eb5900-597e-4ac3-9bc5-2250c302fdc4
以 2MB 块分割文件:
$ split --bytes 2MB --numeric-suffixes \ --suffix-length=1 bpftool-3.10.0-1160.2.1.el7.centos.plus.x86_64.rpm bpftool
输出示例
$ ls bpftool[0-9] -l -rw-r--r--. 1 root root 2000000 Mar 31 14:15 bpftool0 -rw-r--r--. 1 root root 2000000 Mar 31 14:15 bpftool1 -rw-r--r--. 1 root root 2000000 Mar 31 14:15 bpftool2 -rw-r--r--. 1 root root 2000000 Mar 31 14:15 bpftool3 -rw-r--r--. 1 root root 868648 Mar 31 14:15 bpftool4
将分割文件的前缀分配给变量路径。
$ export path=/root/tmp/bpftool
上传文件块。偏移从 0 代表第一个块开始,并为每个文件增加 2000000。请注意,使用 offset 参数以及它们如何与文件大小相关。另请注意,索引在路径变量后使用,如 ${path}0, ${path}1。
请求示例:
$ curl -u sat_username:sat_password -H Accept:application/json -H \ Content-Type:multipart/form-data \ -X PUT --data-urlencode size=$size --data-urlencode offset=0 \ --data-urlencode content@${path}0 https://$(hostname -f)/katello/api/v2/repositories/76/content_uploads/$upload_id $ curl -u sat_username:sat_password -H Accept:application/json -H \ Content-Type:multipart/form-data \ -X PUT --data-urlencode size=$size --data-urlencode offset=2000000 \ --data-urlencode content@${path}1 https://$(hostname -f)/katello/api/v2/repositories/76/content_uploads/$upload_id $ curl -u sat_username:sat_password -H Accept:application/json -H \ Content-Type:multipart/form-data \ -X PUT --data-urlencode size=$size --data-urlencode offset=4000000 \ --data-urlencode content@${path}2 https://$(hostname -f)/katello/api/v2/repositories/76/content_uploads/$upload_id $curl -u sat_username:sat_password -H Accept:application/json -H \ Content-Type:multipart/form-data \ -X PUT --data-urlencode size=$size --data-urlencode offset=6000000 --data-urlencode content@${path}3 https://$(hostname -f)/katello/api/v2/repositories/76/content_uploads/$upload_id $ curl -u sat_username:sat_password -H Accept:application/json -H \ Content-Type:multipart/form-data \ -X PUT --data-urlencode size=$size --data-urlencode offset=8000000 \ --data-urlencode content@${path}4 https://$(hostname -f)/katello/api/v2/repositories/76/content_uploads/$upload_id
将完整上传导入到存储库:
$ curl -H "Content-Type:application/json" -X PUT -u \ sat_username:sat_password -k -d \ "{\"uploads\":[{\"id\": \"$upload_id\", \ \"name\": \"$name\", \"checksum\": \"$checksum\" }]}" \ https://$(hostname -f)/katello/api/v2/repositories/76/import_uploads
删除上传请求:
$ curl -H 'Content-Type: application/json' -X DELETE -k \ -u sat_username:sat_password -d "{}" \ https://$(hostname -f)/katello/api/v2/repositories/76/content_uploads/$upload_id
上传重复内容
请注意,如果您试图使用以下方法上传重复内容:
请求示例:
$ curl -H 'Content-Type: application/json' -X POST -k \
-u sat_username:sat_password -d "{\"size\": \"$size\", \"checksum\":\"$checksum\"}" \
https://$(hostname -f)/katello/api/v2/repositories/76/content_uploads
调用将返回内容单元 ID 而不是上传 ID,如下所示:
{"content_unit_href":"/pulp/api/v3/content/file/files/c1bcdfb8-d840-4604-845e-86e82454c747/"}
您可以复制此输出并直接调用导入上传,将内容添加到存储库中:
请求示例:
$ curl -H "Content-Type:application/json" -X PUT -u \
sat_username:sat_password -k \-d \
"{\"uploads\":[{\"content_unit_id\": \"/pulp/api/v3/content/file/files/c1bcdfb8-d840-4604-845e-86e82454c747/\", \
\"name\": \"$name\", \ \"checksum\": \"$checksum\" }]}" https://$(hostname -f)/katello/api/v2/repositories/76/import_uploads
请注意,调用从使用 upload_id
改为使用 content_unit_id
。
5.4. 将勘误应用到主机或主机组
您可以使用 API 将勘误表应用到主机、主机组或主机组。以下是 PUT 请求的基本语法:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" --request PUT \ --user sat_username:sat_password --insecure \ --data json-formatted-data https://satellite7.example.com
您可以浏览 API doc 中的内置,以查找用于应用勘误的 URL。您可以使用 Satellite Web UI 帮助发现搜索查询的格式。导航到 Hosts > Host Collections 并选择主机聚合。进入 Collection Actions > Errata Installation,并注意搜索查询复选框内容。例如,对于名为 my-collection 的 Host Collection,搜索框包含 host_collection="my-collection"
。
将勘误应用到主机
本例对批量操作 /katello/api/hosts/bulk/install_content
使用 API URL 来显示简单搜索所需的格式。
请求示例:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" --request PUT \ --user sat_username:sat_password --insecure \ --data "{\"organization_id\":1,\"included\":{\"search\":\"my-host\"},\"content_type\":\"errata\",\"content\":[\"RHBA-2016:1981\"]}" \ https://satellite.example.com/api/v2/hosts/bulk/install_content
将勘误应用到主机组
在本例中,请注意需要传递搜索字符串 host_collection="my-collection"
所需的转义级别,如 Satellite Web UI 中所示。
请求示例:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" --request PUT \ --user sat_username:sat_password --insecure \ --data "{\"organization_id\":1,\"included\":{\"search\":\"host_collection=\\\"my-collection\\\"\"},\"content_type\":\"errata\",\"content\":[\"RHBA-2016:1981\"]}" \ https://satellite.example.com/api/v2/hosts/bulk/install_content
5.5. 使用扩展搜索
您可以找到可用于在 Web UI 中构建搜索查询的搜索参数。如需更多信息,请参阅 管理 Red Hat Satellite 中的 构建搜索查询。
例如,要搜索主机,请完成以下步骤:
- 在 Satellite Web UI 中,导航到 Hosts > All Hosts,然后点击 Search 字段来显示搜索参数列表。
- 找到您要使用的搜索参数。在本例中,找到 os_title 和 model。
在 API 查询中组合搜索参数,如下所示:
请求示例:
$ curl --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts?search=os_title=\"RedHat+7.7\",model=\"PowerEdge+R330\" \ | python3 -m json.tool
注意示例请求使用
python3
来格式化 Satellite 服务器中的 respone。在 RHEL 7 和一些较旧的系统中,您必须使用python
而不是python3
。响应示例:
{ ... "results": [ { "model_id": 1, "model_name": "PowerEdge R330", "name": "satellite.example.com", "operatingsystem_id": 1, "operatingsystem_name": "RedHat 7.7", ... } ], "search": "os_title=\"RedHat 7.7\",model=\"PowerEdge R330\"", "subtotal": 1, "total": 11 }
5.6. 使用带有 Pagination Control 的搜索
您可以使用 per_page
和 page
分页参数来限制 API 搜索查询返回的搜索结果。per_page
参数指定每个页面的结果数,以及 page
参数指定根据 per_page
参数计算哪些页面,以返回。
当您没有指定任何分页参数时,要返回的默认项目数量被设置为 1000,但 per_page
值的默认值为 20,当您指定 page
参数时应用它。
列出内容视图
这个示例在页面中返回内容视图列表。该列表包含每个页面的 10 个密钥,并返回第三个页面。
请求示例:
$ curl --request GET --user sat_username:sat_password \
https://satellite.example.com/katello/api/content_views?per_page=10&page=3
列出激活码
这个示例返回页面中 ID 为 1
的机构的激活码列表。列表包含每个页面的 30 个密钥,并返回第二个页面。
请求示例:
$ curl --request GET --user sat_username:sat_password \
https://satellite.example.com/katello/api/activation_keys?organization_id=1&per_page=30&page=2
返回多个页面
您可以使用 for
loop 结构来获取多个结果页面。
这个示例将页 1 返回到每个页面 5 个结果的内容视图 3:
$ for i in seq 1 3
; do \
curl --request GET --user sat_username:sat_password \
https://satellite.example.com/katello/api/content_views?per_page=5&page=$i; \
done
5.7. 覆盖智能类参数
您可以使用 API 搜索智能清单,并提供一个值来覆盖类中的智能参数。您可以在 https://satellite.example.com/apidoc/v2/smart_class_parameters/update.html
的内置 API 引用中找到您可以修改的属性的完整列表。
查找您要更改的 Smart Class 参数的 ID:
列出所有智能类参数。
请求示例:
$ curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/smart_class_parameters
如果您知道 Puppet 类 ID,如 5,您可以限制范围:
请求示例:
$ curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/puppetclasses/5/smart_class_parameters
两个调用都接受 search 参数。您可以在 Satellite Web UI 中查看可搜索字段的完整列表。导航到 Configure > Smart variables,然后点击搜索查询框来显示字段列表。
特别有用的搜索参数是
puppetclass_name
和key
,可用于搜索特定参数。例如,使用--data
选项传递 URL 编码数据。请求示例:
$ curl --request GET --insecure --user sat_username:sat_password \ --data 'search=puppetclass_name = access_insights_client and key = authmethod' \ https://satellite.example.com/api/smart_class_parameters
Satellite 支持标准范围的搜索语法。
当您找到参数的 ID 时,列出包括当前覆盖值的完整详情。
请求示例:
$ curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/smart_class_parameters/63
启用覆盖参数值。
请求示例:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" \ --request PUT --insecure --user sat_username:sat_password \ --data '{"smart_class_parameter":{"override":true}}' \ https://satellite.example.com/api/smart_class_parameters/63
请注意,您无法手动创建或删除参数。您只能修改其属性。Satellite 仅在从代理导入类时创建和删除参数。
添加自定义覆盖匹配器。
请求示例:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" \ --request PUT --insecure --user sat_username:sat_password \ --data '{"smart_class_parameter":{"override_value":{"match":"hostgroup=Test","value":"2.4.6"}}}' \ https://satellite.example.com/api/smart_class_parameters/63
有关覆盖值的更多信息,请参阅
https://satellite.example.com/apidoc/v2/override_values.html
。您可以删除覆盖值。
请求示例:
$ curl --request DELETE --user sat_username:sat_password \ https://satellite.example.com/api/smart_class_parameters/63/override_values/3
5.8. 使用外部文件修改智能类参数
使用外部文件简化了使用 JSON 数据的过程。使用带有语法高亮显示的编辑器可帮助您避免并找到错误。
以下示例请求使用 python3
来格式化 Satellite 服务器中的 respone。在 RHEL 7 和一些较旧的系统中,您必须使用 python
而不是 python3
。
使用外部文件修改智能类参数
本例使用 MOTD Puppet 清单。
根据名称搜索 Puppet 类,本例中为
motd
。请求示例:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" \ --request GET --user sat_user:sat_password --insecure \ https://satellite.example.com/api/smart_class_parameters?search=puppetclass_name=motd \ | python3 -m json.tool
检查以下输出:每个智能类参数都有一个 ID,对同一 Satellite 实例是全局的。
motd
类的content
参数在此 Satellite 服务器中具有id=3
。不要将其与 Puppet 类名称之前显示的 Puppet 类 ID 混淆。响应示例:
{ "avoid_duplicates": false, "created_at": "2017-02-06 12:37:48 UTC", # Remove this line. "default_value": "", # Add a new value here. "description": "", "hidden_value": "", "hidden_value?": false, "id": 3, "merge_default": false, "merge_overrides": false, "override": false, # Set the override value to
true
. "override_value_order": "fqdn\nhostgroup\nos\ndomain", "override_values": [], # Remove this line. "override_values_count": 0, "parameter": "content", "parameter_type": "string", "puppetclass_id": 3, "puppetclass_name": "motd", "required": false, "updated_at": "2017-02-07 11:56:55 UTC", # Remove this line. "use_puppet_default": false, "validator_rule": null, "validator_type": "" }使用参数 ID
3
获取特定于motd
参数的信息,并将输出重定向到文件,如 output_file.json。请求示例:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" --request GET \ --user sat_user:sat_password --insecure \` https://satellite.example.com/api/smart_class_parameters/3 \ | python3 -m json.tool > output_file.json
将上一步中创建的文件复制到新文件中以进行编辑,例如
changed_file.json
:$ cp output_file.json changed_file.json
修改文件中所需的值。在本例中,将
motd
模块的 content 参数改为 true,这需要将override
选项从false
改为true
:{ "avoid_duplicates": false, "created_at": "2017-02-06 12:37:48 UTC", # Remove this line. "default_value": "", # Add a new value here. "description": "", "hidden_value": "", "hidden_value?": false, "id": 3, "merge_default": false, "merge_overrides": false, "override": false, # Set the override value to
true
. "override_value_order": "fqdn\nhostgroup\nos\ndomain", "override_values": [], # Remove this line. "override_values_count": 0, "parameter": "content", "parameter_type": "string", "puppetclass_id": 3, "puppetclass_name": "motd", "required": false, "updated_at": "2017-02-07 11:56:55 UTC", # Remove this line. "use_puppet_default": false, "validator_rule": null, "validator_type": "" }编辑该文件后,验证该文件是否类似如下,然后保存更改:
{ "avoid_duplicates": false, "default_value": "No Unauthorized Access Allowed", "description": "", "hidden_value": "", "hidden_value?": false, "id": 3, "merge_default": false, "merge_overrides": false, "override": true, "override_value_order": "fqdn\nhostgroup\nos\ndomain", "override_values_count": 0, "parameter": "content", "parameter_type": "string", "puppetclass_id": 3, "puppetclass_name": "motd", "required": false, "use_puppet_default": false, "validator_rule": null, "validator_type": "" }
将更改应用到 Satellite 服务器:
$ curl --header "Accept:application/json" \ --header "Content-Type:application/json" \ --request PUT --user sat_username:sat_password --insecure \ --data @changed_file.json \ https://satellite.example.com/api/smart_class_parameters/3
5.9. 删除 OpenSCAP 报告
在 Satellite 服务器中,您可以删除一个或多个 OpenSCAP 报告。但是,当您删除报告时,您必须一次删除一个页面。如果要删除所有 Openscap 报告,请使用如下 bash 脚本。
以下示例请求和示例脚本使用 python3
来格式化来自 Satellite 服务器的响应。在 RHEL 7 和一些较旧的系统中,您必须使用 python
而不是 python3
。
删除 OpenSCAP 报告
要删除 OpenSCAP 报告,请完成以下步骤:
列出所有 OpenSCAP 报告。请注意您要删除的报告的 ID。
请求示例:
curl --insecure --user username:_password_ \ https://satellite.example.com/api/v2/compliance/arf_reports/ | python3 -m json.tool
响应示例:
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 3252 0 3252 0 0 4319 0 --:--:-- --:--:-- --:--:-- 4318 { "page": 1, "per_page": 20, "results": [ { "created_at": "2017-05-16 13:27:09 UTC", "failed": 0, "host": "host1.example.com", "id": 404, "othered": 0, "passed": 0, "updated_at": "2017-05-16 13:27:09 UTC" }, { "created_at": "2017-05-16 13:26:07 UTC", "failed": 0, "host": "host2.example.com, "id": 405, "othered": 0, "passed": 0, "updated_at": "2017-05-16 13:26:07 UTC" }, { "created_at": "2017-05-16 13:25:07 UTC", "failed": 0, "host": "host3.example.com", "id": 406, "othered": 0, "passed": 0, "updated_at": "2017-05-16 13:25:07 UTC" }, { "created_at": "2017-05-16 13:24:07 UTC", "failed": 0, "host": "host4.example.com", "id": 407, "othered": 0, "passed": 0, "updated_at": "2017-05-16 13:24:07 UTC" }, ], "search": null, "sort": { "by": null, "order": null }, "subtotal": 29, "total": 29
使用上一步中的 ID,删除 OpenSCAP 报告。对您要删除的每个 ID 重复。
请求示例:
# curl --insecure --user username:_password_ \ --header "Content-Type: application/json" \ --request DELETE https://satellite.example.com/api/v2/compliance/arf_reports/405
响应示例:
HTTP/1.1 200 OK Date: Thu, 18 May 2017 07:14:36 GMT Server: Apache/2.4.6 (Red Hat Enterprise Linux) X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block X-Content-Type-Options: nosniff Foreman_version: 1.11.0.76 Foreman_api_version: 2 Apipie-Checksum: 2d39dc59aed19120d2359f7515e10d76 Cache-Control: max-age=0, private, must-revalidate X-Request-Id: f47eb877-35c7-41fe-b866-34274b56c506 X-Runtime: 0.661831 X-Powered-By: Phusion Passenger 4.0.18 Set-Cookie: request_method=DELETE; path=/ Set-Cookie: _session_id=d58fe2649e6788b87f46eabf8a461edd; path=/; secure; HttpOnly ETag: "2574955fc0afc47cb5394ce95553f428" Status: 200 OK Vary: Accept-Encoding Transfer-Encoding: chunked Content-Type: application/json; charset=utf-8
删除所有 OpenSCAP 报告的 BASH 脚本示例
使用以下 bash 脚本删除所有 OpenSCAP 报告:
#!/bin/bash #this script removes all the arf reports from the satellite server #settings USER=username PASS=password URI=https://satellite.example.com #check amount of reports while [ $(curl --insecure --user $USER:$PASS $URI/api/v2/compliance/arf_reports/ | python3 -m json.tool | grep \"\total\": | cut --fields=2 --delimiter":" | cut --fields=1 --delimiter"," | sed "s/ //g") -gt 0 ]; do #fetch reports for i in $(curl --insecure --user $USER:$PASS $URI/api/v2/compliance/arf_reports/ | python3 -m json.tool | grep \"\id\": | cut --fields=2 --delimiter":" | cut --fields=1 --delimiter"," | sed "s/ //g") #delete reports do curl --insecure --user $USER:$PASS --header "Content-Type: application/json" --request DELETE $URI/api/v2/compliance/arf_reports/$i done done
附录 A. API 响应代码
Red Hat Satellite 6 API 为 API 调用提供 HTTP 响应状态代码。以下代码是 Satellite API 中所有资源的常见代码。
表 A.1. API 响应代码
响应 | 解释 |
---|---|
200 OK | 对于成功请求操作:显示、索引、更新或删除(GET、PUT、DELETE 请求)。 |
201 已创建 | 对于成功创建操作(POST 请求)。 |
301 移动 permanently | 当 Satellite 限制为使用 HTTPS 但尝试使用 HTTP 时,会进行重定向。 |
400 错误请求 | 缺少需要的参数,或者搜索查询具有无效的语法。 |
401 未授权 | 授权用户失败(例如,不正确的凭证)。 |
403 Forbidden | 用户没有足够的权限来执行该操作或读取资源,否则不支持该操作。 |
404 not Found | 给定 ID 的记录不存在。它可能会出现在 show 中,并在请求的记录不存在时删除操作;或者,当相关记录不存在时,会创建和删除操作。 |
409 冲突 | 因为缺少依赖项(例如,带有主机的主机组)无法删除记录。 |
415 不支持的介质类型 | HTTP 请求的内容类型是 JSON。 |
422 Unprocessable Entity | 由于某些验证错误,无法创建实体。仅适用于创建或更新操作。 |
500 内部服务器错误 | 意外的内部服务器错误。 |
503 服务不可用 | 服务器没有运行。 |
附录 B. API 权限列表
Red Hat Satellite 6 API 支持许多操作,其中许多操作需要特定的权限。下表列出了 API 权限名称、与这些权限关联的操作以及关联的资源类型。
表 B.1. API 权限列表
权限名称 | Actions | 资源类型 |
---|---|---|
view_activation_keys |
| Katello::ActivationKey |
create_activation_keys |
| Katello::ActivationKey |
edit_activation_keys |
| Katello::ActivationKey |
destroy_activation_keys |
| Katello::ActivationKey |
logout |
| |
view_architectures |
| |
create_architectures |
| |
edit_architectures |
| |
destroy_architectures |
| |
view_audit_logs |
| |
view_authenticators |
| |
create_authenticators |
| |
edit_authenticators |
| |
destroy_authenticators |
| |
view_bookmarks |
| |
create_bookmarks |
| |
edit_bookmarks |
| |
destroy_bookmarks |
| |
download_bootdisk |
| |
manage_capsule_content |
| SmartProxy |
view_capsule_content |
| SmartProxy |
view_compute_profiles |
| |
create_compute_profiles |
| |
edit_compute_profiles |
| |
destroy_compute_profiles |
| |
view_compute_resources |
| |
create_compute_resources |
| |
edit_compute_resources |
| |
destroy_compute_resources |
| |
view_compute_resources_vms |
| |
create_compute_resources_vms |
| |
edit_compute_resources_vms |
| |
destroy_compute_resources_vms |
| |
power_compute_resources_vms |
| |
console_compute_resources_vms |
| |
view_config_groups |
| |
create_config_groups |
| |
edit_config_groups |
| |
destroy_config_groups |
| |
view_config_reports |
| |
destroy_config_reports |
| |
upload_config_reports |
| |
view_containers |
| Container |
commit_containers |
| Container |
create_containers |
| Container |
destroy_containers |
| Container |
power_compute_resources_vms |
| ComputeResource |
view_content_views |
| Katello::ContentView |
create_content_views |
| Katello::ContentView |
edit_content_views |
| Katello::ContentView |
destroy_content_views |
| Katello::ContentView |
publish_content_views |
| Katello::ContentView |
promote_or_remove_content_views |
| Katello::ContentView |
export_content_views |
| Katello::ContentView |
access_dashboard |
| |
view_discovered_hosts |
| 主机 |
submit_discovered_hosts |
| 主机 |
auto_provision_discovered_hosts |
| 主机 |
provision_discovered_hosts |
| 主机 |
edit_discovered_hosts |
| 主机 |
destroy_discovered_hosts |
| 主机 |
view_discovery_rules |
| DiscoveryRule |
create_discovery_rules |
| DiscoveryRule |
edit_discovery_rules |
| DiscoveryRule |
execute_discovery_rules |
| DiscoveryRule |
destroy_discovery_rules |
| DiscoveryRule |
view_domains |
| |
create_domains |
| |
edit_domains |
| |
destroy_domains |
| |
view_environments |
| |
create_environments |
| |
edit_environments |
| |
destroy_environments |
| |
import_environments |
| |
view_external_usergroups |
| |
create_external_usergroups |
| |
edit_external_usergroups |
| |
destroy_external_usergroups |
| |
view_external_variables |
| |
create_external_variables |
| |
edit_external_variables |
| |
destroy_external_variables |
| |
view_facts |
| |
upload_facts |
| |
view_filters |
| |
create_filters |
| |
edit_filters |
| |
destroy_filters |
| |
view_arf_reports |
| |
destroy_arf_reports |
| |
create_arf_reports |
| |
view_policies |
| ForemanOpenscap::Policy |
edit_policies |
| ForemanOpenscap::Policy |
create_policies |
| ForemanOpenscap::Policy |
destroy_policies |
| ForemanOpenscap::Policy |
assign_policies |
| ForemanOpenscap::Policy |
view_scap_contents |
| ForemanOpenscap::ScapContent |
view_scap_contents |
| ForemanOpenscap::ScapContent |
edit_scap_contents |
| ForemanOpenscap::ScapContent |
create_scap_contents |
| ForemanOpenscap::ScapContent |
destroy_scap_contents |
| ForemanOpenscap::ScapContent |
edit_hostgroups |
| 主机 |
view_job_templates |
| JobTemplate |
create_job_templates |
| JobTemplate |
edit_job_templates |
| |
edit_job_templates |
| |
edit_remote_execution_features |
| RemoteExecutionFeature |
destroy_job_templates |
| JobTemplate |
lock_job_templates |
| JobTemplate |
create_job_invocations |
| JobInvocation |
view_job_invocations |
| JobInvocation |
execute_template_invocation | TemplateInvocation | |
filter_autocompletion_for_template_invocation |
| TemplateInvocation |
view_foreman_tasks |
| ForemanTasks::Task |
edit_foreman_tasks |
| ForemanTasks::Task |
create_recurring_logics | ForemanTasks::RecurringLogic | |
view_recurring_logics |
| ForemanTasks::RecurringLogic |
edit_recurring_logics |
| ForemanTasks::RecurringLogic |
view_globals |
| |
create_globals |
| |
edit_globals |
| |
destroy_globals |
| |
view_gpg_keys |
| Katello::GpgKey |
create_gpg_keys |
| Katello::GpgKey |
edit_gpg_keys |
| Katello::GpgKey |
destroy_gpg_keys |
| Katello::GpgKey |
view_host_collections |
| Katello::HostCollection |
create_host_collections |
| Katello::HostCollection |
edit_host_collections |
| Katello::HostCollection |
destroy_host_collections |
| Katello::HostCollection |
edit_classes |
| |
create_params |
| |
edit_params |
| |
destroy_params |
| |
view_hostgroups |
| |
create_hostgroups |
| |
edit_hostgroups |
| |
destroy_hostgroups |
| |
view_hosts |
| |
create_hosts |
| |
edit_hosts |
| |
destroy_hosts |
| |
build_hosts |
| |
power_hosts |
| |
console_hosts |
| |
ipmi_boot |
| |
puppetrun_hosts |
| |
search_repository_image_search |
| Docker/ImageSearch |
view_images |
| |
create_images |
| |
edit_images |
| |
destroy_images |
| |
view_lifecycle_environments |
| Katello::KTEnvironment |
create_lifecycle_environments |
| Katello::KTEnvironment |
edit_lifecycle_environments |
| Katello::KTEnvironment |
destroy_lifecycle_environments |
| Katello::KTEnvironment |
promote_or_remove_content_views_to_environments | Katello::KTEnvironment | |
view_locations |
| |
create_locations |
| |
edit_locations |
| |
destroy_locations |
| |
assign_locations |
| |
view_mail_notifications |
| |
view_media |
| |
create_media |
| |
edit_media |
| |
destroy_media |
| |
view_models |
| |
create_models |
| |
edit_models |
| |
destroy_models |
| |
view_operatingsystems |
| |
create_operatingsystems |
| |
edit_operatingsystems |
| |
destroy_operatingsystems |
| |
view_organizations |
| |
create_organizations |
| |
edit_organizations |
| |
destroy_organizations |
| |
assign_organizations |
| |
view_ptables |
| |
create_ptables |
| |
edit_ptables |
| |
destroy_ptables |
| |
lock_ptables |
| |
view_plugins |
| |
view_products |
| Katello::Product |
create_products |
| Katello::Product |
edit_products |
| Katello::Product |
destroy_products |
| Katello::Product |
sync_products |
| Katello::Product |
export_products |
| Katello::Product |
view_provisioning_templates |
| |
create_provisioning_templates |
| |
edit_provisioning_templates |
| |
destroy_provisioning_templates |
| |
deploy_provisioning_templates |
| |
lock_provisioning_templates |
| |
user_logout |
| |
my_account |
| |
api_status |
| |
view_puppetclasses |
| |
create_puppetclasses |
| |
edit_puppetclasses |
| |
destroy_puppetclasses |
| |
import_puppetclasses |
| |
view_realms |
| |
create_realms |
| |
edit_realms |
| |
destroy_realms |
| |
view_search |
| |
view_cases |
| |
attachments |
| |
配置 |
| |
app_root |
| |
view_log_viewer |
| |
logs |
| |
rh_telemetry_api |
| |
rh_telemetry_view |
| |
rh_telemetry_configurations |
| |
view_roles |
| |
create_roles |
| |
edit_roles |
| |
destroy_roles |
| |
access_settings |
| |
view_smart_proxies |
| |
create_smart_proxies |
| |
edit_smart_proxies |
| |
destroy_smart_proxies |
| |
view_smart_proxies_autosign |
| |
create_smart_proxies_autosign |
| |
destroy_smart_proxies_autosign |
| |
view_smart_proxies_puppetca |
| |
edit_smart_proxies_puppetca |
| |
destroy_smart_proxies_puppetca |
| |
view_subnets |
| |
create_subnets |
| |
edit_subnets |
| |
destroy_subnets |
| |
import_subnets |
| |
view_subscriptions |
| 机构(Organization) |
attach_subscriptions |
| 机构(Organization) |
unattach_subscriptions |
| 机构(Organization) |
import_manifest |
| 机构(Organization) |
delete_manifest |
| 机构(Organization) |
view_sync_plans |
| Katello::SyncPlan |
create_sync_plans |
| Katello::SyncPlan |
edit_sync_plans |
| Katello::SyncPlan |
destroy_sync_plans |
| Katello::SyncPlan |
my_organizations |
| |
view_usergroups |
| |
create_usergroups |
| |
edit_usergroups |
| |
destroy_usergroups |
| |
view_users |
| |
create_users |
| |
edit_users |
| |
destroy_users |
|