User Tools

Site Tools


vrealize:code:unallocateanip

Release an IP address in vRA

Input parameter:

[string]IPv4Address = IP address to release(unallocate)

Output parameters:

(NONE)

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

 
function FindAndDestroyIP(IP)
{
	var entitySetName = "StaticIPv4Addresses";
	var host = Server.findAllForType("vCAC:vCACHost")[0];
	var model = "ManagementModelEntities.svc";  
	var property = new Properties();  
	property.put("IPv4Address",IPv4Address);
	var computeResources = vCACEntityManager.readModelEntitiesByCustomFilter(host.id, model, entitySetName, property, null);  
 
	var entityKeyId = "";
	if ( computeResources.length == 0)
	{	
		ErrTextStep1 = "No machine found with IP: "+IP+" in vRA";
		return false;
	}
	else if ( computeResources.length != 1)
	{	
		ErrTextStep1 = "OUCH, Multiple machines found with IP: "+IP+" in vRA";
		return false;
	}
 
 
	System.log("HostID "+computeResources[0].hostId);
	System.log("modelName = "+computeResources[0].modelName);
	System.log("entitySetName = "+computeResources[0].entitySetName);
	System.log("entityIdString = "+computeResources[0].keyString);
 
	// entity key is needed for the delete action
	entityKeyId = computeResources[0].keyString;
	var Props = computeResources[0].getProperties();
	var Links = computeResources[0].getLinks(host);	 // Links = Array of Properties
 
	System.log("Removing: "+entityKeyId);
 
 
        try 
        {
	      vCACEntityManager.deleteModelEntityBySerializedKey(host.id , model , entitySetName , entityKeyId, null);
        } 
        catch(e) 
        {
	      System.warn(e);
              return false;
        }	
        return true;
}
vrealize/code/unallocateanip.txt · Last modified: 2018/11/29 01:36 by admin