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 integrationvco01from 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
findVmByNamefrom recipe 8.1. - A test user who is a member of the project
vcfguidebut not an administrator, to order the item.
How to do it
Build a catalog-friendly workflow
- In Orchestrator, create the configuration element
vcfguide-ch8-catalogin 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 |
- Create the action
checkVmNameincom.vcfguide.chapter8, with the inputvmName(string) and the return typestring. It returns an empty string when the name is fine, and the reason when it isn’t:
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}- Create the workflow Order a VM in VCF Orchestrator Guide/Chapter 8, with the inputs
vmName,size, andreason, allstring, and the outputsipAddressandsummary, bothstring. - On Variables, add
template,folder,cluster,datastore, andspecName, each bound to the variable of the same name invcfguide-ch8-catalog, as in recipe 4.7. AddcpusandmemoryMb(number) andvm(VC:VirtualMachine). - On the schema, add a scriptable task
Check the order, withvmNameandsizein andcpusandmemoryMbout:
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()));- After it, drag the workflow Provision a VM from a template onto the schema. Bind
template,folder,cluster,datastore,specName,cpus, andmemoryMbto the variables,vmNameto the input, and its outputs tovmandipAddress. - Add a last scriptable task
Summarize, withvm,ipAddress,size, andreasonin andsummaryout:
summary = vm.name + " is ready at " + ipAddress + " (" + size + "). Reason: " + reason;System.log(summary);- Run Order a VM once from the Orchestrator Client with
vcfguide-cat-web-01,small, andCatalog 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
- In the VM Apps organization, go to Content & Policies > Content Sources and click New. Choose the type VCF Operations Orchestrator workflows.
- Enter the Name
VCF Orchestrator Guide, select the integrationvco01, click Add, find Order a VM, and add it. Click Create & Import. The source shows one item imported. - Go to Content & Policies > Policies, click New Policy, and choose Content Sharing. Name it
vcfguide catalog, set its scope to the projectvcfguide, add the content sourceVCF Orchestrator Guide, and add the users or groups who may order from it. Click Create.
VM Apps organization, Content & Policies > Content Sources, source VCF Orchestrator Guide of type VCF Operations Orchestrator workflows, integration vco01, 1 item imported (Order a VM); inset: Policies, content sharing policy vcfguide catalog scoped to project vcfguide.
Give it a form
- 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.
- Select
vmName. On Appearance, set the label toVM name. On Values, set the default tovcfguide-. 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. - Select
size, change its display type to Drop-down, and on Values set Value options to a constant list:smallwith the labelSmall: 1 vCPU, 2 GB, andmediumwith the labelMedium: 2 vCPU, 4 GB. Set the default tosmall. - Select
reason, change it to a Text area, and make it required. - Add an external validation: on the form’s Validation settings, choose the action
com.vcfguide.chapter8/checkVmName, bind its inputvmNameto the fieldvmName, 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. - Turn the form on and click Save.
Custom form designer for Order a VM: canvas with VM name, Size drop-down showing both labels, Reason text area; properties pane of VM name on Constraints with the regular expression; external validation set to checkVmName; form enabled.
Order it
- 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 asweb for the demo, the VM namevcfguide-cat-web-02, the size Medium, and a reason. Click Submit. - Under Consume > Deployments, the new deployment shows the request In progress, then Successful. Its history shows the workflow’s run.
- 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. - Delete the VM
vcfguide-cat-web-02in vCenter, then the deployment in VCF Automation.
As the test user, Consume > Catalog with Order a VM next to cloud templates; request form filled (VM name vcfguide-cat-web-02, Size Medium, reason); beside it the deployment web for the demo Successful, and on vco01 the completed run with the log line naming the user.
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.
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
- 3.6 Input forms, for Orchestrator’s own forms, which the catalog form replaces for catalog users.
- 4.7 Configuration elements in code, for binding variables to a configuration element.
- 8.2 Provisioning a VM from a template, the workflow this one wraps.
- 8.3 An approval process for provisioning, for approvals in Orchestrator and in VCF Automation.
- 8.5 Extensibility subscriptions, for the integration
vco01and context parameters. - Pranay Jha, Publishing catalog items with Automation Service Broker in VCF Automation (VCF Automation 9 series, part 14), for content sources and content sharing in a VM Apps organization.
- VMware blog: Good practices for developing custom forms with VMware Cloud Foundation Automation.
- Broadcom KB 383399: reading deployment data in an Orchestrator workflow.
