7.3.11. 异步请求
API 执行异步
POST
请求,除非用户用 Expect: 201-created
标头覆盖它们。
例如,某些资源(如虚拟机、磁盘、快照和模板)会异步创建。创建异步资源的请求会导致
202 Accepted
状态。202 Accepted
资源的初始文档结构还包含 creation_status
元素和创建状态更新的链接。例如:
POST /ovirt-engine/api/collection HTTP/1.1 Accept: application/xml Content-Type: application/xml <resource> <name>Resource-Name</name> </resource> HTTP/1.1 202 Accepted Content-Type: application/xml <resource id="resource_id" href="/ovirt-engine/api/collection/resource_id"> <name>Resource-Name</name> <creation_status> <state>pending</state> </creation status> <link rel="creation_status" href="/ovirt-engine/api/collection/resource_id/creation_status/creation_status_id"/> ... </resource>
到
creation_status
链接的 GET
请求提供创建状态更新:
GET /ovirt-engine/api/collection/resource_id/creation_status/creation_status_id HTTP/1.1 Accept: application/xml HTTP/1.1 200 OK Content-Type: application/xml <creation id="creation_status_id" href="/ovirt-engine/api/collection/resource_id/creation_status/creation_status_id"> <status> <state>complete</state> </status> </creation>
覆盖异步资源创建需要一个
Expect: 201-created
标头:
POST /ovirt-engine/api/collection HTTP/1.1 Accept: application/xml Content-Type: application/xml Expect: 201-created <resource> <name>Resource-Name</name> </resource>