Edited... sorry when I first replied I thought I saw customProperties was a local var but it already is. I'd say try it at the build step. My guess is allocation is taken on the build profile so even though it sounds like this would be the correct spot it might be one step beyond where you can set those properties? Somewhere there is a flow chart with oder of operations for all the events but I'm not finding it.
Original Message:
Sent: Oct 30, 2024 02:13 AM
From: antonioaraujo
Subject: Can we modify "cpuCount" and "totalMemoryMB" in a workflow triggered by compute.allocation.pre event topic?
Dear @qc4vmwaare
I hope you are fine.
Thank you very much for your comment.
Sure, you can see some screenshots of the workflow below:




The full JavaScript code is listed below:
System.log("Set final CPU count and Memory values...");// check inputPropertiesvar customProperties = inputProperties.get("customProperties");var cpu = 1;var totalMemory = 1024;var cpuMemoryConfiguration = customProperties.get("cpuMemoryConfiguration");System.log("cpuMemoryConfiguration: " + cpuMemoryConfiguration);var customFlavor = customProperties.get("customFlavor");System.log("customFlavor: " + customFlavor);var inputCpu = customProperties.get("cpuCount");System.log("cpuCount: " + inputCpu);var inputMemory = customProperties.get("totalMemoryMB");System.log("totalMemoryMB: " + inputMemory);if (cpuMemoryConfiguration == "flavor"){ System.log("cpuMemoryConfiguration == flavor"); if (customFlavor == "tiny"){ cpu = 1; totalMemory = 2048; } else if (customFlavor == "small") { cpu = 2; totalMemory = 4096; } else if (customFlavor == "medium"){ cpu = 4; totalMemory = 8192; } else if (customFlavor == "large") { cpu = 8; totalMemory = 16384; } else { cpu = 1; totalMemory = 2048; System.log("flavor read from customProperties has an invalid value. Setting cpu=1 and memory=2048"); }} else if (cpuMemoryConfiguration == "cpumemory") { System.log("cpuMemoryConfiguration == cpumemory"); cpu = inputCpu; totalMemory = inputMemory; }// Log the hostname selected by the user. System.log("Final CPU count: " + cpu + ", TotalMemoryMB: " + totalMemory);customProperties.put("cpuCount", cpu);customProperties.put("totalMemoryMB", totalMemory);
When the workflow is run, I can see that customProperties variable (workflow output):

includes the values for totalMemoryMB and cpuCount as shown below:

However, the VM deployed has the default values for cpuCount=1 and memory=2048.
Maybe I am missing something.
Just for reference, the subscription created is using the event topic "compute allocation":

Best regards
Antonio
Original Message:
Sent: Oct 30, 2024 01:31 AM
From: qc4vmware
Subject: Can we modify "cpuCount" and "totalMemoryMB" in a workflow triggered by compute.allocation.pre event topic?
It looks like your task might now have an output set for customProperties. If there is an output set the text should display in brown unless you are editing it in an external editor. If you can post your workflow it will make it easier to debug.
Original Message:
Sent: Oct 29, 2024 09:11 AM
From: antonioaraujo
Subject: Can we modify "cpuCount" and "totalMemoryMB" in a workflow triggered by compute.allocation.pre event topic?
Dear all,
I hope you are fine.
This is the question:
Can we modify "cpuCount" and "totalMemoryMB" in a workflow triggered by compute.allocation.pre event topic?
This is the context:
A cloud template that can allow the user to select a Flavor or CPU count and Memory has been developed using the following catalog item.
A field called "CPU/Memory configuration" was added to provide the options as shown below:

If Flavor is selected, then "Flavor" field is shown below with the flavor mappings available.
If "CPU count and Memory" is selected, then "CPU count" and "Memory in MB" are shown below to allow user to enter the specific values.

Cloud template has the following properties:resources: Cloud_vSphere_Machine_1: type: Cloud.vSphere.Machine properties: image: RHEL-9.4-Template-With-Cloudinit cpuMemoryConfiguration: ${input.cpumemoryconfiguration} customFlavor: ${input.flavor} cpuCount: ${input.cpuCount} totalMemoryMB: ${input.memory} folderName: ${env.projectName} description: ${input.description} …
A subscription called "Set CPU count and Memory in a VM deployment" with the "Compute allocation" event topic triggers an Orchestrator workflow that reads inputProperties (payload from vRA) and checks the value of cpuMemoryConfiguration, customFlavor, cpuCount and memory to set cpuCount and totalMemoryMB according to the cpuMemoryConfiguration (flavor or cpu/memory)

I have configure a scriptable task that set the values cpuCount and totalMemoryMB as shown below
System.log("Set final CPU count and Memory values...");// check inputPropertiesvar customProperties = inputProperties.get("customProperties");var cpu = 1;var totalMemory = 1024;var cpuMemoryConfiguration = customProperties.get("cpuMemoryConfiguration");System.log("cpuMemoryConfiguration: " + cpuMemoryConfiguration);var customFlavor = customProperties.get("customFlavor");System.log("customFlavor: " + customFlavor);var inputCpu = customProperties.get("cpuCount");System.log("cpuCount: " + inputCpu);var inputMemory = customProperties.get("totalMemoryMB");System.log("totalMemoryMB: " + inputMemory);if (cpuMemoryConfiguration == "flavor"){ System.log("cpuMemoryConfiguration == flavor"); if (customFlavor == "tiny"){ cpu = 1; totalMemory = 2048; } else if (customFlavor == "small") { cpu = 2; totalMemory = 4096; } else if (customFlavor == "medium"){ cpu = 4; totalMemory = 8192; } else if (customFlavor == "large") { cpu = 8; totalMemory = 16384; } else { cpu = 1; totalMemory = 2048; System.log("flavor read from customProperties has an invalid value. Setting cpu=1 and memory=2048"); }} else if (cpuMemoryConfiguration == "cpumemory") { System.log("cpuMemoryConfiguration == cpumemory"); cpu = inputCpu; totalMemory = inputMemory; }// Log the hostname selected by the user. System.log("Final CPU count: " + cpu + ", TotalMemoryMB: " + totalMemory);//cpuCount = cpu;//totalMemoryMB = totalMemory;customProperties.put("cpuCount", cpu);customProperties.put("totalMemoryMB", totalMemory);
However, once the VM is requested and the event topics triggers the workflow, the values of cpuCount and totalMemoryMB are not set in the final VM deployed.
Do you know is this approach is feasible?
Best regards
Antonio