This
get_app_variable
Description
Retrieve the value of an application variable.
Syntax
get_app_variable("<variable_name>")
Parameters
<variable_name>. The name of the application variable that you want to retrieve the value for.
Return
The value of the application variable.
Example
Suppose we defined this application variable in the application:
"app_variables": [
{
"name": "sl1_hostname",
"description": "The SL1 hostname to participate in the sync",
"sample_value": "10.2.253.115",
"default_value": null,
"required": true,
"value": 10.64.68.25
},
]
Suppose this application calls the step "sync_SL1_data".
In the step "sync_SL1_data", we could use the following function to resolve the value of "sl1hostname":
hostname = self.get_app_variable("sl1_hostname")
The value of hostname would be "10.64.68.25".
get_available_previous_step_input_positions
Description
Retrieves the list of steps in the application, along with the position of the step (the order that the step was run in the application). Position "0" (zero) is reserved for the current step's arguments.
Syntax
get_available_previous_step_input_positions()
Return
Returns a list of tuples. Each tuple includes a step name and the step's position.
get_data_from_step_by_name
Description
Retrieves data saved from a previous step.
To retrieve data from a previous step:
- That previous step must save the data with the save_data_for_next_step function.
- The PowerFlow application must specify that the data from the previous step should be passed to the current step using the output_to parameter.
Although the get_data_from_step_by_name function is simple to use, it does not allow you to write a generic, reusable step, because the step name will be hard-coded in the function. The join_previous_step_data or get_data_from_step_by_order functions allow you to create a more generic, reusable step.
Syntax
get_data_from_step_by_name('<step_name>')
Parameters
<step_name>. The name of a previous step in the application.
Return
The data that was saved by the previous step.
Example
The following is an example of the get_data_from_step_by_name function:
em7_data = self.get_data_from_step_by_name('FetchDevicesFromEM7')
snow_data = self.get_data_from_step_by_name('FetchDevicesFromSnow')
get_data_from_step_by_order
Description
This function retrieves data from a step based on the position of the step in the application.
To retrieve data from a previous step:
- That previous step must save the data with the save_data_for_next_step function.
- The PowerFlow application must specify that the data from the previous step should be passed to the current step using the output_to parameter.
Syntax
get_data_from_step_by_order(<position>)
Parameters
<position>. The position of the step (order that the step was run) in the PowerFlowapplication. Position values start at 0 (zero) .
Return
The data that was saved by the previous step.
Exception
DataNotAvailableException
Example
- Suppose your application has four steps: stepA, stepB, stepC, and stepD
- Suppose stepA was run first (position 0) and includes the parameter output_to:[stepD]
- Suppose stepB was run second (position 1) and includes the parameter output_to:[stepD]
- Suppose stepC was run third (position 2) and includes the parameter output_to:[stepD]
- Suppose stepD was run fourth
If the current step is stepD, and stepD needs the data from stepC, you could use the following:
data_from_stepC = self.get_data_from_step_by_order(2)
get_name
Description
Returns the name of the current step.
Syntax
get_name()
Return
The name of the current step.
get_parameter
Description
Retrieves a parameter value.
Syntax
get_parameter("<param_name>", <lookup_data>=None)
Parameters
- <param_name>. The name of the parameter that you want to retrieve the value for.
- <lookup_data>. An optional dictionary that can provide a reference for additional variable substitutions.
Return
Value of the requested parameter.
Example
For example, suppose we defined this parameter in the step named "GETgoogle":
self.new_step_parameter(name=prefix_url, description="used with relative_url to create the full URL.",sample_value="http://10.2.11.253", default_value=None, required=True)
Suppose in the application that calls "GETgoogle.com", we specified:
"steps": [
{
"file": "GetREST",
"name": "GETgoogle",
"output_to": ["next_step"],
"prefix_url": "http://google.com"
}
],
Suppose we use the get_parameter function in the step "GETgoogle" to retrieve the value of the "prefix_url" parameter:
build_url_1 = self.get_parameter("prefix_url")
The value of build_url_1 would be "http://google.com".
get_parameter_from_previous_step
Description
Retrieves a parameter value from a previous step.
Syntax
get_parameter_from_previous_step(<parameter_name>, <step_name>)
Parameters
<parameter_name>. The name of the parameter that you want to retrieve the value for.
<step_name>. The name of the step from which you want to retrieve a parameter value.
Return
The value of the parameter.
join_previous_step_data
Description
This function retrieves data from one or more previous steps in the application. If you are expecting similar data from multiple steps, or expecting data from only a single step, the join_previous_step_data function is the best choice.
The join_previous_step_data function gathers all data from all steps that included the save_data_for_next_step function and also include the output_to parameter in the application. By default, this function returns the joined set of all data that is passed to the current step. You can also specify a list of previous steps from which to join data.
The retrieved data must be of the same type. The data is then combined into a list or a dictionary. If the data types are not the same, then the function will raise an exception.
To retrieve data from a previous step:
- That previous step must save the data with the save_data_for_next_step function.
- The PowerFlow application must specify that the data from the previous step should be passed to the current step using the output_to parameter.
Syntax
join_previous_step_data(<step_name>)
Parameters
<step_name>. An optional argument that specifies the steps. For example, if you wanted to join only the data from stepA and stepD, you could specify the following:
self.join_previous_step_data(["stepA", "stepD"]),
Return
Combined data structure, either a list or a dictionary, of all the retrieved step data.
Example
The following is an example of the join_previous_step_data function in the "SavetoCache" step (included in each PowerFlow system):
def execute(self): data_from = self.get_parameter(DATA_FROM_PARAM, {}) if data_from: data_to_cache = self.join_previous_step_data(data_from) else: data_to_cache = self.join_previous_step_data() ...
new_step_parameter
Description
Defines an input parameter for the step. The PowerFlow application will examine the parameters and enforce the parameters when the step is run. For example, if you specify a parameter as required, and the user does not specify the required parameter when calling the step, PowerFlow will display an error message and will not execute the step.
Syntax
self.new_step_parameter( name=<parameter_name>, description="<description>", sample_value="<sample_value>", default_value=<default_value>, required=<True/False>, param_type=parameter_types.<Number/String/Boolean>Parameter(), )
Parameters
- name. The name of the parameter. This value will be used to create a name:value tuple in the PowerFlow application file (in JSON).
- description. A description of the step parameter.
- sample_value. A sample value of the required data type or schema.
- default_value. If no value is specified for this parameter, use the default value. Can be any Python data structure. To prevent a default value, specify None.
- required. Specifies whether this parameter is required by the step. The possible values are True or False.
- param_type. Specifies the type of parameter. Options include Number, String, Boolean. This setting is optional.
Example
The following is an example from the "Cache Save" step from the "Base Steps" SyncPack:
self.new_step_parameter( name=SAVE_KEY, description="The key for which to save this data with", sample_value="keyA", default_value=None, required=True, param_type=parameter_types.StringParameterShort(), )
save_data_for_next_step
Description
This function saves an object (usually a variable) and makes the data available to another step. The object must be of a data type that can be pickled by Python. For more information about pickle, see https://docs.python.org/3/library/pickle.html.
Syntax
save_data_for_next_step(<data_to_save>)
Parameters
<data_to_save>. A variable that contains the data.
NOTE: The <data_to_save> object must be of a data type that can be pickled by Python: None, True and False, integers, long integers, floating point numbers, complex numbers, normal strings, unicode strings, tuples, lists, set, and dictionaries.
Example
The following is an example of the save_data_for_next_step function:
save_data = {'key': 'value'}
self.save_data_for_next_step(save_data)
The application must then specify that the data from the current step should be passed to one or more subsequent step, using the output_to parameter. For more information, see Transferring Data Between Steps.
validate_parameter_values
Description
Validates the parameter values provided for an application. For example, the validate_parameter_value function will raise an error if the user failed to provide a required parameter.
Syntax
validate_parameter_values()