vCloud: Create and configure a vm in vApp

2.7k Views Asked by At

I am trying to deploy Virtual Machines from a template into a vApp using the vCloud rest API. I feel that there should be a way to configure a vm as I am spawning it (Since the UI seems to do that) but haven't found a way.

I've been focusing my efforts on recomposing a vApp to add a vm to it. The below example will add a vm but I haven't figured out to configure the vm until after it has been created. Specifically I want to set the VM Name, host name, and IP settings of the vm.

<?xml version="1.0" encoding="UTF-8"?>
<RecomposeVAppParams
   xmlns="http://www.vmware.com/vcloud/v1.5"
   xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1">
   <SourcedItem sourceDelete="false">
       <Source href="templateUri" />
   </SourcedItem>
   <AllEULAsAccepted>true</AllEULAsAccepted>
</RecomposeVAppParams>

After the vm is created I can reconfigure it but neither the network settings or host name actually change. The vCloud Director UI tells me they have changed but looking on the guest os shows that the settings have not changed.

Change host name example (doesn't work):

<vcloud:GuestCustomizationSection
   xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
   xmlns:vcloud="http://www.vmware.com/vcloud/v1.5"
   href="vmUri/guestCustomizationSection/"
   ovf:required="false"
   type="application/vnd.vmware.vcloud.guestCustomizationSection+xml">
       <ovf:Info>Specifies Guest OS Customization Settings</ovf:Info>
       <vcloud:ComputerName>newName</vcloud:ComputerName>
</vcloud:GuestCustomizationSection>

Has anyone been able to configure a VM as you deploy it. Otherwise does anyone know how to effectively configure settings of a VM after it has been deployed. Working XML examples would be amazing but I would still appreciate help in other forms.

2

There are 2 best solutions below

0
On

The closest I have been able to come to this is to deploy a vApp from a catalog somewhat customizing it in the process. This is not exactly what you asked for, but I hope it helps.

<?xml version="1.0" encoding="UTF-8"?>
<InstantiateVAppTemplateParams
   xmlns="http://www.vmware.com/vcloud/v1.5"
   xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
   name="<MyVappName"
   deploy="false"
   powerOn="false">
   <Description>vApp I deployed through REST API...</Description>
   <InstantiationParams>
   <NetworkConfigSection>
    <ovf:Info>Configuration parameters for logical networks</ovf:Info>
    <NetworkConfig networkName="App-Network-1">
     <Configuration>
      <ParentNetwork href="https://vcd-url/api/network/331a8ee3-33fd-4e4a-878e-1a6dce772fea" />
      <FenceMode>bridged</FenceMode>
     </Configuration>
    </NetworkConfig>
   </NetworkConfigSection>
   </InstantiationParams>
   <Source
      href="https://vcd-url/api/vAppTemplate/vappTemplate-d11de298-3041-2ae2-5e81-3ac2b4255423" />
</InstantiateVAppTemplateParams>
0
On

Just use the SDK for this task. Download the example and the library. Add the library to proj and call function from there. The SDK has already and Utility library that handle the http communication with the vcloud creating the requests and serve the answers using serialization. If you really want to do the request by yourself you just run the example in SDK put Fiddler to spy the communication and get the exact request and reproduce it. I know because first time I have started making http request using the documentation and get in trouble.