vCO Workflow Script to Delete a Load Balancer off a vShield Edge Device

The following script enables a Load Balancer to be deleted off a vShield Edge Device

 

 

System.log("===== vShield Edge Gateway: " + objVclGateway.name);
System.log("===== Trying to Lock " + objVclGateway.name + " for vCO Admin");

LockingSystem.lockAndWait( objVclGateway.name, "vcdadmin" );

objVclGateway.updateInternalState();

System.log("===== Locked " + objVclGateway.name + " for vCO Admin");

var objVclGatewayConfiguration;
	objVclGatewayConfiguration = objVclGateway.configuration;

var objVclGatewayFeatures;
	objVclGatewayFeatures = objVclGatewayConfiguration.edgeGatewayServiceConfiguration;

var strLoadBalancerHostName;

if (objVclGatewayFeatures == null)
{
	System.error("===== No Services Found on the vShield Edge Gateway: " + objVclGateway.name);
}
else
{
	var blnFoundLoadBalancerVirtualServer;
		blnFoundLoadBalancerVirtualServer = false;

	var blnFoundLoadBalancerPool;
		blnFoundLoadBalancerPool = false;

	var objVclAbstractObjectSet;
		objVclAbstractObjectSet = objVclGatewayFeatures.networkService;

	var arrNetworkLoadBalancerServices;
		arrNetworkLoadBalancerServices = objVclAbstractObjectSet.find(new VclLoadBalancerService());

	System.log("===== Number of Load Balancer Services: " + arrNetworkLoadBalancerServices.length);

	if (arrNetworkLoadBalancerServices.length == 0)
	{
		System.error("===== Load Balancer Service Not Found on the vShield Edge Gateway: " + objVclGateway.name);
	}
	else
	{
		var objVclLoadBalancerService;
			objVclLoadBalancerService = arrNetworkLoadBalancerServices[0];

		System.log("===== Load Balancer Service Enabled ?: " + objVclLoadBalancerService.isEnabled);

		var objVclObjectListVirtualServer;
			objVclObjectListVirtualServer = objVclLoadBalancerService.virtualServer;

		var arrVclLoadBalancerVirtualServer;
			arrVclLoadBalancerVirtualServer = objVclObjectListVirtualServer.enumerate();

		System.log("===== Before deletion the number of Load Balancer Virtual Servers are: " + objVclObjectListVirtualServer.size());		

		for each (var objVclLoadBalancerVirtualServer in arrVclLoadBalancerVirtualServer)
		{
			System.log("BEFORE DECOM - objVclLoadBalancerVirtualServer.name = " + objVclLoadBalancerVirtualServer.name);

			if (objVclLoadBalancerVirtualServer.name == vAppName + "-VirtualServer")
			{
				System.log("===== A Match was Found for " + objVclLoadBalancerVirtualServer.name + ", this Virtual Server will be deleted.");
				System.log("===== A Match was Found for " + objVclLoadBalancerVirtualServer.description + ", this Virtual Server will be deleted.");

				strLoadBalancerHostName = objVclLoadBalancerVirtualServer.description;

				var intVirtualServerIndex;
					intVirtualServerIndex = objVclObjectListVirtualServer.indexOf(objVclLoadBalancerVirtualServer);

				objVclLoadBalancerService.virtualServer.remove(intVirtualServerIndex);

				blnFoundLoadBalancerVirtualServer = true;

				break;
			}
		}	

		System.log("===== After deletion the number of Load Balancer Virtual Servers are: " + objVclLoadBalancerService.virtualServer.size());		

		var objVclObjectListVirtualServer;
			objVclObjectListVirtualServer = objVclLoadBalancerService.virtualServer;

		var arrVclLoadBalancerVirtualServer;
			arrVclLoadBalancerVirtualServer = objVclObjectListVirtualServer.enumerate();

		for each (var objVclLoadBalancerVirtualServer in arrVclLoadBalancerVirtualServer)
		{
			System.log("AFTER DECOM - objVclLoadBalancerVirtualServer.name = " + objVclLoadBalancerVirtualServer.name);
		}	

		var objVclObjectListPool;
			objVclObjectListPool = objVclLoadBalancerService.pool;

		var arrVclLoadBalancerPool;
			arrVclLoadBalancerPool = objVclObjectListPool.enumerate();

		System.log("===== Before deletion the number of Load Balancer Pools are: " + objVclObjectListPool.size());

		for each (var objVclLoadBalancerPool in arrVclLoadBalancerPool)
		{
			System.log("BEFORE DECOM - objVclLoadBalancerPool.name = " + objVclLoadBalancerPool.name);

			if (objVclLoadBalancerPool.name == vAppName + "-Pool")
			{
				System.log("===== A Match was Found for " + objVclLoadBalancerPool.name + ", this Pool will be deleted.");
				System.log("===== A Match was Found for " + objVclLoadBalancerPool.description + ", this Pool will be deleted.");

				var intPoolIndex;
					intPoolIndex = objVclObjectListPool.indexOf(objVclLoadBalancerPool);

				objVclLoadBalancerService.pool.remove(intPoolIndex);

				blnFoundLoadBalancerPool = true;

				break;
			}
		}

		System.log("===== After deletion the number of Load Balancer Pools are: " + objVclLoadBalancerService.pool.size());

		var objVclObjectListPool;
			objVclObjectListPool = objVclLoadBalancerService.pool;

		var arrVclLoadBalancerPool;
			arrVclLoadBalancerPool = objVclObjectListPool.enumerate();

		for each (var objVclLoadBalancerPool in arrVclLoadBalancerPool)
		{
			System.log("AFTER DECOM - objVclLoadBalancerPool.name = " + objVclLoadBalancerPool.name);
		}
	}
}

if ( ( blnFoundLoadBalancerVirtualServer == true ) || ( blnFoundLoadBalancerPool == true ) )
{
	var objVclTask;
		objVclTask = objVclGateway.update();

	objCustomActions.waitVclTask(objVclTask);

	objVclGateway.updateInternalState();

	System.log("==================================================");
	System.log("===== Load Balancer Service Deleted.");
	System.log("==================================================");	
}

LockingSystem.unlock( objVclGateway.name, "vcdadmin" );

System.log("===== Un-Locked " + objVclGateway.name + " for vCD Admin");

System.log("===== Host Name to Remove From DNS: " + strLoadBalancerHostName);

Leave a Reply