我正在使用VMWare vCenter REST API从OVF库项目部署新的虚拟机。该API的一部分允许使用additional_paramaters,但我无法使其正常运行。具体来说,我想为自定义OVF模板属性设置PropertyParams

从OVF部署VM时,我使用以下REST API:
POST https://{server}/rest/com/vmware/vcenter/ovf/library-item/id:{ovf_library_item_id}?~action=deploy

我尝试了许多结构,要么都以POST成功而已,但是参数被完全忽略,或者出现500 Internal Server错误,并显示有关未能转换properties结构的消息:



从文档中看似正确的有效负载(但由于上面的错误而失败):

deployment_spec : {
  /* ... */

  additional_parameters : [
    {
      type : 'PropertyParams',
      properties : [
        {
          id : 'my_property_name',
          value : 'foo',
        }
      ]
    }
  ]
}

给定一个包含以下内容的OVF:
<ProductSection>
  <Info>Information about the installed software</Info>
  <Product>MyProduct</Product>
  <Vendor>MyCompany</Vendor>
  <Version>1.0</Version>
  <Category>Config</Category>
  <Property ovf:userConfigurable="true" ovf:type="string" ovf:key="my_property_name" ovf:value="">
    <Label>My Property</Label>
    <Description>A custom property</Description>
  </Property>
</ProductSection>

对于其他属性类型(例如boolean),这也将失败。

注意I have posted on the vCenter forums as well

最佳答案

我遇到了同样的问题,我通过浏览vapi结构/com/vmware/vapi/metadata/metamodel/structure/id:<idstructure>成功解决了这个问题

这是我的发现:

首先,使用filter api获取属性结构:
https://{{vc}}/rest/com/vmware/vcenter/ovf/library-item/id:300401a5-4561-4c3d-ac67-67bc7a1a6
然后,使用类com.vmware.vcenter.ovh.property_params进行部署。以示例为例将更加清楚:

{
"deployment_spec": {
    "accept_all_EULA": true,
    "name": "clientok",
    "default_datastore_id": "datastore-10",
    "additional_parameters": [
    {
        "@class": "com.vmware.vcenter.ovf.property_params",
            "properties":
            [
                {
                    "instance_id": "",
                    "class_id": "",
                    "description": "The gateway IP for this virtual appliance.",
                    "id": "gateway",
                    "label": "Default Gateway Address",
                    "category": "LAN",
                    "type": "ip",
                    "value": "10.1.2.1",
                    "ui_optional": true
                }

            ],
        "type": "PropertyParams"
        }
    ]
}

09-27 14:17