Some more advanced programming

Now that we have gone over the basics of programming, let's go a little further. We will use one of the items of the toolbox, the decision element. We will work with some other elements later on in this book, but we won't be able to cover all of them. All the elements are explained with examples in the vRealize Orchestrator Cookbook.

Adding a decision element

A decision element is what programmers call an If-clause. It checks for a condition and then points to one or the other way. A decision uses a test to check whether a certain condition has been met. The result is always true or false. The following three types of decision elements exist in Orchestrator:

Adding a decision element

The differences between the three decision elements are the following:

  • A (basic) Decision can only check whether a single parameter has fulfilled a certain condition. There are simple checks that depend on the type of the parameter. For instance, it can check whether a number is greater than a set value or whether a string contains a certain value or the power state of a VM.
  • A Custom decision enables the programmer to write a JavaScript to determine whether a condition has been met. This check can be as complex as the programmer likes.
  • The Decision activity checks the outcome (the OUTPUT parameter) of a workflow against a certain simple condition like the (basic) Decision.

In the next chapter about JavaScript, we will dive a bit deeper into conditions and these checks.

We will now use the (basic) Decision element to modify our first workflow by performing the following steps:

  1. By using the Orchestrator Client, copy our first workflow or create a new version as shown earlier.
  2. Now, edit the copied workflow.
  3. Drag the Decision element from the Generic toolbox into the workflow between the Create simple virtual machine and Add CD-ROM workflows.
  4. You will see that after inserting this element, a new end point has been created, and there is a green and a red line. The green line represents the flow of the program if the result of decision is True, whilst the red is the False result.
    Adding a decision element
  5. We will now implement a check in the Decision element. The aim is to insert a CD-ROM image depending on the chosen operation system. To do this, we first need to move the vmGuestOs parameter from its current place in the attributes to the INPUT parameters so that we can choose a different OS.
  6. Go to the attributes, right-click on the vmGuestOs parameter, and select Move as INPUT parameter.
  7. Now, go back to the schema and edit the Create simple virtual machine workflow element. You will see that the vmGuestOs is not set anymore. We discussed this behavior before.
  8. Set the vmGuestOs as the INPUT parameter again.
  9. Now, we will set up the Decision element. Edit the Decision element and then click on Decision.
  10. The parameter that should be checked is currently not defined and shows Not set (NULL). Just click on it.
  11. A window will open up and display all the attributes and INPUT parameters of the workflow. Choose vmGuestOs.
  12. Then, choose the Name equals from the drop-down menu and enter windows7Guest_64 in the text box next to it, as follows:
    Adding a decision element

We now have a decision. When the workflow runs and someone selects the Windows 7 64-bit operating system, the workflow will follow the green line. If someone selects anything else, the workflow will end. This is not really ideal, but we are not finished yet.

Working with connection lines

Each element in a workflow is connected by a line to another. We will now modify our workflow to make it a bit more useful and learn how to connect workflow elements as well as break them.

  1. When editing the workflow, select the line between the Decision element and the end point by simply clicking on it. It should get bolder.
  2. Now, press Delete, and the red line as well as the end element will disappear.
  3. Drag another Add CD-ROM workflow directly onto the Decision element, as follows:
    Working with connection lines
  4. The new Add CD-ROM workflow element will now be automatically connected to the Decision element by using a red (false) arrow. This is because the green (true) arrow is already connected.
  5. Hover your mouse over the new Add CD-ROM element. You will see that a blue arrow and a red arrow appear. Hover over the blue one until it becomes bigger.
  6. Drag the blue line onto the startVM action, as follows:
    Working with connection lines

    We have now connected all the elements of this workflow as well as created a more meaningful false branch. Let's clean up and make it not only prettier, but also more readable.

  7. Drag the second Add CD-ROM workflow element underneath the other one.
  8. Rename the Decision element to something that resembles the check that you perform, such as Windows7?.
  9. Rename the Add CD-ROM workflows to clarify what the difference is, such as Add Win CD-ROM and Add LINUX CD-ROM.
    Working with connection lines
  10. Now, we need to assign parameters to the new Add CD-ROM workflow element. Edit the workflow and assign the parameters, as follows:

    Parameter

    Type

    Value

    vm

    existing

    newVM

    ConnectAtPowerOn

    existing

    ConnectAtPowerOn

    deviceType

    existing

    deviceType

    filePath

    Value

    [Datastore name] folder/file of a different ISO image

This concludes our little example for the moment. We will come back to it later and improve it further.

Things you might like to try out

Here are some ideas that you can try out with this workflow:

  • Add another Decision element to check whether it's a SUSE Linux.
    Things you might like to try out
  • Explore the Switch element from the toolbox (needs vRO 6).
    Things you might like to try out
  • Check out the different decisions that you can perform depending on the variable type. To do this, create or use parameters of the type: number, string, VM, and datastore in the Decision element and check the content of the drop-down menu.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset