Connecting to a hypervisor using UVAPI is extremely easy.

  1. Create a ConnectorBean.
  2. Create a ConnectionInformationBean.
  3. Assign the ConnectionInformationBean to the ConnectorBean.
  4. Invoke the ConnectorBean's open method.

Examples

The following examples show how to connect to a VMware vSphere4 vCenter4 server, a Microsoft Hyper-V server, and a Citrix XenServer 5.5 server.

VMware vSphere4 vCenter4

import com.hyper9.uvapi.types.ConnectorBean;
import com.hyper9.uvapi.connectors.VMwareConnector;
import com.hyper9.uvapi.types.ConnectionInformationBean;
import com.hyper9.uvapi.impls.ConnectionInformationBeanImpl;

// Create a VMware ConnectorBean.
ConnectorBean vcb = new VMwareConnector();

// Create a ConnectionInformationBean that will specify the
// connection information used to connect to the hypervisor.
ConnectionInformationBean vcib = new ConnectionInformationBeanImpl();

// Set the address of the hypervisor we're connecting to.
vcib.setAddress("vmware.hyper9.com");

// Set the ports to connect to.
vcib.setPort(443);

// Instruct the connector to use SSL when connecting.
vcib.setUseSsl(true);]

// Instruct the connector to ignore SSL errors when connecting.
vcib.setIgnoreCert(true);

// Set the user name to use when connecting.
vcib.setUserName("userName");

// Set the password to use when connecting.
vcib.setPassword("password");

// Assign the connection information beans to its connector.
vcb.setConnectionInformation(vcib);

// Open the connections to the hypervisor.
vcb.open();

// And now we have an open connection to the hypervisor.

// Last but not least, close the connection to the hypervisor.
vcb.close();

Micrsoft Hyper-V

import com.hyper9.uvapi.types.ConnectorBean;
import com.hyper9.uvapi.connectors.HyperVConnector;;
import com.hyper9.uvapi.types.ConnectionInformationBean;
import com.hyper9.uvapi.impls.ConnectionInformationBeanImpl;

// Create a Hyper-V ConnectorBean.
ConnectorBean hcb = new HyperVConnector();

// Create a ConnectionInformationBean that will specify the
// connection information used to connect to the hypervisor.
ConnectionInformationBean hcib = new ConnectionInformationBeanImpl();

// Set the address of the hypervisor we're connecting to.
hcib.setAddress("hyperv.hyper9.com");

// Set the user name to use when connecting. Notice that we can
// use a standard domain notation to specify the domain of the
// user we're connecting as. We could also use the 
// USERNAME@DOMAIN notation, or simply USERNAME if the machine
// is not a member of a domain or is a domain controller.
hcib.setUserName("mydomain\\userName");

// Set the password to use when connecting.
hcib.setPassword("password");

// Assign the connection information beans to its connector.
hcb.setConnectionInformation(hcib);

// Open the connections to the hypervisor.
hcb.open();

// And now we have an open connection to the hypervisor.

// Last but not least, close the connection to the hypervisor.
hcb.close();

Citrix XenServer 5.5

import com.hyper9.uvapi.types.ConnectorBean;
import com.hyper9.uvapi.connectors.XenConnector;;
import com.hyper9.uvapi.types.ConnectionInformationBean;
import com.hyper9.uvapi.impls.ConnectionInformationBeanImpl;

// Create a Xen ConnectorBean.
ConnectorBean xcb = new XenConnector();

// Create a ConnectionInformationBean that will specify the
// connection information used to connect to the hypervisor.
ConnectionInformationBean xcib = new ConnectionInformationBeanImpl();

// Set the address of the hypervisor we're connecting to.
xcib.setAddress("xen.hyper9.com");

// Set the ports to connect to.
xcib.setPort(443);

// Instruct the connector to use SSL when connecting.
xcib.setUseSsl(true);]

// Instruct the connector to ignore SSL errors when connecting.
xcib.setIgnoreCert(true);

// Set the user name to use when connecting.
xcib.setUserName("userName");

// Set the password to use when connecting.
xcib.setPassword("password");

// Assign the connection information beans to its connector.
xcb.setConnectionInformation(xcib);

// Open the connections to the hypervisor.
xcb.open();

// And now we have an open connection to the hypervisor.

// Last but not least, close the connection to the hypervisor.
xcb.close();

Commonalities

Did you notice the commonalities between the examples? I hope so, as one of the great things about UVAPI is that you can treat all hypervisors as if they are cut from the same cloth. This type of standardization continues when you begin to query the hypervisors for information.