Home > vSphere API > How to Import and Export OVF Packages

How to Import and Export OVF Packages

This article is based on a similar one at vSphere Java API home page. At that time, one of VMware community members sent me an email for samples of using OvfManager APIs. Then I went to office on a Saturday writing two samples, which have been validated by several folks as “working” samples.

The purpose of the samples are to illustrate the vSphere APIs. Let’s take a look at them one by one.

Time to learn how to "Google" and manage your VMware and clouds in a fast and secure

HTML5 App

First, ExportOvfToLocal.java. This sample shows how to download either a VM or vApp to your local machine. The typical flow is:

  • Find the VM or vApp
  • Call their exportVm() or exportVApp() methods and get HttpNfcLease
  • Set lease time out
  • Wait for HttpNfcLease until it’s ready
  • From the HttpNfcLease.info property, find the all URLs from which you download the vmdk files
  • Call OvfManager.createDescriptor() API to create the content of ovf and save it to a file along with downloaded vmdk files.
  • Release the lease by calling httpNfcLeaseComplete() method
/*================================================================================
Copyright (c) 2008 VMware, Inc. All Rights Reserved.
<pre>Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

 * Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

 * Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

 * Neither the name of VMware, Inc. nor the names of its contributors may be used
to endorse or promote products derived from this software without specific prior
written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
================================================================================*/
package com.vmware.vim25.mo.samples.ovf;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;

import com.vmware.vim25.HttpNfcLeaseDeviceUrl;
import com.vmware.vim25.HttpNfcLeaseInfo;
import com.vmware.vim25.HttpNfcLeaseState;
import com.vmware.vim25.OvfCreateDescriptorParams;
import com.vmware.vim25.OvfCreateDescriptorResult;
import com.vmware.vim25.OvfFile;
import com.vmware.vim25.mo.HostSystem;
import com.vmware.vim25.mo.HttpNfcLease;
import com.vmware.vim25.mo.InventoryNavigator;
import com.vmware.vim25.mo.ManagedEntity;
import com.vmware.vim25.mo.ServiceInstance;
import com.vmware.vim25.mo.VirtualApp;
import com.vmware.vim25.mo.VirtualMachine;

/**
 * Exports VMDK(s) and OVF Descriptor for a VM or a vApp.
 * http://vijava.sf.net
 * @author Steve Jin (sjin at vmware.com)
 */

public class ExportOvfToLocal
{
   public static LeaseProgressUpdater leaseProgUpdater;

	 public static void main(String[] args) throws Exception
	  {
	    if (args.length != 7)
	    {
	      System.out.println("java ExportOvfToLocal <SdkUrl> <username> <password> <VappOrVmName> <hostip> <VirtualMachine|VirtualApp> <localDir>");
	      System.out.println("java ExportOvfToLocal https://10.20.152.74/sdk root password NewVM1 10.20.152.74 VirtualMachine C:\\Temp\\ovf\\");
	      return;
	    }

	    ServiceInstance si = new ServiceInstance(new URL(args[0]), args[1], args[2], true);

	    String vAppOrVmName = args[3];
	    String hostip = args[4];
	    String entityType = args[5];
	    String targetDir = args[6];

	    HostSystem host = (HostSystem) si.getSearchIndex().findByIp(null, hostip, false);

	    System.out.println("Host Name : " + host.getName());
	    System.out.println("Network : " + host.getNetworks()[0].getName());
	    System.out.println("Datastore : " + host.getDatastores()[0].getName());

	    InventoryNavigator iv = new InventoryNavigator(si.getRootFolder());

	    HttpNfcLease hnLease = null;

	    ManagedEntity me = null;
	    if (entityType.equals("VirtualApp"))
	    {
	      me = iv.searchManagedEntity("VirtualApp", vAppOrVmName);
	      hnLease = ((VirtualApp)me).exportVApp();
	    }
	    else
	    {
	      me = iv.searchManagedEntity("VirtualMachine", vAppOrVmName);
	      hnLease = ((VirtualMachine)me).exportVm();
	    }

	    // Wait until the HttpNfcLeaseState is ready
	    HttpNfcLeaseState hls;
	    for(;;)
	    {
	      hls = hnLease.getState();
	      if(hls == HttpNfcLeaseState.ready)
	      {
	        break;
	      }
	      if(hls == HttpNfcLeaseState.error)
	      {
	        si.getServerConnection().logout();
	        return;
	      }
	    }

	    System.out.println("HttpNfcLeaseState: ready ");
	    HttpNfcLeaseInfo httpNfcLeaseInfo = hnLease.getInfo();
	    httpNfcLeaseInfo.setLeaseTimeout(300*1000*1000);
	    printHttpNfcLeaseInfo(httpNfcLeaseInfo);

	    //Note: the diskCapacityInByte could be many time bigger than
	    //the total size of VMDK files downloaded.
	    //As a result, the progress calculated could be much less than reality.
	    long diskCapacityInByte = (httpNfcLeaseInfo.getTotalDiskCapacityInKB()) * 1024;

	    leaseProgUpdater = new LeaseProgressUpdater(hnLease, 5000);
	    leaseProgUpdater.start();

	    long alredyWrittenBytes = 0;
	    HttpNfcLeaseDeviceUrl[] deviceUrls = httpNfcLeaseInfo.getDeviceUrl();
	    if (deviceUrls != null)
	    {
	      OvfFile[] ovfFiles = new OvfFile[deviceUrls.length];
	      System.out.println("Downloading Files:");
	      for (int i = 0; i < deviceUrls.length; i++)
	      {
	        String deviceId = deviceUrls[i].getKey();
	        String deviceUrlStr = deviceUrls[i].getUrl();
	        String diskFileName = deviceUrlStr.substring(deviceUrlStr.lastIndexOf("/") + 1);
	        String diskUrlStr = deviceUrlStr.replace("*", hostip);
	        String diskLocalPath = targetDir + diskFileName;
	        System.out.println("File Name: " + diskFileName);
	        System.out.println("VMDK URL: " + diskUrlStr);
	        String cookie = si.getServerConnection().getVimService().getWsc().getCookie();
	        long lengthOfDiskFile = writeVMDKFile(diskLocalPath, diskUrlStr, cookie, alredyWrittenBytes, diskCapacityInByte);
	        alredyWrittenBytes += lengthOfDiskFile;
	        OvfFile ovfFile = new OvfFile();
	        ovfFile.setPath(diskFileName);
	        ovfFile.setDeviceId(deviceId);
	        ovfFile.setSize(lengthOfDiskFile);
	        ovfFiles[i] = ovfFile;
	      }

	      OvfCreateDescriptorParams ovfDescParams = new OvfCreateDescriptorParams();
	      ovfDescParams.setOvfFiles(ovfFiles);
	      OvfCreateDescriptorResult ovfCreateDescriptorResult =
	        si.getOvfManager().createDescriptor(me, ovfDescParams);

	      String ovfPath = targetDir + vAppOrVmName + ".ovf";
	      FileWriter out = new FileWriter(ovfPath);
	      out.write(ovfCreateDescriptorResult.getOvfDescriptor());
	      out.close();
	      System.out.println("OVF Desriptor Written to file: " + ovfPath);
	    }

	    System.out.println("Completed Downloading the files");
	    leaseProgUpdater.interrupt();
	    hnLease.httpNfcLeaseProgress(100);
	    hnLease.httpNfcLeaseComplete();

	    si.getServerConnection().logout();
	  }

	private static void printHttpNfcLeaseInfo(HttpNfcLeaseInfo info)
	{
		System.out.println("########################  HttpNfcLeaseInfo  ###########################");
		System.out.println("Lease Timeout: " + info.getLeaseTimeout());
		System.out.println("Total Disk capacity: "	+ info.getTotalDiskCapacityInKB());
		HttpNfcLeaseDeviceUrl[] deviceUrlArr = info.getDeviceUrl();
		if (deviceUrlArr != null)
		{
			int deviceUrlCount = 1;
			for (HttpNfcLeaseDeviceUrl durl : deviceUrlArr)
			{
				System.out.println("HttpNfcLeaseDeviceUrl : "
						+ deviceUrlCount++);
				System.out.println("	Device URL Import Key: "
						+ durl.getImportKey());
				System.out.println("	Device URL Key: " + durl.getKey());
				System.out.println("	Device URL : " + durl.getUrl());
				System.out.println("	SSL Thumbprint : "	+ durl.getSslThumbprint());
			}
		}
		else
		{
			System.out.println("No Device URLS Found");
		}
	}

	private static long writeVMDKFile(String localFilePath, String diskUrl, String cookie,
			long bytesAlreadyWritten, long totalBytes) throws IOException
	{
		HttpsURLConnection conn = getHTTPConnection(diskUrl, cookie);
		InputStream in = conn.getInputStream();
		OutputStream out = new FileOutputStream(new File(localFilePath));
		byte[] buf = new byte[102400];
		int len = 0;
		long bytesWritten = 0;
		while ((len = in.read(buf)) > 0)
		{
			out.write(buf, 0, len);
			bytesWritten += len;
			int percent = (int)(((bytesAlreadyWritten + bytesWritten) * 100) / totalBytes);
			leaseProgUpdater.setPercent(percent);
			System.out.println("written: " + bytesWritten);
		}
		in.close();
		out.close();
		return bytesWritten;
	}

	private static HttpsURLConnection getHTTPConnection(String urlStr, String cookieStr) throws IOException
	{
		HostnameVerifier hv = new HostnameVerifier()
		{
			public boolean verify(String urlHostName, SSLSession session)
			{
				return true;
			}
		};
		HttpsURLConnection.setDefaultHostnameVerifier(hv);
		URL url = new URL(urlStr);
		HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();

		conn.setDoInput(true);
		conn.setDoOutput(true);
		conn.setAllowUserInteraction(true);
		conn.setRequestProperty("Cookie",	cookieStr);
		conn.connect();
		return conn;
	}

}

Second, ImportLocalOvfVApp.java. This sample shows how to upload a VM or vApp. The flow is:

  • Read in the *.ovf file and call OvfManager().createImportSpec() method
  • From a ResoucePool, call its importVApp() method() and get HttpNfcLease object
  • Wait until the lease is ready
  • Upload the vmdk files using the URL provided by the lease object
  • Release the lease by calling httpNfcLeaseComplete() method

Note: with VI Java API 5.0 GA, remove the line “ovfDescriptor = escapeSpecialChars(ovfDescriptor);” becuase escaping is added to underlying engine.

/*================================================================================
Copyright (c) 2008 VMware, Inc. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

 * Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

 * Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

 * Neither the name of VMware, Inc. nor the names of its contributors may be used
to endorse or promote products derived from this software without specific prior
written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
================================================================================*/
package com.vmware.vim25.mo.samples.ovf;

import java.io.*;
import java.net.*;
import javax.net.ssl.*;
import com.vmware.vim25.*;
import com.vmware.vim25.mo.ComputeResource;
import com.vmware.vim25.mo.Folder;
import com.vmware.vim25.mo.HostSystem;
import com.vmware.vim25.mo.HttpNfcLease;
import com.vmware.vim25.mo.ResourcePool;
import com.vmware.vim25.mo.ServiceInstance;

/**
 * Deploy VM or vApp from local disk to an ESX(i) server
 * http://vijava.sf.net
 * @author Steve Jin (sjin at vmware.com)
 */

public class ImportLocalOvfVApp
{
	private static final int CHUCK_LEN = 64 * 1024;

	public static LeaseProgressUpdater leaseUpdater;

	public static void main(String[] args) throws Exception
	{
		if (args.length < 6)
		{
			System.out.println(
			"java ImportLocalOvfVApp <targetURL> <username> <password> <hostip> <OVFFile LocalPath> <NewVMName>");
			System.out.println(
			"java ImportLocalOvfVApp https://10.20.140.47/sdk Administrator password 10.17.204.115 E:/Downloads/Nostalgia.ovf NewVM");
			return;
		}

		ServiceInstance si = new ServiceInstance(new URL(args[0]), args[1], args[2], true);

		String ovfLocal = args[4];
		String hostip = args[3];
		String newVmName = args[5];

		HostSystem host = (HostSystem) si.getSearchIndex().findByIp(null, hostip, false);

		System.out.println("Host Name : " + host.getName());
		System.out.println("Network : " + host.getNetworks()[0].getName());
		System.out.println("Datastore : " + host.getDatastores()[0].getName());

		Folder vmFolder = (Folder) host.getVms()[0].getParent();

		OvfCreateImportSpecParams importSpecParams = new OvfCreateImportSpecParams();
		importSpecParams.setHostSystem(host.getMOR());
		importSpecParams.setLocale("US");
		importSpecParams.setEntityName(newVmName);
		importSpecParams.setDeploymentOption("");
		OvfNetworkMapping networkMapping = new OvfNetworkMapping();
		networkMapping.setName("Network 1");
		networkMapping.setNetwork(host.getNetworks()[0].getMOR()); // network);
		importSpecParams.setNetworkMapping(new OvfNetworkMapping[] { networkMapping });
		importSpecParams.setPropertyMapping(null);

		String ovfDescriptor = readOvfContent(ovfLocal);
		if (ovfDescriptor == null)
		{
			si.getServerConnection().logout();
			return;
		}

		ovfDescriptor = escapeSpecialChars(ovfDescriptor);
		System.out.println("ovfDesc:" + ovfDescriptor);

		ResourcePool rp = ((ComputeResource)host.getParent()).getResourcePool();

		OvfCreateImportSpecResult ovfImportResult = si.getOvfManager().createImportSpec(
				ovfDescriptor, rp, host.getDatastores()[0], importSpecParams);

		if(ovfImportResult==null)
		{
			si.getServerConnection().logout();
			return;
		}

		long totalBytes = addTotalBytes(ovfImportResult);
		System.out.println("Total bytes: " + totalBytes);

		HttpNfcLease httpNfcLease = null;

		httpNfcLease = rp.importVApp(ovfImportResult.getImportSpec(), vmFolder, host);

		// Wait until the HttpNfcLeaseState is ready
		HttpNfcLeaseState hls;
		for(;;)
		{
			hls = httpNfcLease.getState();
			if(hls == HttpNfcLeaseState.ready || hls == HttpNfcLeaseState.error)
			{
				break;
			}
		}

		if (hls.equals(HttpNfcLeaseState.ready))
		{
			System.out.println("HttpNfcLeaseState: ready ");
			HttpNfcLeaseInfo httpNfcLeaseInfo = (HttpNfcLeaseInfo) httpNfcLease.getInfo();
			printHttpNfcLeaseInfo(httpNfcLeaseInfo);

			leaseUpdater = new LeaseProgressUpdater(httpNfcLease, 5000);
			leaseUpdater.start();

			HttpNfcLeaseDeviceUrl[] deviceUrls = httpNfcLeaseInfo.getDeviceUrl();

			long bytesAlreadyWritten = 0;
			for (HttpNfcLeaseDeviceUrl deviceUrl : deviceUrls)
			{
				String deviceKey = deviceUrl.getImportKey();
				for (OvfFileItem ovfFileItem : ovfImportResult.getFileItem())
				{
					if (deviceKey.equals(ovfFileItem.getDeviceId()))
					{
						System.out.println("Import key==OvfFileItem device id: " + deviceKey);
						String absoluteFile = new File(ovfLocal).getParent() + File.separator + ovfFileItem.getPath();
						String urlToPost = deviceUrl.getUrl().replace("*", hostip);
						uploadVmdkFile(ovfFileItem.isCreate(), absoluteFile, urlToPost, bytesAlreadyWritten, totalBytes);
						bytesAlreadyWritten += ovfFileItem.getSize();
						System.out.println("Completed uploading the VMDK file:" + absoluteFile);
					}
				}
			}

			leaseUpdater.interrupt();
			httpNfcLease.httpNfcLeaseProgress(100);
			httpNfcLease.httpNfcLeaseComplete();
		}
		si.getServerConnection().logout();
	}

	public static long addTotalBytes(OvfCreateImportSpecResult ovfImportResult)
	{
		OvfFileItem[] fileItemArr = ovfImportResult.getFileItem();

		long totalBytes = 0;
		if (fileItemArr != null)
		{
			for (OvfFileItem fi : fileItemArr)
			{
				printOvfFileItem(fi);
				totalBytes += fi.getSize();
			}
		}
		return totalBytes;
	}

	private static void uploadVmdkFile(boolean put, String diskFilePath, String urlStr,
			long bytesAlreadyWritten, long totalBytes) throws IOException
	{
		HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier()
		{
			public boolean verify(String urlHostName, SSLSession session)
			{
				return true;
			}
		});

		HttpsURLConnection conn = (HttpsURLConnection) new URL(urlStr).openConnection();
		conn.setDoOutput(true);
		conn.setUseCaches(false);
		conn.setChunkedStreamingMode(CHUCK_LEN);
		conn.setRequestMethod(put? "PUT" : "POST"); // Use a post method to write the file.
		conn.setRequestProperty("Connection", "Keep-Alive");
		conn.setRequestProperty("Content-Type",	"application/x-vnd.vmware-streamVmdk");
		conn.setRequestProperty("Content-Length", Long.toString(new File(diskFilePath).length()));

		BufferedOutputStream bos = new BufferedOutputStream(conn.getOutputStream());

		BufferedInputStream diskis = new BufferedInputStream(new FileInputStream(diskFilePath));
		int bytesAvailable = diskis.available();
		int bufferSize = Math.min(bytesAvailable, CHUCK_LEN);
		byte[] buffer = new byte[bufferSize];

		long totalBytesWritten = 0;
		while (true)
		{
			int bytesRead = diskis.read(buffer, 0, bufferSize);
			if (bytesRead == -1)
			{
				System.out.println("Total bytes written: " + totalBytesWritten);
				break;
			}

			totalBytesWritten += bytesRead;
			bos.write(buffer, 0, bufferSize);
			bos.flush();
			System.out.println("Total bytes written: " + totalBytesWritten);
			int progressPercent = (int) (((bytesAlreadyWritten + totalBytesWritten) * 100) / totalBytes);
			leaseUpdater.setPercent(progressPercent);
		}

		diskis.close();
		bos.flush();
		bos.close();
		conn.disconnect();
	}

	public static String readOvfContent(String ovfFilePath)	throws IOException
	{
		StringBuffer strContent = new StringBuffer();
		BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(ovfFilePath)));
		String lineStr;
		while ((lineStr = in.readLine()) != null)
		{
			strContent.append(lineStr);
		}
		in.close();
		return strContent.toString();
	}

	private static void printHttpNfcLeaseInfo(HttpNfcLeaseInfo info)
	{
		System.out.println("================ HttpNfcLeaseInfo ================");
		HttpNfcLeaseDeviceUrl[] deviceUrlArr = info.getDeviceUrl();
		for (HttpNfcLeaseDeviceUrl durl : deviceUrlArr)
		{
			System.out.println("Device URL Import Key: " + durl.getImportKey());
			System.out.println("Device URL Key: " + durl.getKey());
			System.out.println("Device URL : " + durl.getUrl());
			System.out.println("Updated device URL: " + durl.getUrl());
		}
		System.out.println("Lease Timeout: " + info.getLeaseTimeout());
		System.out.println("Total Disk capacity: " + info.getTotalDiskCapacityInKB());
		System.out.println("==================================================");
	}

	private static void printOvfFileItem(OvfFileItem fi)
	{
		System.out.println("================ OvfFileItem ================");
		System.out.println("chunkSize: " + fi.getChunkSize());
		System.out.println("create: " + fi.isCreate());
		System.out.println("deviceId: " + fi.getDeviceId());
		System.out.println("path: " + fi.getPath());
		System.out.println("size: " + fi.getSize());
		System.out.println("==============================================");
	}

	public static String escapeSpecialChars(String str)
	{
		str = str.replaceAll("<", "&lt;");
		return str.replaceAll(">", "&gt;"); // do not escape "&" -> "&amp;", "\"" -> "&quot;"
	}
}

While you are downloading or uploading the files, you would also like to update the progress with the httpNfcLease.httpNfcLeaseProgress() API. This is done periodically in a separate thread with both samples. Note that the size calculation is not accurate, so you may find mismatch there.

/*================================================================================
Copyright (c) 2008 VMware, Inc. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

 * Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

 * Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

 * Neither the name of VMware, Inc. nor the names of its contributors may be used
to endorse or promote products derived from this software without specific prior
written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
================================================================================*/
package com.vmware.vim25.mo.samples.ovf;

import com.vmware.vim25.mo.HttpNfcLease;

/**
 * http://vijava.sf.net
 * @author Steve Jin (sjin at vmware.com)
 */

public class LeaseProgressUpdater extends Thread
{
	private HttpNfcLease httpNfcLease = null;
	private int progressPercent = 0;
	private int updateInterval;

	public LeaseProgressUpdater(HttpNfcLease httpNfcLease, int updateInterval)
	{
		this.httpNfcLease = httpNfcLease;
		this.updateInterval = updateInterval;
	}

	public void run()
	{
		while (true)
		{
			try
			{
				httpNfcLease.httpNfcLeaseProgress(progressPercent);
				Thread.sleep(updateInterval);
			}
			catch(InterruptedException ie)
			{
				break;
			}
			catch(Exception e)
			{
				throw new RuntimeException(e);
			}
		}
	}

	public void setPercent(int percent)
	{
		this.progressPercent = percent;
	}
}

You can import an OVF package from a URL using vSphere Client. How to implement it using the API? Easy. Instead of reading from a local file, you read from the URL. I leave it to you to try out.

For more details, check out the code repository. I have tested both samples in a round trip: export a VM to a local disk, and then import it back. The imported VM works well.

Marcus Ludvigson from Lawson sent me an email with a fix for unfinished upload disk file issue that happens occasionally. You need to add the following two sections of code into uploadVmdkFile() method.

conn.setDoInput(true);
try
{
  DataInputStream dis = new DataInputStream(conn.getInputStream());
  dis.close();
} catch (Exception e) {}

Categories: vSphere API Tags: ,
  1. Alan Vella
    May 17th, 2012 at 08:41 | #1

    @Steve Jin

    Hi Steve,

    After downloading the VMDKs I need to tar them up in an OVA package. Knowing the size of the VMDKs to be downloaded before I actually download them would allow me to stream the VMDKs directly into the OVA package – as opposed to downloading the VMDKs first THEN creating the OVA package. This would save me storage space and time.

    I would also like to show the progress in process of the whole operation but I can’t do this properly without knowing the size of the VMDKs to be downloaded.

    By the way, thank you for your prompt replies and well done for your excellent blog!

    Alan.

  2. Eric
    June 6th, 2012 at 11:16 | #2

    Hello Steve,

    In your example, if the ESX server doesn’t contain any VM, the result of
    Folder vmFolder = (Folder) host.getVms()[0].getParent();

    is a Null pointer exception.

    Do you know what we can do to import a OVF on a empty ESX server ? This
    is not so easy to know what to put in this Folder variable.

    If you have any idea 😉

    Thanks for your nice article.

    Bye

  3. Rini
    June 10th, 2012 at 14:15 | #3

    I have the same issue. What did you mean by ” Invalid host system id”…
    I can print my host system’s summary info…

    Getting the same invalidtype exception… Please advice

  4. RB
    June 10th, 2012 at 16:16 | #4

    InvalidType exception went away when I replaced “US” with “en-US” in importSpecParams.setLocale(“en-US”);

    Now I am seeing the following exception: I am trying to create the VM on a cluster.

    om.vmware.vim25.InvalidHostState
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.Class.newInstance0(Class.java:355)
    at java.lang.Class.newInstance(Class.java:308)
    at com.vmware.vim25.ws.XmlGen.fromXml(XmlGen.java:201)
    at com.vmware.vim25.ws.XmlGen.parseSoapFault(XmlGen.java:80)
    at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:132)
    at com.vmware.vim25.ws.VimStub.createImportSpec(VimStub.java:1193)
    at com.vmware.vim25.mo.OvfManager.createImportSpec(OvfManager.java:69)

    How should i set the HostSystem?

    Right now I am doing thsi:
    importSpecParams.setHostSystem(cluster.getHosts()[0].getMOR());

    Also finding the resource pool like this:
    rp = (ResourcePool) new InventoryNavigator(
    cluster).searchManagedEntities(“ResourcePool”)[0];

    And using that pool to create the importspec:
    OvfCreateImportSpecResult ovfImportResult = si.getOvfManager().createImportSpec(
    ovfDescriptor, rp, dst, importSpecParams);

  5. Kathy
    July 8th, 2012 at 22:46 | #5

    Hi steve,

    I can download vmdk and create ovf description, but I can’t create manifest file. Do you know what’s problem with me? And how to create manifest file. Please~~~ Thanks.

  6. Deepika
    July 10th, 2012 at 01:47 | #6

    The code to import OVF works fine if my disk is a VM. What is the procedure to import a vApp? The present code says “Unsupported element VirtualSystemCollection”. How can I resolve this?
    The export class provides two methos “exportVM()” and “exportVApp()”. Isn’t there a similar thing in importing as well? like, importVApp and inportVM?

  7. Kathy
    July 11th, 2012 at 09:12 | #7

    I try to use httpNfcLeaseGetManifest to get manifest data, but it returns null. Do you know how to get manifest data? And I have a question about exporting ovf by vSphere Client, vSphere SDK, and ovftool. Which one is the fast method? If Steve know that, please kindly tell me. Thank you very much.

  8. mike
    August 28th, 2012 at 12:52 | #8

    Hi Steve,
    Is it possible to load vmdk file directly via datastore URL path (e.g. https://192.168.2.1/folder/mxue-vm-3?dcPath=MYCENTER&dsName=mystore) instead of deviceURL from HttpNfcLease? We have to set up security certificates for each ESX server host if we use deviceURL. We are hoping to do operations all through vSphere server connection (VI Instance) and that’s why we are trying loading vmdk via datastore url based on vSphere server IP. Our tests failed as the created VM gets powered on but cannot find OS. The vmdk does not seem to be really loaded though the vmdk gets loaded to datastore. Can you offer some insights or suggests?

    thanks

  9. Mahesh
    September 21st, 2012 at 08:26 | #9

    Hi Steve,

    I can import ovf file, But want to Import OVA file, I tried lot but giving following error.

    Exception in thread “main” java.rmi.RemoteException: VI SDK invoke exception:org.dom4j.DocumentException: null Nested exception: null
    at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:182)
    at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:124)
    at com.vmware.vim25.ws.VimStub.createImportSpec(VimStub.java:1251)
    at com.vmware.vim25.mo.OvfManager.createImportSpec(OvfManager.java:69)

    I tried it by increasing heap size while running but fails, any clue or suggestion.

    mahesh

  10. Tony Fountaine
    November 29th, 2012 at 05:31 | #10

    Hi Steve,
    We are using your code for importing an OVF into vSphere, however it is not uploading the included iso file correctly. It seems to upload fine however it appears to be a blank iso on the datastore. It works fine when importing via the VSphere Client. I have noticed that the vmdk files have create=false and the iso file has create=true. It is reporting the correct number of bytes uploaded.

  11. Tony Fountaine
    December 3rd, 2012 at 04:48 | #11

    @Tony Fountaine
    Hi All,
    I found the answer here
    Just needed to add one more line of code:
    conn.setRequestProperty(“Overwrite”, “t”);

  12. EE
    January 18th, 2013 at 04:33 | #12

    Can this be done exactly the same but only using OVA instead of OVF file?

  13. hagit
    March 8th, 2013 at 00:16 | #13

    in case you want to import ovf to an existing vapp

    need to call vapp.importVapp(ovfImportResult.getImportSpec(), null, null)

    otherwise it fail
    The SteveProxy.jar does not have a java translation to this case

    Thanks for the wonderful examples

  14. Ryan Abela
    May 21st, 2013 at 11:39 | #14

    Hi All,
    We implemented import / export as above, and it always worked correctly. Now we’re trying to upgrade to VSphere 5.1 and we started using a ‘StoragePod’ (a cluster of datastores) instead of a ‘Datastore’.

    An idea how to use

    si.getOvfManager().createImportSpec( … using a StoragePod?

    Thanks alot for this article!

  15. May 21st, 2013 at 12:40 | #15

    Glad it helped. I haven’t used the StroagePod yet by myself. Will probably look at it later. Should you find anything useful, please feel free to share here.
    Steve

  16. Muni
    July 27th, 2013 at 00:52 | #16

    Hi,

    How to import ovf on a cluster instead of host.

  17. August 16th, 2013 at 05:51 | #17

    Hi

    I’m trying to import a 1.29GB ova file. I get this exception:

    Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Arrays.java:2367)
    at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:130)
    at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:114)
    at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:415)
    at java.lang.StringBuffer.append(StringBuffer.java:237)
    at com.vmware.vim25.mo.samples.ImportLocalOvfVApp.readOvfContent(ImportLocalOvfVApp.java:190)
    at com.vmware.vim25.mo.samples.ImportLocalOvfVApp.main(ImportLocalOvfVApp.java:60)

    I’ve tried to increase the heap space to 2048mb but I get the same error.

    Can anyone help?

    Thanks

  18. August 23rd, 2013 at 18:36 | #18

    Hi Brian,

    You want to try chunk mode instead of normal mode.

    Steve

  19. yxa
    October 22nd, 2013 at 02:28 | #19

    Can you give me a c # import Vapp code? I like your JAVA code after the writing prompt error “request reference accident or unknown types.” . Email address is yangxuanang@sys-test.com.cn

  20. October 22nd, 2013 at 10:41 | #20

    Sorry that I don’t have C# vApp code. You can port the Java code to C# though. Good luck!

    Steve

  21. yxa
    October 22nd, 2013 at 20:55 | #21

    @Steve Jin
    hello! I have some questions to ask you, can you give me an E-mail?

  22. October 23rd, 2013 at 10:45 | #22

    My email is on the site. You can ask questions here or the vijava API forum (http://vijava.sf.net).

    Steve

  23. yxa
    October 23rd, 2013 at 20:12 | #23

    @Steve Jin
    Datacenter dc = vim.FindEntityViews(typeof(Datacenter), null, null, null)[1] as Datacenter;
    string dcName = dc.Name;
    Folder fd = vim.GetView(dc.VmFolder, null) as Folder;

    List computerList = vim.FindEntityViews(typeof(ComputeResource), null, null, null);
    ComputeResource comput = computerList[1] as ComputeResource;
    string name = comput.Name;

    ResourcePool rp = vim.GetView(((ComputeResource)computerList[1]).ResourcePool, null) as ResourcePool;
    string rpName = rp.Name;

    List hostlst = vim.GetViews(((ComputeResource)computerList[1]).Host, null);
    HostSystem hs = hostlst[1] as HostSystem;
    string hsName = hs.Name;

    Datastore store = vim.GetView(hs.Datastore[0], null) as Datastore;
    Network network = vim.GetView(hs.Network[0], null) as Network;
    VirtualMachine vm = vim.GetView(hs.Vm[0],null) as VirtualMachine;

    OvfCreateImportSpecParams importSpecParams = new OvfCreateImportSpecParams();
    importSpecParams.HostSystem = hs.MoRef;
    importSpecParams.Locale = “US”;
    importSpecParams.EntityName = “vapptst”;
    importSpecParams.DeploymentOption = “”;

    //OvfNetworkMapping networkMapping = new OvfNetworkMapping();
    //networkMapping.Name = network.Name;
    //networkMapping.Network = network.MoRef;
    //importSpecParams.NetworkMapping = new OvfNetworkMapping[] { networkMapping };
    //importSpecParams.PropertyMapping = new KeyValue[] { null };
    string ovfDescriptor = System.IO.File.ReadAllText(ovfFilePath);
    OvfManager ovf = new OvfManager(vim, rp.MoRef);
    OvfCreateImportSpecResult ovfImportResult = ovf.CreateImportSpec(
    ovfDescriptor, rp.MoRef, store.MoRef, importSpecParams);

    . This is the code I wrote in the use of the ovf.CreateImportSpec() methods when the error message as “request reference accident or unknown types. I want to know is that there is something wrong with the parameter Settings. thank you

  24. October 24th, 2013 at 12:11 | #24

    This can be tricky and it takes time to sort it out. You may want to compare your code with the sample and try different combinations.

    Steve

  25. yxa
    October 25th, 2013 at 03:40 | #25

    @Steve Jin
    Thank you very much! I have almost found the reason

  26. yxa
    October 25th, 2013 at 04:24 | #26

    @yxa
    When using CreateVMTask method, I can’t add to create a virtual machine network and storage size. Can you give me an example of JAVA? thank you

  27. October 25th, 2013 at 10:22 | #27

    There are many samples in vijava repository. Check them out from the project home http://vijava.sf.net.

    Good luck!

    Steve

  28. yxa
    January 7th, 2014 at 03:05 | #28

    Hello, Steve, sorry to trouble you again, I use a WebClient to upload files to the data store, but not more than 50 m size, can you give me some help? How to upload large files to the data storage, can be either c # or Java code, thank you!!

  29. January 8th, 2014 at 00:19 | #29

    What help do you want? The sample code listed should work the magic.

    Steve

  30. yxa
    January 8th, 2014 at 01:13 | #30

    How to upload files to the data store. Here is my c # code (but only upload a small file, not bigger file upload):
    ///
    /// 上载文件
    ///
    /// 服务器
    /// 用户名
    /// 密码
    /// 数据中心
    /// 数据存储
    /// 目录(dir或../dir)
    /// 本地文件
    ///
    public static bool UploadFile(string server, string userName, string password, string dataCenterName, string dataStoreName, string directoryName, string localFileName)
    {
    //VimClient vimClient = GetVimClient(server, userName, password);
    //String serviceUrl = vimClient.ServiceUrl;
    //serviceUrl = serviceUrl.Substring(0, serviceUrl.LastIndexOf(“sdk”) – 1);
    String httpUrl = string.Format(“https://{0}/folder/{1}/{2}?dcPath={3}&dsName={4}”, server, directoryName, Path.GetFileName(localFileName), dataCenterName, dataStoreName);
    httpUrl = httpUrl.Replace(“\\ “, “%20”);

    WebClient client = new WebClient();
    NetworkCredential nwCred = new NetworkCredential();
    nwCred.UserName = userName;
    nwCred.Password = password;
    client.Credentials = nwCred;
    bool bo=false;
    try{
    client.UploadData(urlString, “PUT”, File.ReadAllBytes(localFileName));
    client.Dispose();
    bo=true;
    }
    catch (Exception ex)
    {
    bo= false;
    System.Diagnostics.Debug.WriteLine(ex);
    }
    return bo;
    }

  31. January 9th, 2014 at 17:13 | #31

    There is a section in last chapter of my book discusses the uploading. You can check it out there.

    Steve

  32. Jamshoo Lakhani
    September 24th, 2014 at 05:43 | #32

    It gives me an issue
    Deploy OVF template Operation timed out.

  33. Praneeth
    November 19th, 2014 at 07:15 | #33

    Hi Steve,
    What if my ovf/ova image is already present on datastore ? How to deploy the VM ?
    I don’t want to give the HTTP data store path (URL) as it is taking around 20 minutes for deployment. It is trying to do a network transfer of the file.

  34. Tanmoy
    December 3rd, 2014 at 07:59 | #34

    Hi Steve,
    I am using your way to import ovf. It works like a champ. But even after successfull import I am getting an exception “Deployment failed due to duplicate name” (verified throuogh vsphere client, its true!). Is there any way to handle this from your code? So that I can retry import using a different name? Now I am not able to know this scenario until I check through vsphere client.

  35. December 3rd, 2014 at 11:20 | #35

    Glad to know. You can easily check if there is any existing vm with same name before importing ovf.

    Steve

  36. Ramakrishna Reddy
    December 8th, 2014 at 10:29 | #36

    Hi Steve,

    I would like to Tag the VM instances of Vsphere.
    Can you please assist me how we can able to achieve this.

    Thanks

  37. Adriano G
    January 8th, 2015 at 08:27 | #37

    Hi Steven,

    I have a question, using VSphere Client to deploy a OVA, we just need to inform the URL of file(http://….) and then the job will automatically read URL from there, internally. So the java client don’t need to consume memory.

    Looking in your code, it seems that we need to read whole file before and and submit in the method as String(ovfDescriptior).

    OvfCreateImportSpecResult ovfImportResult = si.getOvfManager().createImportSpec(
    ovfDescriptor, rp, host.getDatastores()[0], importSpecParams);

    Is there any way to use the same behavior from VSphere client? Just pass the URL to and then task will read inside vcenter and use the content.

    Our java client can easily gets a OutOfMemory exception. Increasing the heap space is not a good solution, I have file with 5GB. Reading in a chunk mode as you suggest is not clear for me, because you send to “createImportSpec” as string, I can not see how we can send partial content there.

    Any idea?

    Thanks,

  38. sp
    March 24th, 2015 at 17:46 | #38

    Hi Steve,

    Thanks for this great post.
    I am using the chunked streaming mode with code mostly similar to the uploadVmdkfile() that you posted in here, but I am facing an error saying – “Error writing request body to server”.
    Any idea of why this error could be occuring?

    Thanks.

  39. March 24th, 2015 at 19:04 | #39

    Hi SP, want to post stack trace and code? Thx

    Steve

  40. Steve
    March 26th, 2015 at 05:43 | #40

    Can you give a sample python code using pyvmomi for Exporting ovf?

  41. March 26th, 2015 at 11:36 | #41

    Hi Steve, I don’t have pyVmomi code for exporting off. You may want to check out the pyVmomi project home. Hopefully they have something for you.

    Good luck!

    Steve

  42. vihari
    June 28th, 2015 at 23:34 | #42

    Hi steve,

    we got below error while importing ovf package to my ESXI.

    ovfDesc:<?xml version=”1.0″ encoding=”UTF-8″?><!–Generated by VMware ESX Server, User: root, UTC time: 2014-11-26T08:15:30.590378Z–><Envelope vmw:buildId=”build-1065491″ xmlns=”http://schemas.dmtf.org/ovf/envelope/1″ ——-
    ———————–
    Total bytes: 0
    Exception in thread “main” java.rmi.RemoteException: VI SDK invoke exception:com.vmware.vim25.InvalidRequest
    at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:122)
    at com.vmware.vim25.ws.VimStub.importVApp(VimStub.java:1343)
    at com.vmware.vim25.mo.ResourcePool.importVApp(ResourcePool.java:102)
    at vm_sample.test.main(test.java:164)
    ——————————————–

    —————–
    code :-
    —————–

    String ovfLocal = “D:/os/xxxxx.ovf”;
    String hostip = “xxxxxxxxx”;
    String newVmName = “deploy”;

    HostSystem host = (HostSystem) si.getSearchIndex().findByIp(null, hostip, false);

    System.out.println(“Host Name : ” + host.getName());
    System.out.println(“Network : ” + host.getNetworks()[0].getName());
    System.out.println(“Datastore : ” + host.getDatastores()[0].getName());

    Folder vmFolder = (Folder) host.getVms()[0].getParent();

    System.out.println(“vmfolder : ” + vmFolder.getName());

    OvfCreateImportSpecParams importSpecParams = new OvfCreateImportSpecParams();
    importSpecParams.setHostSystem(host.getMOR());
    importSpecParams.setLocale(“US”);
    importSpecParams.setEntityName(newVmName);
    importSpecParams.setDeploymentOption(“”);

    //System.out.println(“known” + importSpecParams.deploymentOptio);

    OvfNetworkMapping networkMapping = new OvfNetworkMapping();
    networkMapping.setName(“Network 1”);
    networkMapping.setNetwork(host.getNetworks()[0].getMOR()); // network);
    importSpecParams.setNetworkMapping(new OvfNetworkMapping[] { networkMapping });
    importSpecParams.setPropertyMapping(null);

    String ovfDescriptor = readOvfContent(ovfLocal);
    if (ovfDescriptor == null)
    {
    si.getServerConnection().logout();
    return;
    }

    ovfDescriptor = escapeSpecialChars(ovfDescriptor);
    System.out.println(“ovfDesc:” + ovfDescriptor);

    ResourcePool rp = ((ComputeResource)host.getParent()).getResourcePool();

    OvfCreateImportSpecResult ovfImportResult = si.getOvfManager().createImportSpec(
    ovfDescriptor, rp, host.getDatastores()[0], importSpecParams);
    if(ovfImportResult==null)
    {
    si.getServerConnection().logout();
    return;
    }

    long totalBytes = addTotalBytes(ovfImportResult);
    System.out.println(“Total bytes: ” + totalBytes);

    HttpNfcLease httpNfcLease = null;
    httpNfcLease = rp.importVApp(ovfImportResult.getImportSpec(), vmFolder, host);
    ————————————> this is my 164 th line may be we got error here.

    can you please help us resolve above issue.

    Thanks,

  43. PraveenKumar
    August 26th, 2015 at 18:46 | #43

    Is there any direct API in vsphere SDK/java to extract ova file (to ovf and vmdk files) or to tar the files to ova file?.

    I want to extract OVA file without using Runtime.getRuntime() API.

    Thanks in advance.

  44. August 29th, 2015 at 22:19 | #44

    Good question. I think you can search for generic Java libraries for tar/untar.
    Steve

  45. KD
    October 12th, 2015 at 16:19 | #45

    I’m getting the following exception when I run ImportLocalOvfVApp:

    Exception in thread “main” java.rmi.RemoteException: VI SDK invoke exception : RetrieveServiceContent; nested exception is:
    java.io.IOException: Stream closed
    at com.vmware.vim25.ws.WSClient.createInvokeException(WSClient.java:213)
    at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:181)
    at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:118)
    at com.vmware.vim25.ws.VimStub.retrieveServiceContent(VimStub.java:4076)
    at com.vmware.vim25.mo.ServiceInstance.(ServiceInstance.java:120)
    at com.vmware.vim25.mo.ServiceInstance.(ServiceInstance.java:104)
    at com.vmware.vim25.mo.samples.ovf.ImportLocalOvfVApp.main(ImportLocalOvfVApp.java:32)
    Caused by: java.io.IOException: Stream closed
    at java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:159)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager$RewindableInputStream.read(XMLEntityManager.java:2892)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:673)
    at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:189)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:812)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
    at org.dom4j.io.SAXReader.read(SAXReader.java:465)
    at org.dom4j.io.SAXReader.read(SAXReader.java:343)
    at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:177)

    Could this be due to issues in the OVA file?

    Thanks!

  46. October 12th, 2015 at 22:52 | #46

    No, it’s not related to OVA yet. I think there is something wrong with connecting to your server.

    -Steve

  47. KD
    October 14th, 2015 at 09:59 | #47

    Hi Steve,

    I’m getting this response (VC server 6.0):

    Unexpected element tag “Envelope” seen

    while parsing serialized value of type string
    at line 1, column 364

    while parsing call information for method CreateImportSpec
    at line 1, column 285

    while parsing SOAP body
    at line 1, column 271

    while parsing SOAP envelope
    at line 1, column 38

    while parsing HTTP request for method createImportSpec
    on object of type vim.OvfManager
    at line 1, column 0

    Here’s the SOAP message sent:
    https://www.dropbox.com/s/ej0o44eb5qm5xib/soap4.xml?dl=0

  48. camellia
    December 30th, 2015 at 04:37 | #48

    Hi Steve,

    When we import an OVF file which larger then 8GB, we get below exception , do you know what is the issue ?

    05:12:44,483 INFO [stdout] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:12:44 AM [Plug-in standard output]: Total bytes written: 11047693312 Progress: 100
    05:32:49,736 INFO [stdout] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard output]: Total bytes written (last): 11047693312
    05:32:49,859 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: com.vmware.vim25.ManagedObjectNotFound
    05:32:49,859 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    05:32:49,860 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    05:32:49,860 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    05:32:49,860 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    05:32:49,861 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at java.lang.Class.newInstance0(Class.java:357)
    05:32:49,861 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at java.lang.Class.newInstance(Class.java:310)
    05:32:49,861 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at com.vmware.vim25.ws.XmlGen.fromXml(XmlGen.java:205)
    05:32:49,861 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at com.vmware.vim25.ws.XmlGen.parseSoapFault(XmlGen.java:82)
    05:32:49,862 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:134)
    05:32:49,862 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at com.vmware.vim25.ws.VimStub.httpNfcLeaseProgress(VimStub.java:951)
    05:32:49,862 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at com.vmware.vim25.mo.HttpNfcLease.httpNfcLeaseProgress(HttpNfcLease.java:92)
    05:32:49,862 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at vcenter.ImportOvf.importOvf(ImportOvf.java:124)
    05:32:49,863 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at vcenter.VCenter.task_VCenter_importOvf(VCenter.java:637)
    05:32:49,863 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    05:32:49,863 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    05:32:49,863 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    05:32:49,864 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at java.lang.reflect.Method.invoke(Method.java:597)
    05:32:49,864 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at com.hp.ov.activator.resmgr.kernel.pooling.impl.PoolManager.invokeTranslating(PoolManager.java:917)
    05:32:49,864 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at com.hp.ov.activator.resmgr.kernel.pooling.impl.PoolManager.invokeHandlingRemoteObject(PoolManager.java:969)
    05:32:49,864 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at com.hp.ov.activator.resmgr.kernel.ResMgr.invoke(ResMgr.java:1032)
    05:32:49,865 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at com.hp.ov.activator.resmgr.kernel.ResMgr.invokeAtomicTask(ResMgr.java:2395)
    05:32:49,865 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at com.hp.ov.activator.resmgr.kernel.ResMgr.runServiceRemoteObject(ResMgr.java:524)
    05:32:49,865 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at com.hp.ov.activator.resmgr.kernel.ResMgr.runService(ResMgr.java:323)
    05:32:49,865 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at com.hp.ov.activator.resmgr.rmi.HPIAResourceManagerImpl.executeAtomicTask(HPIAResourceManagerImpl.java:179)
    05:32:49,866 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    05:32:49,866 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    05:32:49,866 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    05:32:49,866 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at java.lang.reflect.Method.invoke(Method.java:597)
    05:32:49,867 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:303)
    05:32:49,867 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at sun.rmi.transport.Transport$1.run(Transport.java:159)
    05:32:49,867 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at java.security.AccessController.doPrivileged(Native Method)
    05:32:49,868 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
    05:32:49,868 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
    05:32:49,868 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
    05:32:49,868 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
    05:32:49,868 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    05:32:49,869 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    05:32:49,869 ERROR [stderr] (RMI TCP Connection(2)-16.147.136.242) Dec 9, 2015 5:32:49 AM [Plug-in standard error]: at java.lang.Thread.run(Thread.java:662)

    Best Regards,
    Chen

  49. December 30th, 2015 at 20:13 | #49

    Hi camellia,

    It seems you have an exception there: com.vmware.vim25.ManagedObjectNotFound. Don’t know which managed object is not found there.

    -Steve

  50. camellia
    January 5th, 2016 at 08:23 | #50

    Hi Steve,

    I tried to upload a 16G byte file, but using below 100 progress it will only upload 10G byte file, right? if I need to change the progress value or the CHUCK_LEN value? thanks.

    CHUCK_LEN = 10 * 1024 * 1024;
    httpNfcLease.httpNfcLeaseProgress(100);

    Best Regards,
    Chen

Comment pages
  1. No trackbacks yet.