slideshow 6 slideshow 4 slideshow 8 slideshow 1 slideshow 2 slideshow 3 slideshow 5 slideshow 7

Using the Switch element in vRealize Orchestrator

vRealize Orchestrator (v6) contains a switch element that can be used to evaluate a series of values. In scripting and programming languages the switch construct is also named Case or Do Case.

For example if we want to check the status of a VM and there are three possible values then we would have to use three if statements or three decision elements to check what the status is.

if status = poweredOn 
if status = poweredOff 
if status = suspended 

Now we can use the switch element to handle this. you start with adding the switch element to your workflow. In this example I also have first added a small script that will get the power state of a VM. (This the single line of code in that script: vmState = vm.runtime.powerState.value;)

You can also download the complete workflow here

vCenter Orchestrator Switch example

Next drop an element to the right of the switch element. This new element will become the default path that we will use when no values match.

vCenter Orchestrator Switch example

Next drop an element on top of the switch element which will create a new branch for the first value to evaluate.

vCenter Orchestrator Switch example

With the new branch added it will look like this. With the difference that I have also connected that additional branch to the workflow that we follow with the normal path. If you checkout my final example you will understand why.

vCenter Orchestrator Switch example

Next add yet another element on top of the switch to evaluate another attribute value.  And then edit the switch to define the values that you want to evaluate and which path to take for which element.
vCenter Orchestrator Switch example

In this final example you can see what happens: if a vm is powered off then we take the default path of creating a snapshot. If the vm is suspended we follow a path to first start the vm and then from there shut down the vm. And finally when the vm is powered on we will shut it down.

vCenter Orchestrator Switch example

Follow us on LinkedIn