第 6 章 API cheat sheet
您可以查看如何使用 Red Hat Satellite API 执行各种任务的示例。您可以通过 HTTPS 在端口 443 上使用 API。
例如,在 Ruby 中,您可以指定 Satellite 服务器 URL,如下所示:
url = 'https://satellite.example.com/api/v2/' katello_url = 'https://satellite.example.com/katello/api/v2/'
url = 'https://satellite.example.com/api/v2/'
katello_url = 'https://satellite.example.com/katello/api/v2/'
您可以使用这些值来完全自动化脚本,无需验证要使用的端口。
以下示例使用 curl
发送 API 请求。如需更多信息,请参阅 第 5.1 节 “在 curl 中调用 API”。
6.1. 使用主机 复制链接链接已复制到粘贴板!
6.1.1. 列出主机 复制链接链接已复制到粘贴板!
本例返回注册主机列表。
API 请求
curl \ --request GET \ --user My_User_Name:My_Password \ https://satellite.example.com/api/v2/hosts \ | python3 -m json.tool
$ curl \
--request GET \
--user My_User_Name:My_Password \
https://satellite.example.com/api/v2/hosts \
| python3 -m json.tool
API 响应
6.1.2. 为主机请求信息 复制链接链接已复制到粘贴板!
此请求返回主机 satellite.example.com
的信息。
API 请求
curl \ --request GET \ --user My_User_Name:My_Password \ https://satellite.example.com/api/v2/hosts/satellite.example.com \ | python3 -m json.tool
$ curl \
--request GET \
--user My_User_Name:My_Password \
https://satellite.example.com/api/v2/hosts/satellite.example.com \
| python3 -m json.tool
API 响应
6.1.3. 列出主机事实 复制链接链接已复制到粘贴板!
此请求返回主机 satellite.example.com
的所有事实。
API 请求
curl \ --request GET \ --user My_User_Name:My_Password \ https://satellite.example.com/api/v2/hosts/satellite.example.com/facts \ | python3 -m json.tool
$ curl \
--request GET \
--user My_User_Name:My_Password \
https://satellite.example.com/api/v2/hosts/satellite.example.com/facts \
| python3 -m json.tool
API 响应
6.1.4. 搜索具有匹配模式的主机 复制链接链接已复制到粘贴板!
此查询返回与模式"example"匹配的所有主机。
API 请求
curl \ --request GET \ --user My_User_Name:My_Password \ https://satellite.example.com/api/v2/hosts?search=example \ | python3 -m json.tool
$ curl \
--request GET \
--user My_User_Name:My_Password \
https://satellite.example.com/api/v2/hosts?search=example \
| python3 -m json.tool
API 响应
6.1.5. 搜索环境中的主机 复制链接链接已复制到粘贴板!
此查询会返回生产环境
中的所有主机。
API 请求
curl \ --request GET \ --user My_User_Name:My_Password \ https://satellite.example.com/api/v2/hosts?search=environment=production \ | python3 -m json.tool
$ curl \
--request GET \
--user My_User_Name:My_Password \
https://satellite.example.com/api/v2/hosts?search=environment=production \
| python3 -m json.tool
API 响应
6.1.6. 使用特定事实值搜索主机 复制链接链接已复制到粘贴板!
此查询返回具有模型名称 RHV Hypervisor
的所有主机。
API 请求
curl \ --request GET \ --user My_User_Name:My_Password \ https://satellite.example.com/api/v2/hosts?search=model=\"RHV+Hypervisor\" \ | python3 -m json.tool
$ curl \
--request GET \
--user My_User_Name:My_Password \
https://satellite.example.com/api/v2/hosts?search=model=\"RHV+Hypervisor\" \
| python3 -m json.tool
API 响应
6.1.7. 删除主机 复制链接链接已复制到粘贴板!
此请求删除名为 host1.example.com 的主机。
API 请求
curl \ --request DELETE \ --user My_User_Name:My_Password \ https://satellite.example.com/api/v2/hosts/host1.example.com \ | python3 -m json.tool
$ curl \
--request DELETE \
--user My_User_Name:My_Password \
https://satellite.example.com/api/v2/hosts/host1.example.com \
| python3 -m json.tool
6.1.8. 下载全主机引导磁盘镜像 复制链接链接已复制到粘贴板!
此请求通过其 ID 下载主机的完整引导磁盘镜像。
API 请求
curl \ --request GET \ --user My_User_Name:My_Password \ --output My_Image.iso \ https://satellite.example.com/api/bootdisk/hosts/host_ID?full=true
$ curl \
--request GET \
--user My_User_Name:My_Password \
--output My_Image.iso \
https://satellite.example.com/api/bootdisk/hosts/host_ID?full=true