03-09-2016 08:54 AM - edited 03-01-2019 06:41 AM
Task Name | UCSD has VLAN pool policies. This workflow will get the number of free VLANS and the VLAN list that is free. |
Description | |
Prerequisites | Minimum UCSD version: 5.4.0.2 |
Category | Custom task |
Components | |
User Inputs | |
User Output |
Instructions for Regular Workflow Use:
Instructions for Regular Workflow Use:
A thank you goes out to: Tejeswar Sahu
The workflow:
The workflow input and LOV provider from custom task:
The UCSD VLAN pool Policies in question:
The workflow run:
The custom task code:
importPackage(java.lang);
importPackage(java.util);
importPackage(com.cloupia.service.cIM.inframgr);//VDCUtil,InfraPersistenceUtil
importPackage(com.cloupia.service.cIM.inframgr.profiles);//VLANPoolPolicy
importPackage(com.cloupia.model.cIM);//GlobalConstants
importPackage(com.cloupia.service.cIM.inframgr.reservation);//CapacityReservationPersistentUtil
var policyName = input.vlanPoolPolicyName;
logger.addInfo("Selected vlanPoolPolicyName is:"+policyName);
var vpp = VDCUtil.getVLANPoolPolicyByName(policyName);
if (vpp == null)
{
loggerogger.addError("No such VLAN pool policy exists.");
throw new Exception("No such VLAN pool policy exists.");
}
var vlanList = getVLANListFromVLANPoolPolicy(vpp.getVlanRange());
logger.addInfo("List = "+vlanList);
logger.addInfo("NO of vlans in the vlan pool policy::"+vlanList.size());
var dcName = vpp.getDcName();
var resourceType = GlobalConstants.RESOURCE_TYPE.VLAN_DN+GlobalConstants.RESOURCE_TYPE.DELIM+dcName;
var reservedVlanIds = CapacityReservationPersistentUtil.getCapacityReservationByType(resourceType);
var vlanId = -1;
var reservedSet = new HashSet();
for(var count = 0;count<reservedVlanIds.size();count++){
var cr = reservedVlanIds.get(count);
reservedSet.add(cr.getResourceId());
}
var freeVlanList = getVlanIdfromVLANList(vlanList, dcName,reservedSet);
logger.addInfo("Free List = "+freeVlanList);
var noOfFreeVlans = freeVlanList.size();
logger.addInfo("noOfFreeVlans = "+noOfFreeVlans);
output.noOfFreeVlans = noOfFreeVlans;
output.FreeVLANList = freeVlanList;
///////////////////////////////////////
function getVlanIdfromVLANList(vlanList, dcName, reservedSet) //throws Exception
{
var freeVlanList = new ArrayList();
var vlanIdMap = InfraPersistenceUtil.getVLANPoolTableIdsByDCName(dcName);
for(var count = 0;count<vlanList.size();count++)
{
var vlanId = vlanList[count];
if(reservedSet.contains(vlanId+""))
{
logger.addInfo("RESERVED:"+vlanId)
continue;
}
if (vlanIdMap != null)
{
if (!vlanIdMap.containsKey(vlanId))
{
freeVlanList.add(vlanId);
//logger.addInfo("1:FREE IP IS:"+vlanId);
} else
{
var existVpt = vlanIdMap.get(vlanId);
if (existVpt.isNetapp() || existVpt.isNetwork() || existVpt.isUcs() || existVpt.isVmware())
{
logger.addInfo("Skipping vlan Id since it's used. " + vlanId);
continue;
} else
{
logger.addInfo("Generated vlaId is not reserved and not used");
logger.addInfo("2: Allocating vlan id " + vlanId);
freeVlanList.add(vlanId);
//logger.addInfo("2:FREE IP IS:"+vlanId);
}
}
} else
{
freeVlanList.add(vlanId);
// logger.addInfo("3:FREE IP IS:"+vlanId);
}
}
logger.addInfo("NO OF AVAILABLE FREE VLANS:::"+freeVlanList.size());
// return -1;
return freeVlanList;
}
///////////////////////////////////////
//private List<Integer> getVLANListFromVLANPoolPolicy(String vlanID) throws Exception
function getVLANListFromVLANPoolPolicy(vlanID) //throws Exception
{
/*try
{
var vlanList = new ArrayList();
} catch (e)
{
logger.addError("Error While retrieving VLAN ID from VLAN Pool::::::"+e);
throw new Exception("Error While retrieving VLAN ID from VLAN Pool");
}
return vlanList;
*/
try
{
var vlanList = new ArrayList();
var vlanArr = vlanID.split(",");
if ((vlanArr != null) && (vlanArr.length > 0))
{
for (var count = 0;count<vlanArr.length;count++)
{
var vlanRange = vlanArr[count];
if (vlanRange.contains("-"))
{
var vlanRangeArr = vlanRange.split("-");
if (vlanRangeArr[0] != null)
vlanRangeArr[0] = vlanRangeArr[0].trim();
if (vlanRangeArr[1] != null)
vlanRangeArr[1] = vlanRangeArr[1].trim();
var startId = Integer.parseInt(vlanRangeArr[0]);
var endId = Integer.parseInt(vlanRangeArr[1]);
for (var i = startId; i <= endId; i++)
vlanList.add(i);
} else
{
vlanList.add(Integer.parseInt(vlanRange));
}
}
}
return vlanList;
} catch (e)
{
logger.addError("Error While retrieving VLAN ID from VLAN Pool::::::"+e);
throw new Exception("Error While retrieving VLAN ID from VLAN Pool");
}
}
The custom Task Inputs and outputs:
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: