Skip to content

Workflows as catalog items

Recipe 8.5 had VCF Automation call Orchestrator in the middle of its own work. The other way round is just as useful: put an Orchestrator workflow straight into the VCF Automation catalog, next to the cloud templates, so users order it the same way they order anything else. Anything a workflow can do becomes a self-service item with VCF Automation’s projects, sharing, approvals, and history around it: a VM built your way, a DNS record, a firewall request, a password reset.

The workflow from recipe 8.2 isn’t ready for that as it is. Its inputs are vCenter objects, and a user ordering a VM shouldn’t have to pick a cluster and a datastore. So you first build Order a VM, a thin wrapper with three plain inputs that fills in the rest from a configuration element. Then you import it into a VM Apps organization, share it with the vcfguide project, give it a proper form, and order it.

Getting ready

  • The VM Apps organization, the project vcfguide, and the Orchestrator integration vco01 from recipe 8.5.
  • The workflow Provision a VM from a template and the objects it uses (template, folder, cluster, datastore, customization specification) from recipe 8.2, and the action findVmByName from recipe 8.1.
  • A test user who is a member of the project vcfguide but not an administrator, to order the item.

How to do it

Build a catalog-friendly workflow

  1. In Orchestrator, create the configuration element vcfguide-ch8-catalog in VCF Orchestrator Guide/Chapter 8, with five variables, and pick each value as in recipe 8.2:
Name Type Value
template VC:VirtualMachine tpl-linux-01
folder VC:VmFolder vcfguide
cluster VC:ClusterComputeResource your lab cluster
datastore VC:Datastore your lab datastore
specName string vcfguide-linux
  1. Create the action checkVmName in com.vcfguide.chapter8, with the input vmName (string) and the return type string. It returns an empty string when the name is fine, and the reason when it isn’t:
com.vcfguide.chapter8/checkVmName
if (!vmName) {
return ""; // the form's required check handles an empty field
}
if (!/^vcfguide-[a-z0-9-]{1,20}$/.test(vmName)) {
return "Use vcfguide- followed by up to 20 lower-case letters, digits or hyphens.";
}
try {
System.getModule("com.vcfguide.chapter8").findVmByName(vmName);
return "A VM called " + vmName + " already exists.";
} catch (e) {
return ""; // not found, so the name is free
}
  1. Create the workflow Order a VM in VCF Orchestrator Guide/Chapter 8, with the inputs vmName, size, and reason, all string, and the outputs ipAddress and summary, both string.
  2. On Variables, add template, folder, cluster, datastore, and specName, each bound to the variable of the same name in vcfguide-ch8-catalog, as in recipe 4.7. Add cpus and memoryMb (number) and vm (VC:VirtualMachine).
  3. On the schema, add a scriptable task Check the order, with vmName and size in and cpus and memoryMb out:
Order a VM — Check the order
var problem = System.getModule("com.vcfguide.chapter8").checkVmName(vmName);
if (!vmName || problem) {
throw "Can't build " + vmName + ": " + (problem || "no name given");
}
var sizes = {
small: { cpus: 1, memoryMb: 2048 },
medium: { cpus: 2, memoryMb: 4096 }
};
if (!sizes.hasOwnProperty(size)) {
throw "Unknown size " + size + ". Use small or medium.";
}
cpus = sizes[size].cpus;
memoryMb = sizes[size].memoryMb;
var context = System.getContext();
System.log("Order for " + vmName + " (" + size + ") by " +
(context.getParameter("__metadata_userName") || Server.getRunningUser()));
  1. After it, drag the workflow Provision a VM from a template onto the schema. Bind template, folder, cluster, datastore, specName, cpus, and memoryMb to the variables, vmName to the input, and its outputs to vm and ipAddress.
  2. Add a last scriptable task Summarize, with vm, ipAddress, size, and reason in and summary out:
Order a VM — Summarize
summary = vm.name + " is ready at " + ipAddress + " (" + size + "). Reason: " + reason;
System.log(summary);
  1. Run Order a VM once from the Orchestrator Client with vcfguide-cat-web-01, small, and Catalog test, to know it works before VCF Automation is involved. Run it again with the same name: it fails in Check the order with A VM called vcfguide-cat-web-01 already exists. Delete the VM.

Import it into VCF Automation

  1. In the VM Apps organization, go to Content & Policies > Content Sources and click New. Choose the type VCF Operations Orchestrator workflows.
  2. Enter the Name VCF Orchestrator Guide, select the integration vco01, click Add, find Order a VM, and add it. Click Create & Import. The source shows one item imported.
  3. Go to Content & Policies > Policies, click New Policy, and choose Content Sharing. Name it vcfguide catalog, set its scope to the project vcfguide, add the content source VCF Orchestrator Guide, and add the users or groups who may order from it. Click Create.
Figure 8.15. The workflow imported as a content source and shared with a project.
Needs a lab check. On VCF Automation 9.1 (VM Apps organization), record the menu names (Content & Policies, Content Sources, Policies), the exact content source type name, the button labels in steps 10 and 11, and whether a content sharing policy can share a whole content source or only items.

Give it a form

  1. Go to Content & Policies > Content, open the menu next to Order a VM, and choose Customize form. The designer shows one field for each workflow input, plus the request’s own fields, such as the project and the deployment name.
  2. Select vmName. On Appearance, set the label to VM name. On Values, set the default to vcfguide-. On Constraints, make it required and set Regular expression to ^vcfguide-[a-z0-9-]{1,20}$, with the message Use vcfguide- followed by lower-case letters, digits or hyphens.
  3. Select size, change its display type to Drop-down, and on Values set Value options to a constant list: small with the label Small: 1 vCPU, 2 GB, and medium with the label Medium: 2 vCPU, 4 GB. Set the default to small.
  4. Select reason, change it to a Text area, and make it required.
  5. Add an external validation: on the form’s Validation settings, choose the action com.vcfguide.chapter8/checkVmName, bind its input vmName to the field vmName, and point the message at that field. Now a user who picks a name that’s taken is told so before the request is sent.
  6. Turn the form on and click Save.
Figure 8.16. The custom form for Order a VM.
Needs a lab check. On VCF Automation 9.1, confirm the custom form designer’s tab names (Appearance, Values, Constraints), the drop-down value options, and how external validation is set up: where it lives, that an action returning a non-empty string blocks the request with that message, and how the action’s input is bound to a field.

Order it

  1. Log in as the test user, go to Consume > Catalog, and click Request on Order a VM. Pick the project vcfguide, enter a deployment name such as web for the demo, the VM name vcfguide-cat-web-02, the size Medium, and a reason. Click Submit.
  2. Under Consume > Deployments, the new deployment shows the request In progress, then Successful. Its history shows the workflow’s run.
  3. On vco01, Activity > Workflow Runs shows the run of Order a VM, with the nested Provision a VM from a template. The log of Check the order names the test user who ordered it.
  4. Delete the VM vcfguide-cat-web-02 in vCenter, then the deployment in VCF Automation.
Figure 8.17. Ordering the workflow from the catalog, and the run it starts.
Needs a lab check. Walk steps 18 to 21 on VCF Automation 9.1. Record whether a workflow request asks for a deployment name, what the deployment shows (status, history, the workflow’s outputs ipAddress and summary), which account the run on vco01 is started as, whether __metadata_userName is set for catalog requests, and whether deleting the deployment does anything to the VM.

How it works

A content source is a pointer. The content source doesn’t copy the workflow. It records the workflow’s ID and the integration it lives on, and reads the workflow’s inputs to build the item. When the user submits a request, VCF Automation starts the workflow on vco01 through the integration, passes the form’s values as inputs, and follows the run until it ends. A change to the workflow’s script is live at once. A change to its inputs needs the content source to import again, so the item’s form matches.

Sharing decides who sees it. An item exists in the organization once it’s imported, but nobody can order it until a content sharing policy puts it in a project’s catalog for a set of users. The same item can be shared with several projects, each with its own policy.

Plain inputs make good items. The catalog form can show vCenter objects as pickers, but those ask a user to understand your infrastructure and let them choose anything the integration’s account can see. A wrapper with plain inputs keeps those decisions in Orchestrator: the configuration element says where VMs go, and the size names hide the numbers. The form decides what the user sees, and the workflow checks it again, because forms can be bypassed through the API.

One check, used twice. checkVmName runs as the form’s external validation, so the user hears about a taken name while filling in the form, and again in Check the order, so a request through the API gets the same answer. The action returns a message instead of throwing, which is what form validation needs, and the workflow turns a message into an error.

Back in vRO 5.5–7In vRealize Automation 7, publish a workflow as an XaaS blueprint in the design tab, edit its form in the XaaS form designer, and entitle it to a business group in an entitlement.
In Orchestrator 9.xIn a VM Apps organization, import workflows with a VCF Operations Orchestrator workflows content source, share them with a project by a content sharing policy, and design the request in the custom form designer.

There's more

Approvals for catalog items. An item like Order a VM is where VCF Automation’s approval policies belong, as recipe 8.3 explains. A policy can require approval for this item in this project, and the workflow only starts once someone approves. The Orchestrator workflow doesn’t need to know.

Drop-downs from Orchestrator. Instead of a constant list, a drop-down’s values can come from an action, such as listTemplates in recipe 8.2 changed to return names. Keep such actions fast and give them defaults for every input they read, because the form calls them while it loads and while the user types. A field bound to another field may be empty when the form opens, so check for null and return an empty list rather than failing.

Read the request in the workflow. Context parameters such as __metadata_userName, __metadata_projectId, and __metadata_deploymentId tell the workflow who ordered it and where it belongs, as in recipe 8.5. Use them for naming, for tags, or to mail the requester.

Day 2 actions. A workflow item creates a deployment, but no resource VCF Automation manages, so the deployment offers no actions on the VM it built. To let users power, resize, or delete what a workflow created, make it a custom resource with resource actions, which a later recipe in this chapter covers, or put the VM in a cloud template and use the workflow as a subscription instead.

Catalog items in All Apps organizations. All Apps organizations build catalog items from blueprints, and a blueprint can include Orchestrator workflows through the organization’s Orchestrator integration. The workflow side is the same: plain inputs, its own checks, and context parameters for the request.

See also