Panel | ||||
---|---|---|---|---|
|
Introduction
Dynamic Commands allow you to add supporting functionality to a task instance. In this chapter, we will enhance the ue-task Extension developed in the previous chapters by adding a Dynamic Command. The command we create will reset the task instance - to prepare it for a rerun scenario.
...
- Add Dynamic Command to the "UE Task" Universal Template.
- Add a backing implementation for Dynamic Command to the extension.py file in the ue-task Extension project.
- Rebuild and upload the modified Extension.
- Execute the Dynamic Command
Step 1 - Add a Dynamic Command to the "UE Task" Universal Template
Go back to the "UE Task" Universal Template form.
...
Note that the “Supported Status(es)” is set to: In Doubt, Cancelled, Failed, Finished, and Success. These are the task instance statuses where the command will be available for execution. For all other statuses the command will be greyed out.
Save the command.
Step 2 - Add Backing Implementation for Dynamic Command to extension.py
Open file ~/dev/extensions/sample-task/src/extension.py
in your editor of choice.
...
Note | ||
---|---|---|
| ||
The value supplied to the dynamic_command decorator must match the command Name of the associated Dynamic Command defined in the Controller's Universal Template (for example, @dynamic_command("reset_environment")). |
Step 3 - Build and Upload the Extension Zip Archive Using the UIP VS Code Extension
Save all changes to extension.py.
...
Expand | ||
---|---|---|
| ||
Step 3 Supplemental - Build and Upload the Extension Zip Archive Using the CLISave all changes to extension.py. From the command line, cd to the ~/dev/extensions/sample-task directory and execute the push command as shown below: Recall that the push command builds and uploads the Extension zip archive |
Step 4 - Execute Dynamic Command
In the Controller, open the "UE Task tasks" tab. If the tab is already open, it must be closed and reopened before the the new Dynamic Command will be available on the task instances.
...
The Step 1 and Step 2 Output Only fields have been set to Initial. This is a contrived example, but it demonstrates how a Dynamic Command could be used as a helper command for a task instance by performing some action on the target agent system (or beyond) and then updating the task instance in a meaningful way that may be required for a rerun scenario.
In this case, information flowed from the Dynamic Command execution back to the task instance fields. However, task specific information could also have been passed down to the Dynamic command.
Step 5 - Update the Local template.json
In step 1, we modified the Universal Template by adding a new Dynamic command. Recall that inside ~/dev/extensions/sample-task/src/templates, there is a template.json file. This file should correspond to the Universal Template in the Controller.
Right now, they are not both the same. The Controller's version of template.json has the Dynamic Choice Fields changes. To grab those changes, use the pull command as shown below:
UIP VS Code Extension
Expand | ||
---|---|---|
| ||
Step Supplemental - CLI |
Now, both the local and Controller's version of the Universal Template are the same.