PropertyParams when deploying VM from OVF

送分小仙女□ 提交于 2021-02-07 14:54:50

问题


I am using the VMWare vCenter REST API to deploy new Virtual Machines from OVF library items. Part of the API allows for additional_paramaters but I am unable to get it to function properly. Specifically, I would like to set the PropertyParams for custom OVF template properties.

When deploying VM from OVF, I am using the following REST API: POST https://{server}/rest/com/vmware/vcenter/ovf/library-item/id:{ovf_library_item_id}?~action=deploy

I have tried many structures and either end up with the POST succeeding but the parameters completely ignored, or with a 500 Internal Server error with a message about failing to convert the properties structure:

Could not convert field 'properties' of structure 'com.vmware.vcenter.ovf.property_params'

The payload that seems correct from the documentation (but fails with the error above):

deployment_spec : {
  /* ... */

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

Given an OVF that contains the following:

<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>

This also fails for other property types such as boolean.

Note that I have posted on the vCenter forums as well.


回答1:


I had the same issue, i success to solve it by browsing the vapi structure /com/vmware/vapi/metadata/metamodel/structure/id:<idstructure>

Here is my finding :

firstly, get your properties structure by using the filter api :

https://{{vc}}/rest/com/vmware/vcenter/ovf/library-item/id:300401a5-4561-4c3d-ac67-67bc7a1a6

Then, to deploy, use the class com.vmware.vcenter.ovh.property_params. It will be more clear with the exemple :

{
"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"
        }
    ]
}


来源:https://stackoverflow.com/questions/47912744/propertyparams-when-deploying-vm-from-ovf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!