Thursday, March 24, 2011

Composting vApp(s)

I was so tempted to write code here but I should point the readers to the community (link available in the resource section) where complete example is available. Never the less let me add the pointers here.

When we compose a vApp, we are creating a new vApp which can contain its child VM(s) from various sources. These sources can be VM from an existing template or a VM from existing vApp.  Simply put we are picking up assortment of VM that we like and making a copy of them to be part of the new vApp.
Let’s see step by step, how to go about it.
1.    First and foremost we need to create composition parameters by using ComposeVAppParams object.  We need to set basic information such as Name, Boolean indicating if we want to deploy it and so forth. We also need to set up the instantiation details as we did while instantiating template to vApp.  That basically involves setting up the vApp Network configuration.
2.    Composition parameters contain a list of ‘Source Items’. These source items are nothing but references to VM that need to be added to the composed vApp.

List<SourcedCompositionItemParamType> items =  composeVAppParamsType.getSourcedItem();
ReferenceType vappTemplateVMRef = new ReferenceType();
vappTemplateVMRef.setHref(vmHref);
vappTemplateVMRef.setName(“ChildVm1”);
vappTemplateItem.setSource(vappTemplateVMRef);
   
// Now add this VM reference to the Composition parameters’ item list
items.add(vappTemplateItem);
// More items (VM) can be added to this ‘items’ list

3.    Optionally set up networking for the all child VM(s) now.

One can chose to use the same VM and add it multiple times such that the composed vApp has  more than one such child VM.  It is necessary to use different name for the Reference used in the step 2 above.  We are mainly interested in the HREF that we set on the reference object.


The actual step of composing the vApp using SDK looks as simple as
Vapp vapp = vdc.composeVapp(createComposeParams(vappTemplateRef, vdc));

The actual work is creating the composing details
When recomposing the vApp if you are adding new VM(s) then the steps are exactly same as above where in actual work is creating RecomposeVAppParamsType. You need to add new SourcedComposition Item. If VM needs to be deleted from existing vApp then you need to populate the ‘Delete Item’ list.

// create the recompose vapp params type.
RecomposeVAppParamsType recomposeVAppParamsType = new RecomposeVAppParamsType();
recomposeVAppParamsType.setName("RecomposedVapp");
       
 // adding the vm item.
 List<SourcedCompositionItemParamType> newItems = recomposeVAppParamsType.getSourcedItem();
  newItems.add(vmItem);

2 comments:

  1. Hi,
    you mention "readers to the community (link available in the resource section)". Actually I can't find the link. Could you provide me with the URL? Another question I have is, if there is an option to create an empty VM into a Vapp by defining CPU, RAM adding NICs and HDs?

    Thanks!

    ReplyDelete
  2. Hi

    Is it possible to clone a vm from a template in the catalog externally and then do the following:

    -create a new vapp
    - copy the network section from the template to the new vapp
    -use the vm that was cloned externally and add it to the new vapp

    I guess doing the second part is easy as you explained in your post. I was more concerned about the first.

    ReplyDelete