VMware Aria Automation Tools

 View Only
  • 1.  Can we modify "cpuCount" and "totalMemoryMB" in a workflow triggered by compute.allocation.pre event topic?

    Posted Oct 29, 2024 09:12 AM

    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 inputProperties
    var 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



  • 2.  RE: Can we modify "cpuCount" and "totalMemoryMB" in a workflow triggered by compute.allocation.pre event topic?

    Posted Oct 30, 2024 01:32 AM

    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.




  • 3.  RE: Can we modify "cpuCount" and "totalMemoryMB" in a workflow triggered by compute.allocation.pre event topic?

    Posted Oct 30, 2024 02:13 AM
    Edited by antonioaraujo Oct 30, 2024 03:19 AM

    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 inputProperties
    var 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




  • 4.  RE: Can we modify "cpuCount" and "totalMemoryMB" in a workflow triggered by compute.allocation.pre event topic?

    Posted Nov 04, 2024 06:09 PM
    Edited by qc4vmware Nov 04, 2024 06:35 PM

    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.  

    Maybe try calling this from compute.provision.pre ?  Also, when we were first setting things up when not specifically using flavors we had to have at least one flavor defined that could support that maximum size of whatever vm's we wanted to deploy.  So even though we don't use their flavors we created one that we call WAYYYYY Big that is like 40 cpu and some high amount of ram.  I think there is some logic in vRA when you don't specify a flavor where it might still process them in some way.




  • 5.  RE: Can we modify "cpuCount" and "totalMemoryMB" in a workflow triggered by compute.allocation.pre event topic?

    Broadcom Employee
    Posted Oct 30, 2024 04:16 AM

    I suggest you remove "var" from line 4, customProperties is already defined.
    Make sure your subscription is "blocking", otherwise the modifications to customProperties are not stored and will not be passed on to the next events.




  • 6.  RE: Can we modify "cpuCount" and "totalMemoryMB" in a workflow triggered by compute.allocation.pre event topic?

    Posted Oct 30, 2024 06:23 AM

    Dear @Michael Duchaine,

    I hope you are fine.

    Thank you very much for your comments.

    I updated the scriptable task removing var from line 4 as shown below:

    I also double-checked that the subscription if "blocking":

    However, after requesting a new deploying the VM does not take values set in the workflow.

    Workflow output shows that "cpuCount" and "totalMemoryMB" were assigned properly but not taken by the VM:

    VM is only using the values that were set in the cloud template:

    Do you know if there is any constraints for setting those values (cpuCount and totalMemoryMB) within an Orchestrator workflow in customProperties? I mean, is that feasible?

    Best regards

    Antonio