Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
VMware vRealize Orchestrator Cookbook. - Second Edition

You're reading from  VMware vRealize Orchestrator Cookbook. - Second Edition

Product type Book
Published in Nov 2016
Publisher Packt
ISBN-13 9781786462787
Pages 556 pages
Edition 2nd Edition
Languages
Author (1):
Daniel Langenhan Daniel Langenhan
Profile icon Daniel Langenhan

Table of Contents (19) Chapters

VMware vRealize Orchestrator Cookbook Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Installing and Configuring Orchestrator 2. Optimizing Orchestrator Configuration 3. Distributed Design 4. Programming Skills 5. Visual Programming 6. Advanced Programming 7. Interacting with Orchestrator 8. Better Workflows and Optimized Working 9. Essential Plugins 10. Built-in Plugins 11. Additional Plugins 12. Working with vSphere 13. Working with vRealize Automation

Chapter 5. Visual Programming

This chapter looks into the basic visual programming tools we can use. We will have a look at the following recipes:

  • Scripting with logs

  • Scripting with decisions

  • Error handling in workflows

  • Scripting with loops

  • Workflow presentations

  • Linking actions in presentations

  • Changing credentials during runtime

Introduction


As this chapter focuses on basic visual programming tools, it is a good place to have a quick look at how the programming of workflows works.

A workflow is made up of several sections. This chapter's focus will be on the creation of new workflows. We will work with the general, inputs, outputs, schemas, and presentation.

Variables (general, inputs, and outputs)

Each workflow can have variables in three different areas. Variables are called attributes or parameters depending on where they are.

In JavaScript, the naming convention for variables is to start with lowercase and use uppercase when a new word starts, for example, myFirstAttribute, currentVM, and so on. This is what programmers call a camelCase convention. We should use the same convention when programming in Orchestrator.

Variables in the general section

A variable in the General section is called an attribute. An attribute is accessible throughout the whole workflow, but, not outside it. An attribute can have an initial...

Scripting with logs


In this recipe, we will look into how logging works in scripting. You will learn how to create log entries and where they are stored.

Getting ready

We just need a working Orchestrator, and you will need the rights to create new workflows and run them. We will work with the Orchestrator Client.

Additionally, we need administrative (root) access to the Orchestrator's operating system.

How to do it...

We will split this recipe into two sections, Creating logs and Checking the log files.

Creating logs

We will now create log entries during a workflow:

  1. Create a new workflow.

  2. Drag all log elements from the Log section into the workflow and arrange them as shown here:

  3. Create the following variables:

    Name

    Type

    Section

    Binds with

    logText

    String

    IN

    Transports error text

    logObject

    String

    IN

    Transports object text

  4. Bind each log element with the required in-parameter.

  5. Save and exit the workflow.

  6. Run the workflow and enter two different phrases, such as LogText and LogObject...

Scripting with decisions


In this workflow, we will see how decisions can be implemented into scripts. You will learn how to create basic and custom decisions.

Getting ready

We just need a working Orchestrator, and you will need the rights to create new workflows and run them. We will work with the Orchestrator Client.

We need a new workflow where we can add a decision. You also should know how to work with logs.

For the Decision activity element, we will be using the example workflow 00.00 BasicWorkflow, which is stored in the Basic Helper folder.

How to do it...

There are three decisions that can be used in Orchestrator; we will discuss them in the following sections.

Basic decision

The Basic decision lets you check a single variable against a condition. A condition is always something that is either true or false. For example, the condition 5 > 3 is true, whereas the condition Team contains i  is false.

  1. Create a new workflow and define an in-parameter of the String type.

  2. Assemble the structure...

Error handling in workflows


This recipe is dedicated to showing how to handle errors in workflows. We will learn how to catch errors and redirect them.

Getting ready

We just need a working Orchestrator, and you will need the rights to create new workflows and run them. We will work with the Orchestrator Client.

How to do it...

  1. Create a new workflow. We will reuse this workflow in the recipe, Resuming failed workflows in Chapter 4, Programming Skills.

  2. Add the following variables:

    Name

    Type

    Section

    Use

    number

    Number

    IN

    Used to create an intentional error

  3. Assemble the workflow (as seen in the following screenshot) by dragging a Scriptable task into the workflow and then a Throw exception element from the generic section onto the Scriptable task. Add the two log elements to the workflow by just dropping them onto the lines:

  4. Bind the in-parameter to the scriptable task and add the following script, which will throw an error when the value 5 is entered:

          if (number==5) { 
...

Scripting with loops


Here, we will explore how to create loops in scripts. You will learn how to build loops and use them.

Getting ready

We just need a working Orchestrator, and you will need the rights to create new workflows and run them. We will work with the Orchestrator Client.

You need to understand how decisions are used in Orchestrator; this was explained in the recipe Scripting with decisions.

For the Foreach element, we will be using the example workflow 00.00 BasicWorkflow, which is stored in the Basic Helper folder.

How to do it...

There are several types of loop one can create; however, they can all be reduced to the following two basic types.

The decision loop

This basic kind of loop runs until a certain condition is met. We will build a so-called for loop in this example. A discussion about the different types of decision loops (for, do-while, and while-do) can be found in the How it works... section of this recipe.

  1. Create a new workflow and build the preceding schema.

  2. Add the following...

Workflow presentations


In this recipe, you will learn how to configure the input window (the presentation) and make it not only more user-friendly, but also reduce the amount of errors a user can enter. You will learn how to link values, hide inputs on conditions, and use predefined answers.

Getting ready

We just need a working Orchestrator, and you will need the rights to create new workflows and run them. We will work with the Orchestrator Client.

How to do it...

We will split this recipe into several sections. We will only create a presentation, not a working workflow.

Preparation

This preparation is just so that we can see some results:

  1. Create a new workflow using the following variables:

    Linking actions in presentations


    This recipe will show how to further improve and automate presentations in workflows by linking actions into them. This is done to present to the user only a specific list of options derived on runtime.

    Getting ready

    We will create a new workflow and reuse the action getElementFromArray, which we created in the recipe Creating actions in Chapter 6, Advanced Programming (see the com.packtpub.Orchestrator-Cookbook2ndEdition module in the example pack).

    You should be familiar with the topics we introduced in the recipe Workflow presentations in this chapter.

    How to do it...

    1. Using the Orchestrator Client, create a new workflow.

    2. Create the following variables:

    Name

    Type

    Section

    Use

    number

    Number

    IN

    This is used for presentations

    string

    String

    IN

    This is used for presentations

    boolYesNo

    Boolean

    IN

    This is used for presentations

    input

    Array of Strings

    IN

    This is used for presentations

    text

    String

    IN

    This is used for presentations

    ...

    Name

    Type

    Section

    Use

    string

    String

    IN

    This is a placeholder for the linked action

    number

    Number

    IN

    This is used to select a value from an array

    array

    Array of string

    Attribute

    This can take values such as Mon, Tue, Wed, Thu, Fri, Sat, Sun

  2. Create a log element and bind all variables...

Changing credentials during runtime


This recipe will show you how to use the Change credential element to change the user who is currently executing the workflow.

Getting ready

We need to create a new workflow.

For this recipe, you will need to have more than one AD/LDAP group configured to have access to Orchestrator. Remember that you can use the Orchestrator internal LDAP to test this. To facilitate this, please follow the User management recipe in Chapter 7, Interacting with Orchestrator.

How to do it...

  1. Create a new workflow with the following variable:

    Name

    Type

    Section

    Use

    newCredential

    Credential

    IN

    The user name and password of the new user

  2. Drag a Change credential element onto the schema.

  3. Bind the newCredential in-parameter to the Change credential element.

  4. Now, drag one System log element before and one after the Change credential element.

  5. Edit the System log elements. Remove the text input and change the log to workflow.runningUserName. This will log the username that...

lock icon The rest of the chapter is locked
You have been reading a chapter from
VMware vRealize Orchestrator Cookbook. - Second Edition
Published in: Nov 2016 Publisher: Packt ISBN-13: 9781786462787
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}