vCO Workflow Script to Add REST Operations to a REST Host for F5 BIG-IP LTM – Part 2

The following script is part 2 and enables the addition of REST Operations to a REST Host for F5 BIG-IP LTM

 

 

 

var arrKeys;
	arrKeys = objProperties.keys;

System.log("arrKeys.length = " + arrKeys.length);

var arrRESTOperations;
	arrRESTOperations = objRESTHost.getOperations();

System.log("arrRESTOperations.length = " + arrRESTOperations.length);

for ( var i = 0; i < arrRESTOperations.length; i++ )
{
	var strRESTOperation;
		strRESTOperation = arrRESTOperations[i];

	for ( var j = 0; j < arrKeys.length; j++ )
	{
		var strKey;
			strKey = arrKeys[j];

		var arrKey;
			arrKey = strKey.split('_');

		var strMethod;
			strMethod = arrKey[0];

		var strName;
			strName = arrKey[1];

		var objRESTOperation;
			objRESTOperation = objRESTHost.getOperation(strRESTOperation);

		if ( strName == objRESTOperation.name )
		{
			objProperties.remove(strKey);

			System.log("Removing From List to Add: " + strKey);
		}
	}
}

var arrKeys;
	arrKeys = objProperties.keys;

System.log("arrKeys.length = " + arrKeys.length);

for ( var i = 0; i < arrKeys.length; i++ )
{
	var strKey;
		strKey = arrKeys[i];

	var arrKey;
		arrKey = strKey.split('_');

	var strMethod;
		strMethod = arrKey[0];

	var strName;
		strName = arrKey[1];

	var strTemplateURL;
		strTemplateURL = objProperties.get(strKey);

	var objRESTOperation;
		objRESTOperation = new RESTOperation(strName);
		objRESTOperation.method = strMethod;
		objRESTOperation.urlTemplate = strTemplateURL;
		objRESTOperation.defaultContentType = "application/json";

		objRESTOperation = objRESTHost.addOperation(objRESTOperation);

	System.log("Adding to REST Host: " + strName);

	RESTHostManager.updateHost(objRESTHost);
}

Leave a Reply