Templating and Property Toolkit
4 minute read
To learn more about this OneFuse feature, refer to Templating guide and Property Toolkit features.
Introduction
The OneFuse Property Toolkit (PTK) is the Swiss army knife of the OneFuse Platform.
PTK can be used to simplify configurations, define business logic as configuration, build simple logic or tackle the most complex problems. At face value, the PTK is meta-data that can be called upon offering simple name value pairs that can be used as a reference for decision making. In its most powerful form, it can contain logic, decision trees, platform abstractions, and much more.
Feature highlights
- Minimize automation inputs by presenting simple meaningful inputs, and leveraging policy-driven decisioning
- Reduce configuration sprawl with dynamic property configurations
- Reduce custom code/technical debt in the areas of configurations and business logic
- Cross-platform/tool standardization
- Use OneFuse Property Sets to drive property assignment and rendering
- Supports OneFuse Template Engine
Resources
Best practices
template_properties parameter for OneFuse modules
Every OneFuse Module takes an input parameter called template_properties:
- Allows users to define their own values for variables within each Module.
- In a Python dict format that takes multiple values and passes them to OneFuse Modules.
It is best practice to combine all of your template_properties together and pass them collectively into each OneFuse Module, rather than passing only the needed variables for a particular OneFuse Module. This greatly simplifies configurations, and allows for:
- Defining a base set of
template_propertiesin aproperties.pyfile and import it. - Merging in additional ones as needed, always ensuring the needed values are passed into each OneFuse Module.
OneFuse Property Sets for Property Toolkit consumption
The OneFuse Property Toolkit is a very powerful tool within Python with the ability to look up data against a standard set of properties.
An example would be a Property Sets for: Environment that defines known values for different integrations or services for provisioning:
- You may have a Property Set for the production environment that effects the name, network selection, DNS registration, template to be used, etc.
- You may also have a Property Set for the development environment that differently effects the name, network selection, DNS registration, template to be used, etc.
It is a best practice to have all of your Property Set management within a dedicated .py file named properties.py. This allows a single location where you can review and manage the OneFuse Property Sets and the resultant property associations versus having them scattered throughout the OneFuse Python Module.
Render templates in OneFuse Python Module
Render OneFuse templates in Python using the OneFuse Templating Engine.
Rendering template specific parameters
| Parameter Name | Notes |
|---|---|
template |
OneFuse Template string. |
template_properties |
(Optional) Additional properties that are referenced and rendered within the Template |
Rendering examples
Example for rendering a template
Run the following command in Python Console to render Templates.
#Run the following in the Python Console
#Assumes OneFuse Manager is instantiated to 'ofm' variable
ofm.render('<template>', <template_properties>)
# Example
ofm.render('{{ environment }}', {"environment": "production"})
# Example Output
# >>> 'production'
Use OneFuse Property Sets in OneFuse Python Module
Get OneFuse Property Sets and pass them as template_properties
Property Set specific parameters
| Parameter Name | Notes |
|---|---|
name |
OneFuse Property Set name to retrieve. |
Outputs
The entire response_json is returned. Use the attribute below to retrieve the properties.
| Attribute Name | Notes |
|---|---|
properties |
Get the Property Set’s properties. |
Example
#Run the following in the Python Console
#Assumes OneFuse Manager is instantiated to 'ofm' variable
#Example uses provision_naming method and passes in properties from a OneFuse Property Set as <template_properties>
ofm.provision_naming('<policy_name>', ofm.get_sps_by_name('<property_set_name>')['properties'], '<tracking_id>')
Other Property Toolkit methods
Use other Property Toolkit Methods in OneFuse Python Module
#Run the following in the Python Console
## get_sps_properties
# Find any properties with key prefixed with 'OneFuse_SPS_'
# Run the following help command to learn more
help(OneFuseManager.get_sps_properties)
## get_create_properties
# Find any properties with key prefixed with 'OneFuse_CreateProperties_'
# Run the following help command to learn more
help(OneFuseManager.get_create_properties)