chelnak
3/23/2016 - 11:15 AM

Get snapshot information for a vCAC virtual machine http://www.helloitscraig.co.uk/2016/03/retrieve-snapshot-information-vcacvirtualmachine

/*
Name: getvCACVirtualMachineSnapshots
Input: vCACHost - vCAC:VCACHost
Input: vCACVirtualMachine - vCAC:VirtualMachine
Output: Array/Properties
Description: Get snapshot information for a vCAC virtual machine
*/

//Get snapshot entities from the virtual machine
var properties = new Properties();
properties.put("VirtualMachineID", vCACVirtualMachine.virtualMachineID);

var vmEntity = vCACEntityManager.readModelEntity(vCACHost.id, "ManagementModelEntities.svc", "VirtualMachines", properties, null);
var vmSnapshotEntities = vmEntity.getLink(vCACHost,"VMSnapshots");

//Push snapshot properties to an array
var virtualMachineSnapshots = [];

for(var i = 0; i < vmSnapshotEntities.length; i++){

	var snapshotProperties = vmSnapshotEntities[i].getProperties();
	virtualMachineSnapshots.push(snapshotProperties);

	//Log snapshot properties to the console	
	for (var j = 0; j < snapshotProperties.keys.length; j++) {
	
		System.log(snapshotProperties.keys[j] + " : " + snapshotProperties.get(snapshotProperties.keys[j]));
		
	}

}

return virtualMachineSnapshots;