- About Custom Workflow Inputs
- Prerequisites
- Creating a Custom Workflow Input
- Cloning a Custom Workflow Input
- Creating a Custom Task
- Importing Workflows, Custom Tasks, Script Modules, and Activities
- Exporting Workflows, Custom Tasks, Script Modules, and Activities
- Cloning a Custom Workflow Task from the Task Library
- Cloning a Custom Workflow Task
- Controlling Custom Workflow Task Inputs
- Example: Using Controllers
- Example: Creating and Running a Custom Task
Creating Custom Workflow Tasks
- About Custom Workflow Inputs
- Prerequisites
- Creating a Custom Workflow Input
- Cloning a Custom Workflow Input
- Creating a Custom Task
- Importing Workflows, Custom Tasks, Script Modules, and Activities
- Exporting Workflows, Custom Tasks, Script Modules, and Activities
- Cloning a Custom Workflow Task from the Task Library
- Cloning a Custom Workflow Task
- Controlling Custom Workflow Task Inputs
- Example: Using Controllers
- Example: Creating and Running a Custom Task
About Custom Workflow Inputs
Cisco UCS Director Orchestrator offers a list of well-defined input types for custom tasks. You can use the input type list to define the input for custom workflow tasks. Cisco UCS Director also enables you to create a customized workflow input for a custom workflow task. You can create a new input type by cloning and modifying an existing input type.
Prerequisites
Before writing custom tasks, you must meet the following prerequisites:
-
Cisco UCS Director is installed and running on your system. For more information about how to install Cisco UCS Director, refer to the Cisco UCS Director Installation and Configuration Guide.
-
You have a login with administrator privileges. You must use this login when you create and modify custom tasks.
Creating a Custom Workflow Input
You can create a custom input for a custom workflow task. The created input is displayed in the list of input types that you can map to custom task inputs when the custom workflow task is created.
Cloning a Custom Workflow Input
You can use an existing custom workflow input in Cisco UCS Director to create a custom workflow input.
A custom workflow input must be available in Cisco UCS Director.
Step 1 | On the menu bar, choose . |
Step 2 | Choose the Custom Workflow Inputs tab. |
Step 3 | Choose the custom workflow input that needs to be cloned. The Clone icon appears at the top of the custom workflow inputs table. |
Step 4 | Click the Clone icon. |
Step 5 | In the Custom Input Type Name field, type a name for the new input. |
Step 6 | Use the other controls in the Clone Custom Workflow Input dialog box to customize the new input. |
Step 7 | Click Submit. The custom workflow task input is cloned after confirmation and is available for use in the custom workflow task. |
Creating a Custom Task
To create a custom task, do the following:
Step 1 | On the menu bar, choose . | ||||||||||||||||||||||||||||||||||||||||||||||||
Step 2 | Choose the Custom Workflow Tasks tab. | ||||||||||||||||||||||||||||||||||||||||||||||||
Step 3 | Click the Add icon. | ||||||||||||||||||||||||||||||||||||||||||||||||
Step 4 | In the
Add
Custom Workflow Task dialog box, complete the following fields:
| ||||||||||||||||||||||||||||||||||||||||||||||||
Step 5 | Click Next. The Custom Workflow Tasks Inputs window appears. | ||||||||||||||||||||||||||||||||||||||||||||||||
Step 6 | Click the Add icon. | ||||||||||||||||||||||||||||||||||||||||||||||||
Step 7 | In the
Add
Entry to Inputs dialog box, complete the following fields:
| ||||||||||||||||||||||||||||||||||||||||||||||||
Step 8 | Click Submit. A successful entry addition message appears. | ||||||||||||||||||||||||||||||||||||||||||||||||
Step 9 | Click OK. | ||||||||||||||||||||||||||||||||||||||||||||||||
Step 10 | Click the Add icon to add more entry to inputs. | ||||||||||||||||||||||||||||||||||||||||||||||||
Step 11 | Click Next. The Custom Workflow Tasks Outputs window appears. | ||||||||||||||||||||||||||||||||||||||||||||||||
Step 12 | Click the Add icon. | ||||||||||||||||||||||||||||||||||||||||||||||||
Step 13 | In the
Add
Entry to Outputs dialog box, complete the following fields:
| ||||||||||||||||||||||||||||||||||||||||||||||||
Step 14 | Click Submit. A successful entry addition message appears. | ||||||||||||||||||||||||||||||||||||||||||||||||
Step 15 | Click OK. | ||||||||||||||||||||||||||||||||||||||||||||||||
Step 16 | Click the Add icon to add more entry to outputs. | ||||||||||||||||||||||||||||||||||||||||||||||||
Step 17 | Click Next The Controller window appears. | ||||||||||||||||||||||||||||||||||||||||||||||||
Step 18 | (Optional) Click the Add icon to add a controller. | ||||||||||||||||||||||||||||||||||||||||||||||||
Step 19 | In the
Add
Entry to Controller dialog box, complete the following fields:
| ||||||||||||||||||||||||||||||||||||||||||||||||
Step 20 | Click Submit. A successful entry addition message appears. | ||||||||||||||||||||||||||||||||||||||||||||||||
Step 21 | Click Next. The Script window appears. | ||||||||||||||||||||||||||||||||||||||||||||||||
Step 22 | From the Execution Language drop-down list, choose the language. | ||||||||||||||||||||||||||||||||||||||||||||||||
Step 23 | In the Script field, enter the CloupiaScript code for the custom workflow task. | ||||||||||||||||||||||||||||||||||||||||||||||||
Step 24 | Click Save Script. | ||||||||||||||||||||||||||||||||||||||||||||||||
Step 25 | Click Submit. The custom workflow task is created and is available for use in the workflow. |
Importing Workflows, Custom Tasks, Script Modules, and Activities
To import artifacts into Cisco UCS Director, do the following:
Step 1 | On the menu bar, choose . | ||||||||||||||||
Step 2 | In the Orchestration pane, click the Workflows tab. | ||||||||||||||||
Step 3 | Click the Import action. | ||||||||||||||||
Step 4 | In the Import dialog box, click Upload. | ||||||||||||||||
Step 5 | In the File Upload dialog, click Click and select a file from your computer. | ||||||||||||||||
Step 6 | Select the import file. Cisco UCS Director import and export files have a .wfdx file extension. When the file is uploaded, the File Upload dialog displays File ready for use. | ||||||||||||||||
Step 7 | Dismiss the File Upload dialog. | ||||||||||||||||
Step 8 | Click Next. The Import dialog displays a list of Cisco UCS Director objects contained in the uploaded file. | ||||||||||||||||
Step 9 | (Optional)
Specify how objects are handled if they duplicate names already in the workflow
folder. In the
Import dialog box, complete the following fields:
| ||||||||||||||||
Step 10 | Click Import. |
Exporting Workflows, Custom Tasks, Script Modules, and Activities
Step 1 | On the menu bar, choose . | ||||||||
Step 2 | In the Orchestration pane, click the Workflows tab. | ||||||||
Step 3 | On the Workflows tab, click Export. | ||||||||
Step 4 | In the Select Workflows screen, select the workflows that you want to export. | ||||||||
Step 5 | Click Next. | ||||||||
Step 6 | In the Select Custom Tasks screen, select the custom tasks that you want to export. | ||||||||
Step 7 | Click Next. | ||||||||
Step 8 | In the Export: Select Script Modules screen, select the script modules that you want to export. | ||||||||
Step 9 | Click Next. | ||||||||
Step 10 | In the Export: Select Activities screen, select the activities that you want to export. | ||||||||
Step 11 | In the
Export:
Confirmation screen, complete the following fields:
| ||||||||
Step 12 | Click Export. |
You are prompted to save the file.
Cloning a Custom Workflow Task from the Task Library
You can clone tasks in the task library to use in creating custom tasks.
The cloned task is a framework with the same task inputs and outputs as the original task. However, note that the cloned task is a framework only. This means that you must write all the functionality for the new task in CloupiaScript.
Note also that selection values for list inputs, such as dropdown lists and lists of values, are carried over to the cloned task only if the list values are not system-dependent. Such things as names and IP addresses of existing systems are system-dependent; such things as configuration options supported by Cisco UCS Director are not. For example, user groups, cloud names, and port groups are system-dependent; user roles, cloud types, and port group types are not.
Step 1 | On the menu bar, choose . |
Step 2 | Choose the Custom Workflow Tasks tab. |
Step 3 | Click Clone From Task Library. |
Step 4 | In the Clone from Task Library dialog box, click Select. |
Step 5 | Choose a task from the task list. |
Step 6 | Click Select. A custom workflow task is created from the task library. The new custom task is the last custom task in the Custom Workflow Tasks report. The new custom task is named after the cloned task, with the date appended. |
What to Do Next
Edit the custom workflow task.
Cloning a Custom Workflow Task
You can use the existing custom workflow tasks in Cisco UCS Director to create a custom workflow task.
A custom workflow task must be available in Cisco UCS Director.
Step 1 | On the menu bar, choose . |
Step 2 | Choose the Custom Workflow Tasks tab. |
Step 3 | Choose the custom workflow task to clone. The Clone icon appears at the top of the custom workflow tasks table. |
Step 4 | Click the Clone icon. |
Step 5 | In the Clone Custom Workflow Task dialog box, update the required fields. |
Step 6 | Click Next. The inputs defined for the custom workflow tasks appear. |
Step 7 | Edit the task inputs. |
Step 8 | Click Next. Edit the task outputs. |
Step 9 | Click the Add icon to add a new output entry. |
Step 10 | Click Next. |
Step 11 | Edit the controller scripts. See the following topic, Controlling Custom Workflow Task Inputs. |
Step 12 | Click Next. |
Step 13 | To customize the custom task, edit the task script. |
Step 14 | Click Submit. |
Controlling Custom Workflow Task Inputs
Using Controllers
You can modify the appearance and behavior of custom task inputs using the controller interface available in Cisco UCS Director.
When to Use Controllers
-
Show or hide GUI controls: You can dynamically show or hide various GUI fields such as checkboxes, text boxes, drop-down lists, and buttons, based on conditions. For example, if a user selects UCSM from a drop-down list, you can prompt for user credentials for Cisco UCS Manager or change the list of values (LOVs) in the drop-down list to shown only available ports on a server.
-
Form field validation: You can validate the data entered by a user when creating or editing workflows in Workflow Designer. For invalid data entered by the user, errors can be shown. The user input data can be altered before it is persisted in the database or before it is persisted to a device.
-
Dynamically retrieve a list of values: You can dynamically fetch a list of values from Cisco UCS Director objects and use them to populate the GUI form objects.
Marshalling and Unmarshalling GUI Form Objects
Controllers are always associated with a form in the Workflow Designer's task inputs interface. There is a one-to-one mapping between a form and controller. Controllers work in two stages, marshalling and unmarshalling. Both stages have two substages, before and after. To use a controller, you marshall (control UI form fields) and/or unmarshall (validate user inputs) the related GUI form objects using the controller's scripts.
The following table summarizes these stages.
Stage |
Sub-stage |
---|---|
Marshalling — Used to hide and unhide form fields and for advanced control on LOVs and tabular LOVs. |
beforeMarshall — Used to add or set an input field and dynamically create and set the LOV on a page (form). afterMarshall — Used to hide or unhide an input field. |
Unmarshalling - Used for form user input validation. |
beforeUnmarshall — Used to convert an input value from one form to another form, for example, to encrypt the password before sending it to the database. afterUnmarshall — Used to validate a user input and set the error message on the page. |
Building Controller Scripts
Controllers do not require any additional packages to be imported.
You do not pass parameters to the controller methods. Instead, the Cisco UCS Director framework makes the following parameters available for use in marshalling and unmarshalling:
Parameter |
Description |
Example |
---|---|---|
Page |
The page or form that contains all the task inputs. You can use this parameter to do the following: |
page.setHidden(id + ".portList", true); page.setValue(id + ".status", "No Port is up. Port List is Hidden"); |
id |
The unique identifier of the form input field. An id is generated by the framework and can be used with the form input field name. |
page.setValue(id + ".status", "No Port is up. Port List is Hidden");// here ‘status’ is the name of the input field. |
Pojo |
POJO (plain old Java object) is a Java bean representing an input form. Every GUI page must have a corresponding POJO holding the values from the form. The POJO is used to persist the values to the database or to send the values to an external device. |
pojo.setLunSize(asciiValue); //set the value of the input field 'lunSize' |
See Example: Using Controllers for a working code sample that demonstrates the controller functionality.
Example: Using Controllers
The following code example demonstrates how to implement the controller functionality in custom workflow tasks using the various methods — beforeMarshall, afterMarshall, beforeUnmarshall and afterUnmarshall.
/* Method Descriptions: Before Marshall: Use this method to add or set an input field and dynamically create and set the LOV on a page(form). After Marshall: Use this method to hide or unhide an input field. Before UnMarshall: Use this method to convert an input value from one form to another form, for example, when you want to encrypt the password before sending it to the database. After UnMarshall: Use this method to validate a user input and set the error message on the page. */ //Before Marshall: /* Use the beforeMarshall method when there is a change in the input field or to dynamically create LOVs and to set the new input field on the form before it gets loaded. In the example below, a new input field 'portList' is added on the page before the form is displayed in a browser. */ importPackage(com.cloupia.model.cIM); importPackage(java.util); importPackage(java.lang); var portList = new ArrayList(); var lovLabel = "eth0"; var lovValue = "eth0"; var portListLOV = new Array(); portListLOV[0] = new FormLOVPair(lovLabel, lovValue);//create the lov input field //the parameter 'page' is used to set the input field on the form page.setEmbeddedLOVs(id + ".portList", portListLOV);// set the input field on the form ============================================================================================================= //After Marshall : /* Use this method to hide or unhide an input field. */ page.setHidden(id + ".portList", true); //hide the input field 'portList'. page.setValue(id + ".status", "No Port is up. Port List is Hidden"); page.setEditable(id + ".status", false); ============================================================================================================= //Before Unmarshall : /* Use the beforeUnMarshall method to read the user input and convert it to another form before inserting into the database. For example, you can read the password and store the password in the database after converting it into base64 encoding, or read the employee name and convert to the employee Id when the employee name is sent to the database. In the code example below the lun size is read and converted into an ASCII value. */ importPackage(org.apache.log4j); importPackage(java.lang); importPackage(java.util); var size = page.getValue(id + ".lunSize"); var logger = Logger.getLogger("my logger"); if(size != null){ logger.info("Size value "+size); if((new java.lang.String(size)).matches("\\d+")){ var byteValue = size.getBytes("US-ASCII"); //convert the lun size and get the ASCII character array var asciiValueBuilder = new StringBuilder(); for (var i = 0; i < byteValue.length; i++) { asciiValueBuilder.append(byteValue[i]); } var asciiValue = asciiValueBuilder.toString()+" - Ascii value" //id + ".lunSize" is the identifier of the input field page.setValue(id + ".lunSize",asciiValue); //the parameter 'page' is used to set the value on the input field . pojo.setLunSize(asciiValue); //set the value on the pojo. This pojo will be send to DB or external device. } } ============================================================================================================= // After unMarshall : /* Use this method to validate and set an error message. */ importPackage(org.apache.log4j); importPackage(java.lang); importPackage(java.util); //var size = pojo.getLunSize(); var size = page.getValue(id + ".lunSize"); var logger = Logger.getLogger("my logger"); logger.info("Size value "+size); if (size > 50) { //validate the size page.setError(id+".lunSize", "LUN Size can not be more than 50MB "); //set the error message on the page page.setPageMessage("LUN Size can not be more than 50MB"); //page.setPageStatus(2); }
Example: Creating and Running a Custom Task
Step 1 | Go to . |
Step 2 | Click Add and key in the custom task information. |
Step 3 | Click Next. The Cloupia Script Interpreter dialog box appears. |
Step 4 | Click+ and add the input details. |
Step 5 | Click Submit. |
Step 6 | Click Next. The custom task output window is displayed. |
Step 7 | Click Next. The custom task controller window is displayed. |
Step 8 | Click Next. The script window is displayed. |
Step 9 | Select
JavaScript as the execution language and enter the following script to execute.
logger.addInfo("Hello World!"); logger.addInfo("Message "+input.message);where message is the input field name. |
Step 10 | Click Submit. The custom task is defined and added to the custom tasks list. |
Step 11 | Go to Workflows tab. |
Step 12 | Click Add and add a workflow. |
Step 13 | Drag and drop the 'Hello world custom task' to the workflow designer once the workflow is created. |
Step 14 | Add 'Hello World custom task' to the designer. |
Step 15 | Click Validate workflow. |
Step 16 | Click Execute Now and click Submit. |
Step 17 | See the log messages in the Service Request log window. |