Thursday, January 6, 2011

How to create a new vApp

There are many ways one can create a vApp in vCloud, and they vary depending on where one starts. Here are some of the options. As promised we will use the SDK to illustrate the example(s).

  • Create one form a template (POST .../api/v1.0/vdc/<vdc-id>/action/instantiateVAppTemplate)
  • Start from OVF package.
  • Assorted vApp:
    • Compose new vApp from templates and/or existing vApp
      (POST .../api/v1.0/vdc/<vdc-id>/action/composeVAp)
    • Recompose vApp to add/delete VM in it.
      POST .../api/v1.0/vApp/<vapp-id>/action/recomposeVApp (This is not really creating a new vApp so we will visit it next time).
  • Clone from existing vApp POST .../api/v1.0/vdc/<vdc-id>/action/cloneVApp
  • Importing from vSphere 
Let’s visit the above one by one:
1.    Start from OVF Package:
This is the most ground up operation one can think of for creating a vApp. You are basically loading the vApp from the OVF as a vApp Template in a catalog and then its matter of details for instantiating vApp from template as in #2. So let’s look at the first thing first: uploading OVF as vApp Template. The OVF file essentially describes how the vApp is configured using various ‘Sections’ and bundles with the  disk files of the virtual machine. Even before we upload this vApp description we need to create a ‘vApp Template’ object in the vCloud. The SDK provides a method on Vdc object ‘createVappTemplate’.

UploadVAppTemplateParamsType vappTemplParams = new
UploadVAppTemplateParamsType();

vappTemplParams.setDescription("New Template Description");
vappTemplParams.setName("NewVAppTemplate");

VappTemplate vappTemplate = vdc.createVappTemplate(vappTemplParams);

It goes without saying that this template needs to be later added to a Catalog. Once the object is created we upload the OVF descriptor using method on newly created vApp template ‘uploadOVFFile’.

File ovfFile = new File(ovfFileLocation);

FileInputStream ovfFileInputStream = new FileInputStream(ovfFile);

vappTemplate.uploadOVFFile(ovfFileInputStream, ovfFile.length());

 As a result of resolving the OVF descriptor, the Template object knows how many virtual machines are part of the vApp and how many disk every machine has. We are yet to upload the disk files so as a pre-requisite for that it creates a place holder link for those disk files and adds details to the vApp Template object. Make sure that you refresh the vApp Template object on the client side so as to get this newly available configuration data. Now you can upload the disk files to the cloud and take a coffee break.

// wait to make sure OVF descriptor is uploaded.
// Refresh the vApp Template object.
File vmdkFile = new File(vmdkFileLocation);
FileInputStream vmdkFileInputStream = new FileInputStream(vmdkFile);

vappTemplate.uploadFile(vmdkfileName, vmdkFileInputStream, vmdkFile.length());

 Once done go on to the next step of creating a vApp from template as follows. All this available in the sample provided as part of the vCloud SDK.