User Tools

Site Tools


vrealize:code:findlostmachines

Find orphaned machines in vRA

vRA sometimes has machines “stuck” in deployment. This might be because you had to kill a workflow with infinite loops, or the vRO Appliance crashed and never reported back to vRA. Usually these machines does not show in the vRA gui (under machines). But they will still hold IP's as allocated. This workflow you can use to locate witch machines is “stuck” (orphaned).

NOTE: If a machine is deploying at the time you run this workflow, it will reported. So make sure no deployment is running when you execute this workflow.

Input parameter:

(NONE)

Output parameters:

[Array of Properties]MachinneList_VRA = Each entry has one machine with attributes

As always, notice that only one vRA instance is supported (Server.findAllForType(“vCAC:vCACHost”)[0];) (So no multi tenant!)

MachinneList_VRA = new Properties();
 
function MachineObj()
{
	return this;
}
 
 
	var entitySetName = "VirtualMachines";
	var host = Server.findAllForType("vCAC:vCACHost")[0];
	var model = "ManagementModelEntities.svc";  
	var property = new Properties();  
	property.put("IsManaged","true");
	property.put("IsDeleted","false");
	property.put("InitiatorType","Clone");
 
	var computeResources = vCACEntityManager.readModelEntitiesByCustomFilter(host.id, model, entitySetName, property, null);  
 
	var C = 0;
	for each (var Element in computeResources)
	{
		C++;
 
		var Props = Element.getProperties();
		var obj = new MachineObj();
		obj.ComputerName = Props.get("VirtualMachineName");
		obj.AdminUUID = Props.get("VMUniqueID");
		obj.ExternalRef = Props.get("ExternalReferenceId");
		obj.VMID = Props.get("VirtualMachineID");
		obj.HostReservationID =Props.get("HostReservationID")
 
 
		var IPLinks = Element.getLink(host,"StaticIPv4Addresses");
 
		obj.IPList = new Array();
		for each (IP in IPLinks)
		{
			Prop2 = IP.getProperties();
 
			var Str = Prop2.get("IPv4Address");
			obj.IPList.push(Str);
			System.log(obj.ComputerName+" IP: "+Prop2.get("IPv4Address"));
		}
 
		MachinneList_VRA.put(obj.ComputerName,obj);
	}
System.log("Found a total of "+C+" Computers");
vrealize/code/findlostmachines.txt · Last modified: 2018/11/28 23:43 by admin