gpt4 book ai didi

rest - VCenter:REST API:如何将 ova 上传到内容库

转载 作者:行者123 更新时间:2023-12-02 05:00:46 24 4
gpt4 key购买 nike

我正在尝试使用 REST API 从 ova 创建虚拟机。我可以使用 Rest API 来做到这一点:

https://vcenter_ip/rest/com/vmware/vcenter/ovf/library-item/id:<library_item_id_ie_ova_item>?~action=deploy

为此,我通过 VSphere 客户端上传了 ova。 (内容库->选择库->导入项->从本地选择.ovf文件->(提示选择引用文件)从本地选择依赖的.vmdk)

但我想通过Rest API执行上传。

到目前为止我已完成的步骤是:

  1. 创建库

URL: https://vcenter_ip/rest/com/vmware/content/local-library

Method: POST
Headers:
Key:Content-Type
value: application/json
Request Body:
{
"create_spec": {
"name": "CL1",
"description": "CL1 Desc",
"publish_info": {
"authentication_method": "NONE",
"persist_json_enabled": false,
"published": false
},
"storage_backings": [
{
"datastore_id": "datastore-144",
"type": "DATASTORE"
}
],
"type": "LOCAL"
}
}
  • 创建库项目
  • URL:https://vcenter_ip/rest/com/vmware/content/library/item

    Method: POST
    Headers:
    Key:Content-Type
    value: application/json

    Request Body:
    {
    "create_spec": {
    "library_id": "<library_id",
    "description": "mydesc",
    "name": "Damn Small Linux",
    "type": "ovf"
    }
    }
  • 创建新的更新 session
  • URL: https://vcenter_ip/rest/com/vmware/content/library/item/update-session

    Method: POST
    Headers:
    Key:Content-Type
    value: application/json

    Request Body:
    {
    "create_spec":{
    "library_item_id": "<lib_item_id>"
    }
    }

    Response:
    {
    "value": "26f143a2-fb9d-4ed9-bd5f-c7be5825ee37:ec4f8df0-249f-4887-ab84-0933f86e106c"
    }

    接下来,我尝试将文件上传到内容库项目,这就是我遇到的问题。

  • 上传 ovf
  • 4(a)。请求端点上传.ovf文件

    URL:https://vcenter_ip/rest/com/vmware/content/library/item/updatesession/file/id:f539fb7e-af8f-4cc8-ad66-cdcbd80f5dc4%3Aec4f8df0-249f-4887-ab84-0933f86e106c?~action=add

    Method: POST
    Headers:
    Key:Content-Type
    value: application/json
    Key:update_session_id
    value: 26f143a2-fb9d-4ed9-bd5f-c7be5825ee37:ec4f8df0-249f-4887-ab84-0933f86e106c

    {
    "file_spec": {
    "source_type": "PUSH",
    "name": "Damn Small Linux.ovf",
    "size": 9
    }
    }

    响应正文:

    {
    "value": {
    "bytes_transferred": 0,
    "upload_endpoint": {
    "uri": "https://<vcenter_ip>:443/cls/data/1a5129a1-87e8-4650-855d-9041c493c475/Damn%20Small%20Linux.ovf"
    },
    "name": "Damn Small Linux.ovf",
    "source_type": "PUSH",
    "status": "WAITING_FOR_TRANSFER"
    }
    }

    4(b)。使用 put 请求上传到该 URI,并将文件作为多部分表单数据上传(我使用 postman 执行此操作 - 我通过 Vcenter api explorer 执行其余的调用)

    enter image description here

    4(c)。在更新 session 中验证文件

    URL: https://vcenter_ip/rest/com/vmware/content/library/item/updatesession/file/id:26f143a2-fb9d-4ed9-bd5f-c7be5825ee37%3Aec4f8df0-249f-4887-ab84-0933f86e106c?~action=validate
    Method: POST
    Headers:
    Key:Content-Type
    value: application/json
    Key:update_session_id
    value: 26f143a2-fb9d-4ed9-bd5f-c7be5825ee37:ec4f8df0-249f-4887-ab84-0933f86e106c

    Response Body:
    {
    "value": {
    "has_errors": true,
    "invalid_files": [
    {
    "error_message": {
    "args": [
    "Damn Small Linux.ovf",
    "1:1:PARSE_ERROR: Parse error: Unexpected character '-' (code 45) in prolog; expected '<'\r\n at [row,col {unknown-source}]: [1,1].\r\n"
    ],
    "default_message": "File Damn Small Linux.ovf was considered invalid. Reason: 1:1:PARSE_ERROR: Parse error: Unexpected character '-' (code 45) in prolog; expected '<'\r\n at [row,col {unknown-source}]: [1,1].\r\n.",
    "id": "com.vmware.vdcs.cls-main.update_session_file_validation"
    },
    "name": "Damn Small Linux.ovf"
    }
    ],
    "missing_files": []
    }
    }

    但这与我通过 vsphere 客户端成功上传时上传的文件相同。

    这里有什么问题吗?接下来我该如何上传引用 .vmdk?

    最佳答案

    这是一个老问题,但我会给出答案,以防有人遇到这个问题:

    要使其正常工作,您的数据上传 PUT 中需要进行两项设置:

    1. 将 header Content-Type设置为application/octet-stream
    2. 在正文下,确保为 (ovf) 文件选择二进制

    关于rest - VCenter:REST API:如何将 ova 上传到内容库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43676320/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com