Setup workflows
The decommissioning solution from recipe 9.1 reads two settings from the configuration element VCFG_Decommission: a VM folder and a number of days. On your lab Orchestrator you typed them in by hand. On the next Orchestrator, whoever installs the package would have to know which element to open, which fields matter, and what’s a sensible value. VMware’s Coding Design Guide says: give them a configuration workflow instead, so that setting up a solution is one run with a form.
This recipe writes that workflow, and explains why the element itself must come in the package, empty, rather than be created by the workflow.
Getting ready
- The decommissioning solution from recipe 9.1, with the configuration element
VCFG_Decommissionin VCFG/VM. - Recipe 4.7 (configuration elements).
How to do it
Write the setup workflow
- In VCF Orchestrator Guide/Chapter 9/05 Utilities, create the workflow VCFG - VM - Configure Decommissioning, with the inputs
retireFolder(VC:VmFolder) andgraceDays(number, default7), and the outputsummary(string). Its description says what it’s for and when to run it:
Sets up the VM decommissioning solution on this Orchestrator after its packageis imported: writes the retire folder and grace period into the configurationelement VCFG/VM/VCFG_Decommission, then reads them back. Safe to run again tochange the values. Fails if the element is missing: import the package first.- Add a scriptable task,
Check inputs, that refuses values the solution can’t use. A grace period of 0 would delete VMs on the next scheduled run, before anyone could object:
if (!retireFolder) { throw "[VCFG][Configure Decommissioning] retireFolder is required";}if (!(graceDays >= 1 && graceDays <= 90)) { throw "[VCFG][Configure Decommissioning] graceDays must be 1 to 90, got: " + graceDays;}- Add a second scriptable task,
Save settings. It finds the element by folder and name, writes both values, and reads them back intosummary:
// The element comes with the package, so its ID, and every binding to it, stay the same.// This workflow only changes its values.var path = "VCFG/VM";var name = "VCFG_Decommission";var category = Server.getConfigurationElementCategoryWithPath(path);var element = null;if (category) { var elements = category.allConfigurationElements; for (var i = 0; i < elements.length; i++) { if (elements[i].name === name) { element = elements[i]; } }}if (!element) { throw "[VCFG][Configure Decommissioning] " + path + "/" + name + " not found: import the package first";}
var oldFolder = element.getAttributeWithKey("retireFolder").value;var oldDays = element.getAttributeWithKey("graceDays").value;element.setAttributeWithKey("retireFolder", retireFolder);element.setAttributeWithKey("graceDays", graceDays);
summary = "retireFolder: " + (oldFolder ? oldFolder.name : "(empty)") + " -> " + element.getAttributeWithKey("retireFolder").value.name + ", graceDays: " + oldDays + " -> " + element.getAttributeWithKey("graceDays").value;System.log("[VCFG][Configure Decommissioning] " + summary);- Give the form a folder picker for
retireFolderand a number field forgraceDays, with the help text Days a retired VM is kept before it is deleted (1 to 90).
Run it
- Run it with
graceDays=0. It fails inCheck inputs, and the element doesn’t change. - Run it with the folder
vcfguide-retiredandgraceDays=10. The output readsretireFolder: vcfguide-retired -> vcfguide-retired, graceDays: 7 -> 10. Run VCFG - VM - Delete Retired VMs: it now keeps VMs for ten days, without any change to it. - Run the setup workflow again with
7to put the value back.
Run form of VCFG - VM - Configure Decommissioning, with the VM folder picker showing vcfguide-retired and graceDays = 7 with its help text.
setAttributeWithKey(key, value) without a type updates an existing attribute. Exported with values, a VC:VmFolder is stored with its own vCenter’s ID, such as group-v2276.How it works
Bindings follow the ID, not the name. When you bind a workflow variable to a configuration element (recipe 4.7), the workflow stores the element’s ID. A package keeps that ID, so the element imported on the next Orchestrator is the one the workflows are already bound to. A setup workflow that created the element there would give it a new ID, and every binding would point at nothing. So the element travels in the package, and the setup workflow only fills it in.
Values belong to a server. A VC:VmFolder is stored as a vCenter host name and a managed object ID such as group-v2276. On another vCenter that ID is a different folder, or none. Export the solution’s package without configuration values (recipe 9.5), and let the setup workflow pick the folder from the inventory of the Orchestrator it runs on.
Setup is code, so it’s checked like code. A person editing the element by hand can type 0, or pick the wrong folder, and nothing complains until the scheduled delete runs. The setup workflow checks the values once, logs what changed, and can be run again by anyone, so a new environment is set up the same way as the last one.
One element per solution, not per environment. The naming standard (recipe 9.3) allows an environment suffix, <CODE>_<System>_<Env>. Use it when one Orchestrator talks to several environments of a system and a script picks the element by name at run time, such as VCFG_CMDB_Test and VCFG_CMDB_Prod. An element that’s bound to workflows and has different values on each Orchestrator, like this one, has no suffix: the same element is in every environment, filled in differently.
There's more
Hosts and accounts. The guide’s examples go further: a setup workflow that adds a REST host with its operations, or the account a solution uses. Use the library workflows for that (Add a REST host, recipe 5.2; Add a vCenter Server instance, recipe 1.9), called from your setup workflow with your values, rather than rebuilding them in a script. Put passwords in SecureString inputs, store them in the element as SecureString attributes, and never log them.
Accounts whose passwords change. The guide warns about service accounts whose passwords rotate, every 45 days on some directories, and solutions that stop working when they do. Make the same setup workflow the way to change the password, so that rotating it is one run, and the integration check in recipe 9.6 tells you if anything still uses the old one.
See also
- 4.7 Configuration elements.
- 9.5 Packaging by use case, for exporting without values.
- 9.6 Testing workflows and actions, to check a new installation.
- VMware: vRealize Orchestrator Coding Design Guide, technical white paper, March 2016 (section Configuration Workflow).
