VMware Cloud Community
emanarch1
Contributor
Contributor
Jump to solution

vro to call vra to scale in a deployment

I am using code for all day 2 operations on a vm. Destroy/Power on etc.  However, the scale-in function does not seem to work for me.

I i get the operations for the deployment like this .. but it does not execute a scale in. any ideas ?

var form = vCACCAFERequestsHelper.getRequestFormForResourceAction(operation);

System.log("Expected inputs:");

var fields = vCACCAFERequestsHelper.getFormKeys(form);

System.log(fields.length);

for each (var field in fields) {

    System.log( " - " + field);

}

System.log("Creating scale in request...");

var request = vCACCAFERequestsHelper.requestResourceAction(operation, form);

System.log("Scale in request submitted.");

System.log("request.stateName: " + request.stateName);

System.log("request.executionStatus: " + request.executionStatus.value());

1 Solution

Accepted Solutions
Burke-
VMware Employee
VMware Employee
Jump to solution

I suspect the high view count vs. no reply thus far is because you have posted something many people are interested in, but very few have accomplished Smiley Happy ... Well, I have this working in class I teach internally and to partners... While I'm not going to provide my entire workflow, I'll provide the most critical piece that you appear to need and that is the bit of code that actually submits the scale operation to vRA. This code can scale-in OR scale-out a deployment - the differentiating factor is what is provided for the inputs.

  1. First off, create a new workflow that you'll call from your solution... in mine, I named it Submit to vRA
  2. Add the following action: requestResourceAction (found in com.vmware.library.vcaccafe.request) -- this action is what performs the actual operation. It takes two inputs: operation (vCACCAFE:ConsumerResourceOperation) and inputs (Properties).
  3. Add a Scriptable task between the Start element and the action and name it Prepare Properties
  4. Add the following Inputs to the Prepare Properties scriptable task:
    - componentTypeId (string: Attribute with value set to: )
    - componentId (string: Input parameter)
    - classId (string: )- clusterNodeCount (number: Input parameter)
    - BlueprintId (string: Input parameter)
    - typeFilter (string: NULL)
  5. Add the following Output to the Prepare Properties scriptable task:
    - props (Properties: Attribute)
  6. Add the following code to the Scripting tab of Prepare Properties scriptable task:

    var myvCACCAFELiteralMap = new vCACCAFELiteralMap()

    myvCACCAFELiteralMap.put("_cluster", new vCACCAFEIntegerLiteral(clusterNodeCount));

    typeFilter = BlueprintId + "*" + componentId;

    var myvCACCAFEComplexLiteral = new vCACCAFEComplexLiteral(

      componentTypeId,

      null,

      classId,

      typeFilter,

      myvCACCAFELiteralMap);

    props = new Properties();

    props.put(("provider-" + componentId), myvCACCAFEComplexLiteral);

  7. Now, make sure bindings are set as shown below:

Screen Shot 2017-05-04 at 8.55.44 AM.png

1st Screenshot: Bindings for Prepare Properties scriptable task

Screen Shot 2017-05-04 at 8.56.22 AM.png

2nd Screenshot: Bindings for requestResourceAction action

Screen Shot 2017-05-04 at 8.57.15 AM.png

3rd Screenshot: Inputs to Submit to vRA workflow

Input notes:

  • operation - This is an object. Many to choose from when browsing the vRealize Automation Plug-in, look under Administration -> Resource Operations. For the purposes of this post, it would be either Scale In or Scale Out
  • BlueprintId - self-explanatory (Hint: virtualMachineProperties.get("VirtualMachine.Cafe.Blueprint.Id") )
  • componentId - this is the Component ID of the blueprint item you wish to scale in/out -- IE: the Component ID of the web server (Hint: virtualMachineProperties.get("VirtualMachine.Cafe.Blueprint.Component.Id") )
  • clusterNodeCount - This is the desired number of nodes that the blueprint should scale in/out to

(In my hints above, the virtualMachineProperties object is a properties object that was created using the getVirtualMachineProperties action from one of the dailyhypervisor.com packages.)

Your overall workflow should gather the necessary inputs to provide to this one. The one bit that I haven't figured out (due to lack of motivation and/or need) is how to find (via API of course) the Min/Max instances of a Component in the Blueprint.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter

View solution in original post

8 Replies
emanarch1
Contributor
Contributor
Jump to solution

Wondering if i am not clear with my question. Many views but no responses. Any ideas will be much appreciated.

Reply
0 Kudos
emanarch1
Contributor
Contributor
Jump to solution

Folks, anybody has ever coded vro call vra to scale-in/scale-out a deployment ?

Reply
0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

I suspect the high view count vs. no reply thus far is because you have posted something many people are interested in, but very few have accomplished Smiley Happy ... Well, I have this working in class I teach internally and to partners... While I'm not going to provide my entire workflow, I'll provide the most critical piece that you appear to need and that is the bit of code that actually submits the scale operation to vRA. This code can scale-in OR scale-out a deployment - the differentiating factor is what is provided for the inputs.

  1. First off, create a new workflow that you'll call from your solution... in mine, I named it Submit to vRA
  2. Add the following action: requestResourceAction (found in com.vmware.library.vcaccafe.request) -- this action is what performs the actual operation. It takes two inputs: operation (vCACCAFE:ConsumerResourceOperation) and inputs (Properties).
  3. Add a Scriptable task between the Start element and the action and name it Prepare Properties
  4. Add the following Inputs to the Prepare Properties scriptable task:
    - componentTypeId (string: Attribute with value set to: )
    - componentId (string: Input parameter)
    - classId (string: )- clusterNodeCount (number: Input parameter)
    - BlueprintId (string: Input parameter)
    - typeFilter (string: NULL)
  5. Add the following Output to the Prepare Properties scriptable task:
    - props (Properties: Attribute)
  6. Add the following code to the Scripting tab of Prepare Properties scriptable task:

    var myvCACCAFELiteralMap = new vCACCAFELiteralMap()

    myvCACCAFELiteralMap.put("_cluster", new vCACCAFEIntegerLiteral(clusterNodeCount));

    typeFilter = BlueprintId + "*" + componentId;

    var myvCACCAFEComplexLiteral = new vCACCAFEComplexLiteral(

      componentTypeId,

      null,

      classId,

      typeFilter,

      myvCACCAFELiteralMap);

    props = new Properties();

    props.put(("provider-" + componentId), myvCACCAFEComplexLiteral);

  7. Now, make sure bindings are set as shown below:

Screen Shot 2017-05-04 at 8.55.44 AM.png

1st Screenshot: Bindings for Prepare Properties scriptable task

Screen Shot 2017-05-04 at 8.56.22 AM.png

2nd Screenshot: Bindings for requestResourceAction action

Screen Shot 2017-05-04 at 8.57.15 AM.png

3rd Screenshot: Inputs to Submit to vRA workflow

Input notes:

  • operation - This is an object. Many to choose from when browsing the vRealize Automation Plug-in, look under Administration -> Resource Operations. For the purposes of this post, it would be either Scale In or Scale Out
  • BlueprintId - self-explanatory (Hint: virtualMachineProperties.get("VirtualMachine.Cafe.Blueprint.Id") )
  • componentId - this is the Component ID of the blueprint item you wish to scale in/out -- IE: the Component ID of the web server (Hint: virtualMachineProperties.get("VirtualMachine.Cafe.Blueprint.Component.Id") )
  • clusterNodeCount - This is the desired number of nodes that the blueprint should scale in/out to

(In my hints above, the virtualMachineProperties object is a properties object that was created using the getVirtualMachineProperties action from one of the dailyhypervisor.com packages.)

Your overall workflow should gather the necessary inputs to provide to this one. The one bit that I haven't figured out (due to lack of motivation and/or need) is how to find (via API of course) the Min/Max instances of a Component in the Blueprint.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
emanarch1
Contributor
Contributor
Jump to solution

Thank you , it looks great and i appreciate your response. 

Wonder in the docs where you managed to find it .. but i will try that now and let you know.

thanks much

Reply
0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

One of my colleagues just posted a step-by-step blog article on the topic of Auto-Scaling - I suspect the code I shared here is likely to be part of the workflow package he includes in the article: Auto-Scale VMware vRA Workloads with NSX, vRO and vRealize Automation

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
Reply
0 Kudos
emanarch1
Contributor
Contributor
Jump to solution

Thank you , but your colleague did not post any code. He just posted the idea; which is the same thing i am trying to solve.

Reply
0 Kudos
emanarch1
Contributor
Contributor
Jump to solution

Thank you again and it seems the code should be working..

here is what i have now. (see below) on the first run it fails .. it can not get the "propsin.machine.properties"

directly from ebs.. however, if i execute the workflow again, it works fine. So i assume code is good, just not

able to get propsin right away. Wonder if it's a bug or something else.

instanceNumber--;

System.log(" Scaling in to " + instanceNumber + " VMs");

var myvCACCAFELiteralMap = new vCACCAFELiteralMap();

myvCACCAFELiteralMap.put("_cluster", new vCACCAFEIntegerLiteral(instanceNumber)); 

sleep (10);

System.log ("Trying to get the BluePrint ID");

var blueprintId = propsin.machine.properties['VirtualMachine.Cafe.Blueprint.Id'];

System.log("BlueprintID: " + blueprintId);   

typeFilter = blueprintId + "*" + propsin.componentId;  

System.log("TypeFilter: " + typeFilter);   

     

var myvCACCAFEComplexLiteral = new vCACCAFEComplexLiteral( 

      propsin.componentTypeId, 

      null, 

      'Blueprint.Node', 

      typeFilter, 

      myvCACCAFELiteralMap); 

     

     

props = new Properties(); 

props.put(("provider-" + propsin.componentId), myvCACCAFEComplexLiteral);

Reply
0 Kudos
emanarch1
Contributor
Contributor
Jump to solution

awesome job . it works great ! thank you

Reply
0 Kudos