简体   繁体   中英

How do we add custom properties to a VMWare VM using the vCloud Java API?

I am using the vCloud Java API provided by VMWare to automate the creation of VMs in their enterprise cloud solution. I have been able to do this just fine. However I am not able to figur out to set custom properties on the VM. I have checked out the VMWare API reference and I cannot find anything which intuitively suggests how to do this. Any insight may be helpful?

Here is the code I have written till now to configure the VM and I want to add the custom property configuration to it.

private static SourcedCompositionItemParamType addVAppTemplateItem(String vAppNetwork, MsgType networkInfo, String vmHref, String ipAddress, String vmName) {
    SourcedCompositionItemParamType vappTemplateItem = new SourcedCompositionItemParamType();
    ReferenceType vappTemplateVMRef = new ReferenceType();
    vappTemplateVMRef.setHref(vmHref);
    vappTemplateVMRef.setName(vmName);
    vappTemplateItem.setSource(vappTemplateVMRef);


    NetworkConnectionSectionType networkConnectionSectionType = new NetworkConnectionSectionType();
    networkConnectionSectionType.setInfo(networkInfo);

    NetworkConnectionType networkConnectionType = new NetworkConnectionType();
    networkConnectionType.setNetwork(vAppNetwork);
    networkConnectionType.setIpAddressAllocationMode(IpAddressAllocationModeType.MANUAL.value());
    networkConnectionType.setIpAddress(ipAddress);
    networkConnectionType.setIsConnected(true);
    networkConnectionSectionType.getNetworkConnection().add(networkConnectionType);

    InstantiationParamsType vmInstantiationParamsType = new InstantiationParamsType();
    List<JAXBElement<? extends SectionType>> vmSections = vmInstantiationParamsType.getSection();
    vmSections.add(new ObjectFactory().createNetworkConnectionSection(networkConnectionSectionType));
    vappTemplateItem.setInstantiationParams(vmInstantiationParamsType);
    return vappTemplateItem;
}

After going through the REST API documentation I realized that you put Custom Properties into the ProductSection. Unfortunately I could not figure out a way to add a ProductSection when creating a VApp so added the ProductSection after creating the VApp by retrieving the VM and calling updateProductSections on it.

Response from VMWare community forum

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM