Overview
In this how to, we will cover how to use the property toolkit using the SovLabs_createProperties_ method as a custom property.
This method allows you to define multiple properties as part of a single custom property on your blueprint and pass them through into your payload for use. Such uses could be for dynamic site selection, dynamic folder placement or even dynamic allocation in your naming just to name a few. Since this is on a single blueprint it means that these properties can not be re used against multiple blueprints unless you create the same custom property again.
There is a second method you can use which is to create a property definition and prefix it with SVL_ . The property definition would contain all the properties you wish to define with their values and you would dynamically select these different property definitions based on user selection. This also means creating multiple property definitions and maintaining these but this can be used against multiple blueprints easily.
Please search through our articles for this other methods example if you wish to learn more.
Considerations
- Have licensed the property toolkit
Scenario
You have a requirement to set additional attributes based on a user driven selection in the form of a drop down on the blueprint.
You have a property definition created with the following:
Definition name: My.RequestForm.Prop
Possible values:
Name | Value |
---|---|
A | A |
B | B |
C | C |
The properties that we want to set based on the selection from the drop down are as follows:
If My.RequestForm.Prop == A
Test.Prop.Foo1 == "A"
Test.Prop.Foo2 == "blah"
Test.Prop.Foo3 == "0"
Test.Prop.Foo4 == "trees"
Test.Prop.Foo5 == "prod"
if My.RequestForm.Prop == B
Test.Prop.Foo1 == "Z"
Test.Prop.Foo2 == "blahblah"
Test.Prop.Foo3 == "1"
Test.Prop.Foo4 == "flowers"
Test.Prop.Foo5 == "dev"
if My.RequestForm.Prop == C
Test.Prop.Foo1 == "Q"
Test.Prop.Foo2 == "blahblahblah"
Test.Prop.Foo3 == "2"
Test.Prop.Foo4 == "bees"
Test.Prop.Foo5 == "qa"
And if the value is none of these, set the values of Test.Prop.Foo1 → 5 to "UNKNOWN"
Template Engine
This template uses an array of name/value pairs. The name is the name of the VM property you want to set, and the value is a valid SovLabs Template Engine template. (See the SovLabs Template Engine article for more information)
In the example below, the Template Engine statement is a case statement which evaluates the value of My.RequestForm.Prop and outputs the desired string based on that value.
The SovLabs Template Engine we will use in our custom property is as follows:
[ { "name": "Test.Prop.Foo1", "value": "{% case My.RequestForm.Prop %}{% when 'A' %}A{% when 'B' %}Z{% when 'C' %}Q{% else %}UNKNOWN{% endcase %}" }, { "name": "Test.Prop.Foo2", "value": "{% case My.RequestForm.Prop %}{% when 'A' %}blah{% when 'B' %}blahblah{% when 'C' %}blahblahblah{% else %}UNKNOWN{% endcase %}" }, { "name": "Test.Prop.Foo3", "value": "{% case My.RequestForm.Prop %}{% when 'A' %}0{% when 'B' %}1{% when 'C' %}2{% else %}UNKNOWN{% endcase %}" }, { "name": "Test.Prop.Foo4", "value": "{% case My.RequestForm.Prop %}{% when 'A' %}trees{% when 'B' %}flowers{% when 'C' %}bees{% else %}UNKNOWN{% endcase %}" }, { "name": "Test.Prop.Foo5", "value": "{% case My.RequestForm.Prop %}{% when 'A' %}prod{% when 'B' %}dev{% when 'C' %}qa{% else %}UNKNOWN{% endcase %}" } ]
Procedure
Creating the property definition called My.RequestForm.Prop
- In vRA click on Administration (1) → Property Dictionary (2) → Property Definitions (3) and click on New (4)
- Enter the name as My.RequestForm.Prop
- Set the Data Type as String and required can be left as default
- set the display type as Dropdown
- Setup the static list as A,B and C (see below)
- Click on OK
Add the property definition to your blueprint
- In your vRA Blueprint click on Properties (1) → Custom Properties (2) and click on New (3)
- Under name, enter the property definition we created
- Place a check in Show in Request
- Click on OK
Create the SovLabs_CreateProperties
- While still in your blueprint in Custom Properties, click on New
- Type in SovLabs_CreateProperties_<name>, in this example i will set this to SovLabs_CreateProperties_myFooProps
In the value area, paste in the Template text from the scenario section
[{"name":"Test.Prop.Foo1","value":"{% case My.RequestForm.Prop %}{% when 'A' %}A{% when 'B' %}Z{% when 'C' %}Q{% else %}UNKNOWN{% endcase %}"},{"name":"Test.Prop.Foo2","value":"{% case My.RequestForm.Prop %}{% when 'A' %}blah{% when 'B' %}blahblah{% when 'C' %}blahblahblah{% else %}UNKNOWN{% endcase %}"},{"name":"Test.Prop.Foo3","value":"{% case My.RequestForm.Prop %}{% when 'A' %}0{% when 'B' %}1{% when 'C' %}2{% else %}UNKNOWN{% endcase %}"},{"name":"Test.Prop.Foo4","value":"{% case My.RequestForm.Prop %}{% when 'A' %}trees{% when 'B' %}flowers{% when 'C' %}bees{% else %}UNKNOWN{% endcase %}"},{"name":"Test.Prop.Foo5","value":"{% case My.RequestForm.Prop %}{% when 'A' %}prod{% when 'B' %}dev{% when 'C' %}qa{% else %}UNKNOWN{% endcase %}"}]
- Click on OK
- Click on Finish
- You now have a new drop down property on your blueprint
Test your blueprint
- On your blueprint, when you deploy you will now see a drop down, for this test we will select A
- Once the machine has deployed, we can look in vRO and browse to SovLabs → property Toolkit → Property Toolkit machineBuilding
- Scroll down until you see the machine you are building. If the property toolkit has executed correctly we should see the following
If My.RequestForm.Prop == A
Test.Prop.Foo1 == "A"
Test.Prop.Foo2 == "blah"
Test.Prop.Foo3 == "0"
Test.Prop.Foo4 == "trees"
Test.Prop.Foo5 == "prod" - I have run a second deployment with B selected so we can validate the following
if My.RequestForm.Prop == B
Test.Prop.Foo1 == "Z"
Test.Prop.Foo2 == "blahblah"
Test.Prop.Foo3 == "1"
Test.Prop.Foo4 == "flowers"
Test.Prop.Foo5 == "dev" - As a test I added the option of D into my Property Definition and selected this. We should see all of these go to Unknown as we have set this as the else component of our template text
How to see properties on the VM using Manage Properties (SovLabs Property Toolkit) on your deployed VM
- You can check the properties on a deployed VM. Locate the machine you have deployed and click on the name
- Under components click on the VM Name (1) and click on Actions (2)
- Scroll down and click on Manage Properties (SovLabs Property Toolkit) - VMName
- Next to action, select Update Existing Property
- Next to Propert Picker, scroll down until you see the properties we created, in this case Test.Prop.FooN (Where N is 1 → 5), Select Test.Prope.Foo1
- You will see the property value that has been set
Additional information
SovLabs property toolkit : http://docs.sovlabs.com/latest/vRA/7.6/modules/vra-toolkits/property-toolkit/
SovLabs template engine : http://docs.sovlabs.com/latest/vRA/7.6/framework/sovlabs-template-engine/basics/intro/
0 Comments