Overview
In this how to, we will cover off each of the Template Tester elements and what they mean followed by an example of using your own template engine code in an if statement with information that is gathered from an SVL_ property group.
Considerations
- Have SovLabs module/s installed
- Have template engine code ready you want to test.
- SovLabs Property Toolkit if you plan on using the vRA Property Group (SVL_ ) for testing
Procedure
Accessing the template tester
- From vRA click on Catalog (1) and search for Template (2). Under SovLabs Template Tester - SovLabs Modules, click on Request (3)
Template Tester Explained - General Tab
This section covers the General template engine testing
- The Select a type to show a default template is a good starting point if you need help. From here you can either leave it as <none> or select from a few different baked in examples. I will for this example select if/else
- The Template area is where you would enter your template engine code you want to test. If you selected on of the defaults you will see an example here. You can delete the example and put your code here instead. Below is an example of the if/else code
- Placing a check next to the Get Properties from VM? (1) allows you to use a deployed VM to populate the Properties JSON Area. Once you check this there are multiple different filters available to select your VM
Max # of VMs and Business Groups: (2) (Default is 5, most of the time you won't need to change this unless you have more than 5 business groups you want to select)
Business Group filter: (3) You can type in text here to filter out business groups in the list
vRA Business Groups: (4) Lists out your business groups, generally you would be selecting a single business group to capture information from a VM
Hostname filter: (5) You can enter text here to limit the list of VMs in the list
Select VM: (6) This is where you can select the VM you want to capture the JSON Payload information from - The Properties JSON will auto populate IF you have selected all the above Get properties from VM? If you did not select this filter, skip to 5 for further information on this section
- If you have selected a default template from the list, the JSON values will be presented here. If you have entered your own template engine code, then this is where you would enter value pairs that match your code. Below is the example JSON information for the if/else default template
- SovLabs Template Engine Result Output is where you will see what your code produces based on the Template and the Properties JSON. In the if/else example, we expect the output of testVal to be abcdef.
- If you have property toolkit and you want to test against an SVL_ property group, click on next at the bottom left corner of your screen and continue onto the next section of this document.
Template Tester Explained - vRA Property Group Tab
This section cover the vRA Property Group section (for users of property toolkit)
- Max # of Property Groups to get: (1) By default it is 5, but if you have lots of SVL_ property groups you may want to increase this number. The following filters may mean you don't need to change this number
Name Filter: (2) if you know what your SVL_ property group is called or part of it you can type in text to filter the selection
SovLabs Dynamic Property Group: (3) you can select your SVL_ property group from this list
Property Group Properties: (4) this is the paired values captured from your SLV_ property group - Rendered Output (includes Property Group Properties) : Rendered Property Group: This is the properties that are rendered from your SVL_ property group
- Template: This is the template code you either entered in the General tab. In this example it is still the if/else default template code
- Properties JSON merged with Property Group: This is the paired values from the general tab along with the paired values from your SVL_ property group merged into a single JSON
- Output: This is the output of the template engine code along with the merged JSON pair values. In this example, since we did not add in any template code that gets the value of TemplateTester:Testing. It simply provides the value of testVal which is abcdef
- Once you have done all your testing and a satisfied with your results you can click submit or cancel to exit the template tester
Template Tester Simple Example with vRA Property Group
This example will be around an if statement of if a certain name has a certain value then give us a certain output. You do not need to use the vRA property group if you just add the value into the Property JSON.
We will then use the vRA Property Group to capture additional information for the output:
The Template code we will use is as follows:
{% if MyValue == 'true' %}{{TemplateTester}}{% else %}No Template Tester{% endif %}
- Enter the code above into the Template section
- In the Properties JSON we will add the value for MyValue and set it to true. Based on this information, I would not expect any output as we have not defined what {{TemplateTester}} is. If you set this to false the expectation is that it will display "No Template Tester".
- Myvalue = true
Output: - MyValue = false
Output:
- Myvalue = true
- Before we click on Next, let us set MyValue to true so there is no output at the moment and we can test this against my SVL_ property group that contains the information for TemplateTester. Click on Next
- I have left the default max # of property groups to get and the Name filter is Blank. I have select my SVL_ property group from the drop down. Mine is called SVL_TemplateTester. You will see the Property Group Properties contains a value pair of TemplateTester: Testing
- Now that we have the Template captured. And we had set our initial MyValue to true. We should see the JSON add in the TemplateTester value pair and the output should be this new value
- If you change the MyValue in the Properties JSON merged with Property Group to false, the Output should change to "No Template Tester"
- You can now submit or Cancel to exit the template tester.
Additional information
SovLabs Template Tester : http://docs.sovlabs.com/latest/vmware-vra7x-plugin/framework/sovlabs-template-engine/basics/sovlabs-template-tester/
SovLabs Property Toolkit : http://docs.sovlabs.com/latest/vmware-vra7x-plugin/modules/vra-toolkits/property-toolkit/
0 Comments