This example shows how to deploy a virtual machine from a local library item in a resource pool. You can also see how to verify the results of the deployment operation.

This example uses the steps that are described in the Deploy a Virtual Machine or Virtual Appliance from an OVF Package in a Content Library procedure.

import com.vmware.content.library.Item;
import com.vmware.vcenter.ovf.LibraryItemTypes.DeploymentResult;
import com.vmware.vcenter.ovf.LibraryItemTypes.DeploymentTarget;
import com.vmware.vcenter.ovf.LibraryItemTypes.OvfSummary;
import com.vmware.vcenter.ovf.LibraryItemTypes.ResourcePoolDeploymentSpec;
import com.vmware.vcloud.suite.samples.common.ServiceManager;
import com.vmware.vcloud.suite.samples.vim.helpers.VimUtil;
import com.vmware.vim25.ManagedObjectReference;
import java.util.UUID;

...

// Create a virtual machine deployment specification to accept any network resource.
ResourcePoolDeploymentSpec deploymentSpec = new ResourcePoolDeploymentSpec();
String vmName = "MyVirtualMachine"; 
deploymentSpec.setName(vmName);
deploymentSpec.setAcceptAllEULA(true);

 
// Create a deployment target specification to accept any resource pool.
ServiceManager serviceManager = getServiceManager(null);
String clusterName = "myCluster";
ManagedObjectReference clusterMoRef = VimUtil.getCluster(serviceManager.getVimPortType(), serviceManager.getServiceContent(), clusterName);
DeploymentTarget deploymentTarget = new DeploymentTarget();
deploymentTarget.setResourcePoolId(clusterMoRef.getValue());


// Retrieve the library items OVF information and use it for populating the 
// deployment spec instance.
LibraryItem libItemStub = stubFactory.createStub(LibraryItem.class, myStubConfiguration);
OvfSummary ovfSummary = libItemStub.filter(libItemId, deploymentTarget);
deploymentSpec.setAnnotation(ovfSummary.getAnnotation());
String clientToken = UUID.randomUUID().toString();
DeploymentResult result = libItemStub.deploy(clientToken,libItemId,
                                                           deploymentTarget,
                                                           deploymentSpec);
 
// Verify the status of the resource deployment.
System.out.printf("Resource Type=%s (ID=%s) status: ",
                  result.getResourceId().getType(),
                  result.getResourceId().getId());
  
  if (result.getSucceeded() == true) {
      System.out.println("Resource instantiated.");
  
  } else {
      System.out.println("Instantiation failed.");
  }