ipaascore.BaseStep class

Download this manual as a PDF file

This section describes functions included in the ipaascore.BaseStep class. You can use these functions to define the logic in a step.

This section covers the following topics:

get_app_variable

Description

Retrieve the value of an application variable.

Syntax

get_app_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.

NOTE: To retrieve data from a previous step, that previous step must save the data use the save_data_for_next_step function and the application must specify that the data from the previous step should be passed to the current step using the output_to parameter.

NOTE: 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 hardcoded in the function. The functions join_previous_step_data or get_data_from_step_by_order 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.

NOTE: To retrieve data from a previous step, that previous step must save the data use the save_data_for_next_step function and the 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(pos)

Parameters

position. The position of the step (order that the step was run) in the application. 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.com":

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": "QueryREST",

"method": "GET",

"name": "GETgoogle.com",

"output_to": ["next_step"],

"prefix_url": "http://google.com"

}

],

 

Suppose we use the get_parameter function in the step "GETgoogle.com" 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

param_name. The name of the parameter that you want to retrieve the value for.

step_name. 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.

NOTE: To retrieve data from a previous step, that previous step must save the data use the save_data_for_next_step function and the application must specify that the data from the previous step should be passed to the current step using the output_to parameter.

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

Syntax

join_previous_step_data(data_from)

Parameters

data_from. An optional argument that specifies the steps. For example, if you wanted to join only the data from stepA and stepD, you could specify

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 QueryREST step:

def query_with_url_generated_from_input(self):

“““

Iterates over data from previous steps and generates a relative url for each. Then executes that command

:return:

“““

count = 0

input_data = self.join_previous_step_data()

payload = self.get_parameter(PAYLOAD)

if type(input_data) is list:

for input_d in input_data:

relative_url = self.get_parameter(RELATIVE_URL, input_d)

self.process_REST_command(payload, relative_url)

count += 1

elif type(input_data) is dict:

relative_url = self.get_parameter(RELATIVE_URL, input_data)

self.process_REST_command(payload, relative_url)

count += 1

else:

raise NotImplementedError(“Data type: {} is not currently supported for generating relative urls form data”.format(type(input_data)))

new_step_parameter

Description

Define a parameter for the step. The application will provide the parameter values during runtime. If a parameter is defined as required, the step will fail with an exception if the parameter is not provided.

Syntax

new_step_parameter(name='', description='', sample_value='', default_value=None, required=False)

Parameters

name. The name of the parameter. This value will be used to create a name:value tuple in the 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 combination of alphanumeric characters. To prevent a default value, specify "None".

required. Specifies whether this parameter is required by the step. The possible values are "True" or "False".

Example

Here is an example from the QueryREST step:

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)

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.

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 details, see the section about using applications to transfer 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()