Chapter 5. Combining and Modifying Workflows

Now that we understand how to work with a workflow, we will take the next step of combining workflows. As there are a lot of previously created workflows in the library, we can simply play Lego and build a new workflow from the existing elements. This is a common practice. What is also pretty common is to modify the existing workflows to make them do what you would like them to do. In this chapter, we will do all that and a bit more.

For this chapter, I assume that you have gone through the previous chapter or are familiar with its concepts. Here are the major concepts that we'll look at in this chapter:

  • Combining the existing workflows
  • Workflow validation and history
  • Useful workflow operations such as copying, deleting, and undeleting a workflow
  • Introduction to parameter types
  • Introduction to the workflow decision element
  • Modifying the existing workflows

Combining existing workflows

A very common task for workflow creators is to use the existing workflows and put them together. In this section, we will create a new workflow that consists of other workflows. We will build a workflow that will create a VM, add and mount a CD-ROM, and then start it. We have already used the workflows involved in the last chapter. During the next chapters we will enhance this workflow further.

Tip

It's always a good idea to try out an existing workflow before using it so that you know what it is really doing and what inputs it needs.

Creating a new workflow

In order to build a workflow that combines two or more existing workflows, we first need to create a new empty workflow. Just placing a workflow somewhere in the library isn't really that professional. So, we will create a new folder in the library that we will use to store our workflows in. This will also help us later when we create a new package for export (see Chapter 9, Packing It All Up).

Creating a new library folder

To create a new library folder, perform the following steps:

  1. In the Orchestrator client, select the Design mode (the drop-down menu at the top) and then select workflows, Creating a new library folder (the blue icon with white elements).
  2. Right-click on the top library element, Creating a new library folder (the orange, square icon with white cycle).
  3. Select Add folder.
  4. Enter the new folder's name, such as MyWorkflows.

A new folder has been created.

Creating a new library folder

You can change the name of the folder by right-clicking on it and then selecting Edit.

Opening a new workflow for editing

Now that we have a folder, we can create a new empty workflow in it, simply follow these steps:

  1. Right-click on the new library folder that you created and select New workflow.
  2. You are now asked to give the workflow a name, such as InstallFreshVM.

The new workflow opens up and is now ready for editing:

Opening a new workflow for editing

You have seen the preceding window before in Chapter 4, Working with Workflows, where we discussed what each item in this window means.

Adding workflows

Let's add elements to our new workflow.

There are two methods that can be used to add workflows to a new workflow. We will first add the Create simple virtual machine workflow by searching for it and then the Add CD-ROM workflow by selecting it from the library.

  1. In the new workflow that you opened for editing, click on Schema.
  2. In the tool box to the left, you will find the Generic box already opened.
  3. Scroll down and find Workflow element.
  4. Drag the Workflow element icon between the start icon and the end icon, as shown in the following screenshot:
    Adding workflows
  5. As soon as you release the mouse, a window will appear, where you can search for the workflow to be added. In the filter, start typing simple. The more you type, the fewer results are shown. Now type [space] and vi.
    Adding workflows
  6. This should result in only one workflow—Create simple virtual machine.
  7. Click on Select.

    The workflow element has been added to our new workflow. Let's add the Add CD-ROM workflow a different way.

  8. In the toolbox to the right, select All Workflows.
  9. As you can see, the workflow tree library is shown. Dig down to Library | vCenter | Virtual Machine management | Device Management and then drag the Add CD-ROM workflow onto the schema just after the Create simple virtual machine workflow.
    Adding workflows

Adding actions to a workflow

Actions are a different type of workflow. They are what programmers call functions. In Orchestrator, an action is written in JavaScript and can only have one out-parameter, whereas a workflow can have more than one. We will have a closer look at actions in the next chapter when we also look at JavaScript.

Adding an action also works via two methods, as is the case with workflows. Now, we will add an action to our workflow that starts up (powers on) a VM:

  1. In Schema, click on the All Actions toolbox tab.
  2. Look for an action module (the folder symbol) called com.vmware.libary.vc.vm.power. Actions are not sorted in a library view like workflows, but come in modules. As you can see from the name and by browsing through the actions, the modules are sorted and named to simulate a treelike structure.
  3. Drag the StartVM action into the schema and place it after the Add CD-ROM workflow element:
    Adding actions to a workflow

We can also use the Action element from the Generic toolbox, which works by searching for the name of an action, just like we did with the workflows.

The big question is, why should we add an action? Surely there is a workflow that powers on a VM? Well, there is one such workflow, and we will work with it at the end of this chapter when we talk about altering existing workflows. The problem with the Start virtual machine and wait workflow is that it waits for the VMware tools to start up inside the VM. However, we are creating a brand new, empty VM. So, there are no VMware tools yet. Therefore, we have to use the action.

Tip

There are lots of actions that come with Orchestrator. It's a good idea to browse the library actions.

Now that we have added two workflows and one action, we have all the elements of our new workflow together, and we can now go ahead and assign all of their parameters.

Assigning parameters

As you know from Chapter 4, Working with Workflows, each workflow has attributes as well as input and output parameters. To make our new workflow actually work, we need to assign the input and output parameters to our newly created workflow.

Just be mindful of the fact that this process involves a pretty long set of steps, but persistence definitely pays off.

  1. We start where we left off.
  2. In the workflow, hover your mouse over the first workflow element. You will see that the following four icons are displayed:
    Assigning parameters

    The Delete icon deletes this element from the schema. The Error Path icon will be discussed later in Chapter 8, Errors, Logs, and Debug Mode. The Open Details icon displays the workflow in a separate window so that you can check what it actually does. The Edit icon is the one that we will be using.

    Tip

    In Orchestrator 6, you can also use the "bulk import" parameters as soon as you click on a workflow element. We will have a look at that at the end of this section.

  3. Click on the Edit icon.
  4. A new window will open. Click on the IN tab to select the input parameter.
  5. Each input parameter needs to be assigned. If a parameter is not assigned, not set is written next to its name. Now, click on not set next to the vmName parameter.
  6. A new window will open up and show all the possible values that already exist. As this workflow is totally empty, only NULL is shown. Click on Create parameter/attribute in workflow.
  7. Another window opens and lets you create a new attribute inside your new workflow. First, you can (if you want) change the name. However, I normally go with the default name.
  8. A description is a good idea as it explains what a parameter is for.
  9. Now we come to the type of the parameter. We will have a closer look at all the types a bit later in this chapter. Nothing to do here, we will use the default.
  10. You now have two choices. You can make this parameter an input parameter for our new workflow, or you can keep the value fixed. As an input parameter, the user will be asked for it when you start the new workflow. As an attribute, the value is fixed. Choose Create workflow INPUT PARAMETER with the same name.
    Assigning parameters
  11. Click on Ok to return to the list of all the parameters.
  12. Now, click on the not set that is next to vmGuestOs.
  13. Again, we will create a new parameter like we did before. But this time, we will choose to keep this one fixed. Choose Create workflow ATTRIBUTE with the same name.
  14. Select an operating system for your workflow by clicking on not set next to Value and choosing one from the list, such as windows7_64Guest. Remember to press Enter in the filter. Otherwise, you won't see anything.
  15. Click on Ok to return to the list of all the parameters.
  16. Now, click on not set next to vmHost.
  17. As we saw in the last chapter, we don't need this parameter. So, just click on the existing NULL. Then, click on Select.
  18. Now that we learned the basics lets speed this up a bit. For the first workflow element, we will define the parameters in the following way:

    Parameter

    Type

    Value

    vmName

    INPUT

     

    vmGuestOs

    Value

    windows7_64Guest

    vmFolder

    Value

    Select a folder in your infrastructure

    vmResourcePool

    Value

    Select a resource pool in your infrastructure

    vmHost

    NULL

    We don't need to fill anything into this parameter

    vmDiskSize

    Value

    Select some number of GBs for this disk

    vmMemorySize

    INPUT

     

    vmNbOfCpus

    INPUT

     

    vmNetwork

    Value

    Select a VM network from your inventory

    vmDatastore

    Value

    Select a datastore in the your infrastructure

    diskThinProvisioned

    Value

    Select Yes to allow for thin provisioning

  19. Now that all the input parameters are defined, let's look at the out parameter. Click on OUT.
  20. There is only one out parameter, newVM. This parameter will hold the ID of the new VM, and we will reuse it in the workflow.
  21. Click on not set next to newVM and then create a new parameter. Select a value, but leave the value as not set. Click on OK. This will create an attribute that is empty, so that the workflow can fill it in later.
  22. Now that we have finished the first workflow element, let's go to the second one, Add CD-ROM. Edit the workflow element and click on IN to see all the input parameters.
  23. The first parameter is called vm, whose type is the same as that of the newVM output parameter. Click on not set, select the already existing newVM parameter, and click on Select.
    Assigning parameters
  24. Fill the rest of the parameters, as follows:

    Parameter

    Type

    Value

    vm

    existing

    newVM

    ConnectAtPowerOn

    Value

    Yes

    deviceType

    Value

    Datastore ISO file

    filePath

    Value

    [Datastore name] folder/file

  25. Have a look at the out-parameter, as there isn't one, we are done with this element and can move on.
  26. Edit the action element and select IN.
  27. There are only two input parameters. vm will take the newVM attribute. The other is host, and the description says that it's optional. So, set it to NULL.
  28. Click on OUT. Every action has the same out-parameter called actionResult. Only the type changes. We are not interested in the return value. So, we will just set it to NULL.
    Assigning parameters

We are done. We have assigned all the parameters of all the elements in our schema. We learned how to assign a parameter as an input and set a value for it or ignore it by setting it to NULL. We also learned about the special output parameter that actions have.

Since Orchestrator 5.5, things are easier. When you click on the Edit icon, note the grey information bar with a Setup button. By clicking on it, you will now be able to quickly assign all the parameters in one window. Selecting Skip will set the parameter to NULL.

Assigning parameters

Workflow verification

Now that we have assigned all the parameters of the workflow element to the new workflow, we can finally save it and give it a go.

To save the workflow, click on Save and close. If you have created the workflow correctly, Orchestrator will ask whether you want to create a new version of this workflow. In this case, skip to the next section.

If you did something wrong (and you may want to try this), you will be presented with a window that looks like this:

Workflow verification

When Orchestrator saves a workflow, it checks whether all the parameters are assigned, whether there are any empty scripts, and so on. If this is the case, you will get a warning. You can ignore this warning by clicking on Continue anyway. This will save the workflow in the current state. However, you will not be able to execute it.

If you click on View details, Orchestrator will present you with a window that shows its findings.

Workflow verification

In the preceding example, I didn't assign the deviceType and diskThinProvisioned parameters. I also added a thisIsTooMuch attribute, which isn't used. In section A, we find the error that Orchestrator found. In section B, we see the workflow element in which this error occurred. In section C, you are presented with a possibility of fixing the problem. Clicking on Bind parameter will bring you directly to the window where you can create a new parameter or choose from an existing one.

The Delete attribute option should be used with caution. You may not want to delete the parameter. You may just have forgotten to assign it to something. So, check it out first.

You can also run the validation at any point by clicking on Validation Validate at the top of the schema.

Workflow history

When you save and close a workflow, you are asked whether you would like to Add to Version History. What this means is that Orchestrator can keep different histories of a workflow.

Workflow history

Selecting Increase version will create a new version of the workflow. You can see the current versions of a workflow in the General section. By clicking on Show version history, you can see all the existing versions of this workflow.

Workflow history

Comparing the versions

You can use this function to compare the versions of a workflow.

  1. On the workflow's General tab, click on Show version history.
  2. Select the version that you would like to compare the present one against and click on Diff Against Current.
  3. A window will pop up and show both the versions next to each other. Resize the window as required.
  4. When you are finished, click on Close.
    Comparing the versions

Reverting to an older version

Perform the following steps to revert to an older version of the workflow:

  1. Click on Show version history.
  2. Select the version that you'd like to revert to and click on Revert.

Your workflow is now of an earlier version. However, the newer version is still available. You can also revert to a newer version if you wish.

..................Content has been hidden....................

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