VMware Cloud Community
Beechy
Contributor
Contributor

API .NET: Adding VM in Catalog to existing vApp

Hey all,

Here is my requirement: Deploy a VM, which is in my catalog, into an existing vApp, and customize it.

I'm currently using slightly modified code from the RecomposevApp community samples project to achieve part of what i want (i've modified it so it takes a list of vmRef for multiple machines to be . I've been able to create a vApp, and then recompose it with a VM contained in a vApp from a catalog i have.

The problem is, i have no idea how to name this VM before i recompose the vApp (it just gets the name from the template).

My current thinking is i need to get the child vms from the recomposed app, look for the app with the VM name in my catalog, then change it from there- but it feels like there should be a better way of doing it...

My code looks like this:

// Get objects required to connect to VMWare API 

API apiDetails = new API(URL, Username, Password, vDCName);

// Get the Parent vApp

ReferenceType vAppRef = apiDetails.vDC.GetVappRefByName(ParentvApp);

Vapp toBeRecomposed = Vapp.GetVappByReference(apiDetails.vcloudClient, vAppRef);

RecomposeVAppParamsType recomposeParamsType = apiDetails.CreateRecomposeParams(vAppRef,

new List<ReferenceType>{ apiDetails.SearchvAppTemplate(Template).GetChildren()[0].Reference });

Console.WriteLine("Recomposing vApp");

toBeRecomposed.RecomposeVapp(recomposeParamsType).WaitForTask(99999999);

0 Kudos
0 Replies