An extremely nifty feature of UVAPI is the ability to aggregate data across resource and hypervisor types. What that means is you can easily figure out the available CPU of VMs from one hypervisor and the hosts from another.


The following example demonstrates how to combine hosts and VMs into a single list and then print out their aggregate CPU statistics. This example uses the objects returned from the examples on section on querying.

import com.hyper9.uvapi.types.virt.resources.ComputeResourceListBean;
import com.hyper9.uvapi.impls.virt.resources.ComputeResourceListBeanImpl;


// Create an aggregate list of ComputeResources.
ComputeResourceListBean aglist = new ComputeResourceListBeanImpl;

// Add all of the hosts retrieved from the Xen server to
// the aggregate list.

// Add all of the VMs retrieved from the Hyper-V server
// to the aggregate list.

// It is now time to aggregate the CPU information. While it is 
// possible to simply invoke the list's aggregate function, we
// can be more efficient by only aggregating the properties we
// care about.
aglist.aggregate(Arrays.asList("cpu", "cpu.max"));

// Print out the aggregate CPU information.
System.out.println("%s of %s", aglist.getCpu(), aglist.getCpuMax());


Lists Are Resources Too

One interesting thing to note is that UVAPI lists are resources as well, or rather they implement the necessary interfaces to be considered resources. So you can actually add a ComputeResourceListBean to another ComputeResourceListBean and so on. In this way you can do deep aggregation.