User Tools

Site Tools


vrealize:code:getfreeips

Report Free IP's left

vRA has the option to report on IP addresses being exchausted in a network profile. However I had trouble with these when you have allocated multiple ranges within the same subnet and also that the builtin report does not run often enough.

This workflow can be run as Eventbroker, (or in my case, run as part of the “PRECHECK” before deployment). In my case I use these to report (send an email) when there is less than 5 IP's free. (And if there is no free IP, it will fail the “PRECHECK and stop the build process.

Input parameter:

[string]NetworkProfileName = Name of the Network Profile to check

Output parameters:

[boolean]Result = True if workflow was sucessfull, false if it failed
[string]ErrText = Errortext if it failed (null if it was successful)
[number]FreeCount = Number of free IP's left in this network profile

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

var FreeCount = 0;
ErrText = null;
 
function GetFreeIPCount()
{
	var Sucess = true;
	try
	{
 
		var entitySetName = "StaticIPv4NetworkProfiles";
		var host = Server.findAllForType("vCAC:vCACHost")[0];
		var model = "ManagementModelEntities.svc";  
		var property = new Properties();  
		property.put("StaticIPv4NetworkProfileName",NetworkProfileName);
 
		var computeResources = vCACEntityManager.readModelEntitiesByCustomFilter(host.id, model, entitySetName, property, null);  
 
 
		var Props = computeResources[0].getProperties();
		var Link = computeResources[0].getLink(host,"StaticIPv4RangeSummaries");
 
                // Loop through ALL IP allocations 
		for each (L in Link)
		{
				var LinkProp = L.getProperties();
				FreeCount +=LinkProp.UnallocatedAddressCount;
		}
		System.log("Free IP's from this NetworkReservation is: "+FreeCount);
	}
	catch (e)
	{
		Sucess = false;
		System.warn("Failed to Lookup networkProfile: "+NetworkProfileName+" in IpCheck. Error:"+e);
		ErrText = e;
	}
 
	System.log("In FreeIPCheck Result: "+Sucess);
	return Sucess;
}
 
Result = GetFreeIPCount();
vrealize/code/getfreeips.txt · Last modified: 2018/11/29 12:21 by admin