第 1 章 REST API
您可以使用 REST API 来检索有关供应商、物理基础架构供应商和物理服务器的信息。如果需要与您的物理基础架构中的服务器相关的信息,您可以使用 CloudForms REST API。
开始之前
若要使用 REST API,您必须以有权访问该 API 的用户身份登录 CloudForms Management Engine API。默认用户为 admin,密码为 smartvm。
使用以下 URL 来访问 CloudForms REST API:
<CloudForms_address>:<port>/api
例如:
localhost:3000/api
1.1. 检索供应商详细信息
若要检索所有供应商的信息,请使用以下请求 URL:
GET <CloudForms_address>:<port>/api/providers
系统将返回含有下列键的 JSON 回复。
actions (可用操作的列表) count (供应商的总数) name (URI 名称) pages (页数) resource (受 CloudForms 管理的各个供应商的 URL 的列表 ) subcount (返回的供应商数目)
示例
若要检索供应商的所有信息,请使用 ?expand=resources 查询参数,例如:
GET localhost:3000/api/providers?expand=resources
若要检索供应商的某一具体信息(如名称和 ID),请使用 ?expand=resources&attributes=<attribute_list> 查询参数,例如:
GET localhost:3000/ api/providers?expand=resources&attributes=id,name
若要检索供应商的其他信息(如端口、主机名和 IP 地址),请使用 ?expand=resources&attributes=<attribute_list> 查询参数,例如:
GET localhost:3000/api/providers?expand=resources&attributes=port,hostname,ipaddress
若要检索仅与 Lenovo 物理基础架构供应商相关的信息,请对所有供应商资源使用 ?expand=resources&filter[]=type=<provider_type> 属性,例如:
GET localhost:3000/api/providers?expand=resources&filter[]=type=ManageIQ::Providers::Lenovo::PhysicalInfraManager
1.2. 按照 ID 检索供应商详细信息
若要检索特定供应商的信息,请使用以下请求 URL,其中 <provider_ID> 是供应商的唯一标识符:
GET <CloudForms_address>:<port>/api/providers/<provider_ID>
系统将返回含有下列键的 JSON 回复。
href id name created_on updated_on guid zone_id type last_refresh_date tenant_id enabled options actions
示例
若要检索该供应商的具体信息(如名称和 ID),请使用 ?attributes=<attribute_list> 查询参数,例如:
GET localhost:3000/api/providers/<provider_ID>?expand=resources&attributes=id,name
若要检索该供应商的其他信息(如端口、主机名和 IP 地址),请使用 ?attributes=<attribute_list> 查询参数,例如:
GET localhost:3000/api/providers/<provider_ID>?expand=resources &attributes=port,hostname,ipaddress
1.3. 执行物理基础架构供应商操作
您可以使用 REST API 对物理基础架构供应商执行操作,如创建、修改和删除。
注意:要对物理基础架构供应商执行操作,您必须使用您首选的工具或库创建基本的身份验证信息,在使用 REST API 时使用 CloudForms 实例的用户名和密码。
1.3.1. 创建 Lenovo 物理基础架构供应商
若要创建 Lenovo 物理基础架构供应商,请使用以下请求 URL 和 JSON 请求正文发送 POST 请求。
POST <CloudForms_address>:<port>/api/providers
请求正文:
{
"action": "create",
"credentials": {
"password": "<PASSWORD>",
"userid": "<USERNAME>"
},
"hostname": "<LENOVO XCLARITY ADMINISTRATOR ADDRESS>",
"name": "<NAME>",
"port": "<THE SERVICE PORT>",
"type": "ManageIQ::Providers::Lenovo::PhysicalInfraManager"
}1.3.2. 修改 Lenovo 物理基础架构供应商的属性
若要修改 Lenovo 物理基础架构供应商的属性,请使用以下请求 URL 和 JSON 请求正文发送 POST 请求。
POST <CloudForms_address>:<port>/api/providers
请求正文:
{
"action":"edit",
"credentials": {
"password":"<new_passowrd>",
"userid":"<new_user_name>"
},
"hostname":"<New_Lenovo_XClarity_Administrator_address>",
"name":"<new_provider_name>",
"port":"<new_service_port>"
}1.3.3. 刷新所有供应商的信息
若要刷新所有供应商的信息,请使用以下请求 URL 和 JSON 请求正文发送 POST 请求。
POST <CloudForms_address>:<port>/api/providers
请求正文:
{
"action":"refresh"
}1.3.4. 删除物理基础架构供应商
要删除特定的供应商:
使用以下请求 URL 发送 DELETE 请求。
DELETE <CloudForms_address>:<port>/api/providers/<provider_ID>
使用以下请求 URL 和 JSON 请求正文发送 POST 请求。
POST <CloudForms_address>:<port>/api/providers/<provider_ID>
请求正文:
{ "action":"delete" }
1.3.5. 对多个物理基础架构供应商执行操作
若要对多个物理基础架构供应商执行操作,请使用以下请求 URL 和 JSON 请求正文发送 POST 请求。
POST <CloudForms_address>:<port>/api/providers
请求正文:
{
"action":"<action>",
"resources": [{
"href":"<provider_ID>"
},
{
"href":"<provider_ID>"
}]
}1.4. 检索物理服务器详细信息
若要检索所有物理服务器的信息,请使用以下请求 URL:
GET <CloudForms_address>:<port>/api/physical_servers
系统将返回含有下列键的 JSON 回复。
actions (可用操作的列表) count (物理服务器的数量) name (URI 名称) pages (页数) resource (各物理服务器的 URL 的列表 ) subcount (返回的物理服务器数量)
示例
若要检索物理服务器的所有信息,请使用 ?expand=resources 查询参数,例如:
GET localhost:3000/api/physical_servers?expand=resources
若要检索物理服务器的某一具体信息(如名称和 ID),请使用 ?expand=resources&attributes=<attribute_list> 查询参数,例如:
GET localhost:3000/api/physical_servers?expand=resources&attributes=id,name
若要检索物理服务器的具体信息(如固件、网络、客户设备和资源详细信息),请使用 ?expand=resources&attributes=<attribute_list> 查询参数,例如:
GET localhost:3000/api/physical_servers?expand=resources&attributes= hardware.firmwares,hardware.networks,hardware.guest_devices,hardware.assets_details
若要检索仅与特定物理服务器相关的信息,请对所有物理服务器资源使用 ?expand=resources&filter[]=name=<server_name> 查询属性,例如:
GET localhost:3000/api/physical_servers?expand=resources&filter[]=name=Server1-20127X5462
1.5. 按照 ID 检索物理服务器详细信息
若要检索特定物理服务器的信息,请使用以下请求 URL:
GET <CloudForms_address>:<port>/api/physical_servers/<server_ID>
系统将返回含有下列键的 JSON 回复。
actions created_at ems_id ems_ref field_replaceable_unit health_state hostname href location_led_state machine_type manufacturer model name power_state product_name serial_number type uid_ems updated_at vendor
示例
若要检索特定物理服务器的某一具体信息(如名称和 ID),请使用 ?expand=resources&attributes=<attribute_list> 查询参数,例如:
GET localhost:3000/api/physical_servers/<server_ID>?expand=resources&attributes=id,name
若要检索特定物理服务器的具体信息(如固件、网络、客户设备和资源详细信息),请使用 ?expand=resources&attributes=<attribute_list> 查询参数,例如:
GET localhost:3000/api/physical_servers/<server_ID>?expand=resources &attributes=hardware.firmwares,hardware.networks,hardware.guest_devices,hardware.assets_details
1.6. 执行物理服务器操作
您可以使用 REST API 对物理服务器执行管理任务,如开机和关机、重启,以及更改位置 LED 状态。
注意:要对物理服务器执行操作,您必须使用您首选的工具或库创建基本的身份验证信息,再输入您的用户名和密码来访问 CloudForms REST API。
1.6.1. 打开物理服务器电源
若要打开特定物理服务器的电源,请使用以下请求 URL 和 JSON 请求正文发送 POST 请求。
POST <CloudForms_address>:<port>/api/physical_servers/<server_ID>
请求正文:
{
"action":"power_on"
}1.6.2. 关闭物理服务器电源
若要关闭操作系统并关闭特定物理服务器的电源,请使用以下请求 URL 和 JSON 请求正文发送 POST 请求。
POST <CloudForms_address>:<port>/api/physical_servers/<server_ID>
请求正文:
{
"action":"power_off"
}1.6.3. 立即关闭物理服务器电源
若要立即关闭特定物理服务器的电源,请使用以下请求 URL 和 JSON 请求正文发送 POST 请求。
POST <CloudForms_address>:<port>/api/physical_servers/<server_ID>
请求正文:
{
"action":"power_off_now"
}1.6.4. 重启物理服务器
若要关闭操作系统并重启特定的物理服务器,请使用以下请求 URL 和 JSON 请求正文发送 POST 请求。
POST <CloudForms_address>:<port>/api/physical_servers/<server_ID>
请求正文:
{
"action":"restart"
}1.6.5. 立即重启物理服务器
若要立即重启特定的物理服务器,请使用以下请求 URL 和 JSON 请求正文发送 POST 请求。
POST <CloudForms_address>:<port>/api/physical_servers/<server_ID>
请求正文:
{
"action":"restart_now"
}1.6.6. 将物理服务器的位置 LED 状态更改为闪烁
若要将特定服务器的位置 LED 状态更改为闪烁,请使用以下请求 URL 和 JSON 请求正文发送 POST 请求。
POST <CloudForms_address>:<port>/api/physical_servers/<server_ID>
请求正文:
{
"action":"blink_loc_led"
}1.6.7. 对多台物理服务器执行操作
若要对多台物理服务器执行操作,请使用以下请求 URL 和 JSON 请求正文发送 POST 请求。
POST <CloudForms_address>:<port>/api/physical_servers
请求正文:
{
"action":"<action>",
"resources": [{
"href":"<server_ID>"
},
{
"href":"<server_ID>"
}]
}
Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.