importVm(String name, VcResourcePool rp, VcDatastore ds,
VcNetwork network, String ovfPath)
throws Exception {
ManagedObjectReference vmRef;
AuAssert.check(VcContext.isInTaskSession());
VcService vcs = VcContext.getService();
CreateImportSpecParams importParams = new CreateImportSpecParamsImpl();
importParams.setDeploymentOption("");
importParams.setLocale("");
importParams.setEntityName(name);
NetworkMapping[] nets = {
new NetworkMappingImpl("Network 1", network.getMoRef()),
new NetworkMappingImpl("Network 2", network.getMoRef())
};
importParams.setNetworkMapping(nets);
importParams.setIpAllocationPolicy(IpAllocationPolicy.transientPolicy.toString());
importParams.setDiskProvisioning("thin");
// create import spec from ovf
CreateImportSpecResult specResult = vcs.getOvfManager().createImportSpec(
loadOvfContents(ovfPath), rp.getMoRef(), ds.getMoRef(), importParams);
AuAssert.check(specResult.getError() == null && specResult.getWarning() == null);
VmImportSpec importSpec = (VmImportSpec)specResult.getImportSpec();
// start importing the vApp and get the lease to upload vmdks
HttpNfcLease nfcLease = rp.importVApp(importSpec);