Chapter 29. Using the Software Development Kit

This chapter outlines several examples of how to use the Java Software Development Kit in a Java IDE. To use the Java Software Development Kit in a project, the rhevm-sdk-java and rhevm-sdk-java-javadoc .jar files must be added to that project as external libraries. The following .jar files are also required to ensure all classes function correctly:
  • apache-commons-logging
  • commons-beanutils
  • commons-codec
  • httpclient
  • httpcore

29.1. Connecting to the Red Hat Enterprise Virtualization Manager

The Api class acts as the gateway through which you connect to and manipulate objects in the Red Hat Enterprise Virtualization Manager. You must declare an instance of this class each time you interact with the Manager in a project.
To declare an instance of the Api class, first import the Api class into your project:
import org.ovirt.engine.sdk.Api;
Next, declare an instance of the class using the following signature:
Api api = new Api("[your manager's address]", "[user name]@[domain]", "[password]", "[path to certificate]");
In this signature, the address to manager is the address and port name by which to connect to the Red Hat Enterprise Virtualization Manager, the user name, domain and password are the credentials with which to log in, and the path to certificate is the local path on your system to the certificate of the Manager for SSL communication. For more information on using certificates, see Section 29.13, “Working with SSL (Secure Socket Layer)”.
The following example outlines this process in more detail:
import org.ovirt.engine.sdk.Api;
import java.io.IOException;

public class Main
{
	private static final String URL = "https://localhost:443/api";
	
	@SuppressWarnings("unused");
	public static void main(String[] args) throws ClientProtocolException,
		ServerException, UnsecuredConnectionAttemptError, IOException
	{
		// #1 Authenticate using the user name and password
		Api api = new Api(URL, "admin@interal", "123456", "/home/user/.ovirtsdk/");
	
		...
	}
}