silo.low_code.framework package

class silo.low_code.framework.ArgParser(subs, rc, sub_prefix='<', sub_suffix='>')

Bases: SequencePhase

The ArgParser converts the snippet argument into the appropriate execution to execute.

exception silo.low_code.framework.DeviceError

Bases: FrameworkError

exception silo.low_code.framework.FrameworkError

Bases: SLError

class silo.low_code.framework.RequestMaker(credential, cache_read=True, result_cache=None)

Bases: SequencePhase

Network Requests

agent_supported = False
static generate_agent_config(da_job, result_containers)

Generate an agent configuration for the Requestor / DA Job

This function generates all required configurations and returns them as a list of messages. This allows agent alignment to occur with the proper configuration to collect the required collections. If this function is not implemented, execution on the agent will not occur.

Parameters
  • da_job (dict) – Dynamic Application job pertaining to a specific app / device id.

  • result_containers (list) – List of result containers for the current collections

Returns

List of messages that can be used to generate the config

Return type

list

classmethod get_hash_information(result_container)

Generates the hash information for a specific RC

Parameters

result_container (ResultContainer) – RC to use for generating the Requestor hash. This ensures that duplicate requests are not made which will reduce the load on the local system and reduce toe bandwidth to SL1 and storage on both devices.

Returns

Tuple containing the Display ID and backend ID

Return type

tuple

classmethod get_req_id_disp(result_container)

Setup and calling for generating the request ID

Parameters

result_container (ResultContainer) – Current RC

Returns

Request ID Display name

Return type

str

classmethod get_request_id(result_container)

Given a request for a network response, return the request’s unique ID. By default, this is just the details of the network connection. You may need to make it unique based on e.g. headers, credentials, etc.

The goal is to have a unique hashable identifier based on whatever properties make this request unique.

Parameters

result_container (ResultContainer) – ResultContainer of this network request

Returns

A unique, hashable identifier for this request

Return type

hashable

static manipulate_agent_data(result)

Modify the results to be consistent between the agent and CU

Parameters

result (object) – Results from the agent

abstract validate_request(request)

Accepts a single request to ensure that it is valid for the network requester

Validates that the provided request meets the criteria to be executed by this RequestMaker. If the request is not valid, an exception stating why will be raised. There is no return for this function.

Parameters

request (ResultContainer) – Request that needs to be verified.

exception silo.low_code.framework.RequestMoreData(*args, **kwargs)

Bases: Exception

Informs the framework to goto the previous requestor

Raising this exception within a step will rewind the device metric to the previous Requestor. This allows for additional data to be collected if required. The Requestor must know how to consume the data that is raised for the next collection to occur.

This step cannot be used within Syntax and Requestor steps. The Snippet Framework will consider this exception an unhandled exception and will stop the collection process for that device metric.

class silo.low_code.framework.ResultContainer(result, **kwargs)

Bases: object

The ResultContainer is the standard data interface for moving information between the steps. It is a pure data-class with no attached functions so its only purpose is to move information around.

Object properties are set with the following precedence:

  • Assigned as a keyword argument

  • Value from previous_result

Variables
  • collection (Collection) – Collection associated with the ResultContainer

  • error_data (object) – Information for errors that occurred

  • metadata (dict) – Metadata associated with the collection.

  • name (str) – Name of the ResultContainer. If a name is not provided, a name will be generated as “<obj_id>.<did>”.

  • request_ids (list) – Request_ids for each step

  • result (object) – Result from the previous step or final result of the current step

  • execution (list) – List of steps that need to be executed to get the result

  • cache_info (dict) – Dictionary of step caching information

  • action_number (int) – Current index of the execution plan

  • indexing (str) – Index to help identify the request

  • max_iterations (int) – Maximum number of times RequestMoreData can be executed prior to exiting out of RequestMoreData mode.

  • rmd_data (OrderedDict) – Data related to RequestMoreData iterations. To avoid duplicating memory, rmd_data gets pushed into a nested dictionary. This allows us to pop the data out rather than having to clone and return, which results in memory duplication.

Parameters
  • result (object) – Result to set for the container

  • name (str) – Name of the ResultContainer

  • metadata (dict) – Metadata associated with the collection.

  • error_data (object) – Information for errors that occurred

  • request_ids (list) – Request_ids for each step

  • collection (Collection) – Collection associated with the ResultContainer

  • previous_result (ResultContainer) – ResultContainer that should be use for attribute inheritance

  • indexing (str) – Index to help identify the request

  • max_iterations (int) – Maximum number of times RequestMoreData can be executed prior to exiting out of RequestMoreData mode.

  • rmd_data (OrderedDict) – Data related to RequestMoreData iterations

Noindex

action_number
argument
cache_info
clear_rmd()

Clear out everything related to RequestMoreData and returns the value

Return type

dict

collection
property credential

Lookup the credential assigned to the device

Return type

dict

property current_config

Return the configuration for the current step

Return type

object

property current_step_info

Return the step information for the current step. (step_name, step_config)

Return type

tuple

property current_step_name

Return the name for the current step

Return type

str

did
error_data
execution
get_rmd()

Return the results of RequestMoreData

Return type

dict

property index
indexing
is_cache_step(action_num=None)

Determine if the current step is a caching step

Return type

bool

max_iterations
metadata
name
property request_id

Return the current request_id based off action_number

Returns

Request ID for current action number or None

Return type

union[str,None]

request_ids
result
rmd_data
set_index(index)

Set the index for the result container

Parameters

index (str) – Index when RequestMoreData is active

status
update_rmd()

Add the current result to RequestMoreData

silo.low_code.framework.String23

alias of str

silo.low_code.framework.add_group_descr(group, descr)

Adds a description for a group

Parameters
  • group (str) – Name of the group

  • descr (str) – Description of the group

silo.low_code.framework.cleanup_run(func)

Ensure the framework cleanup steps occur regardless of the outcome

silo.low_code.framework.get_module_logger(name)

Get a logger for the module

This logger is used when any non-contextually aware information needs to be logged.

Parameters

name (str) – Name of the module

Returns

Logger that is used for logging non-contextually aware information

silo.low_code.framework.get_step_adapter(rc, user_logger)

Get a LogAdapter for context-aware log messages based on the user-provided logger

This adapter updates the log messages to use the Framework’s logging header. These messages will not be available in the snippet_framework logfile but will be captured by the WebUIs logging capturing.

Parameters
  • rc (ResultContainer) – Result container containing information about the current collection

  • user_logger (logger) – Logger for the Adapter

Returns

A logger adapter with extra content headers.

silo.low_code.framework.get_step_logger(rc)

Get access to the Snippet Frameworks debug function

This allows a step developer access to write to snippet_framework.log through the debug method. It allows tracing for the framework to be handled in a single log file. If the developer wanted to write “Hello, World!” into the snippet_framework log the following commands would need to be run:

debug = get_step_logger(rc)
debug("Hello, World!")
Parameters

rc (ResultContainer) – Result container containing information about the current collection

Returns

Debug function for the snippet_framework

Return type

callable

silo.low_code.framework.read_cached_results(cache_key, reuse_for=None)

Return the most recent cached element for the given cache_key

This function enables the lookup of Snippet Framework cached elements outside of the Snippet Framework. While this function could work with automatic cache keys the Snippet Framework generates, its best used by overriding the cache_key name within the steps configuration.

The functionality of reuse_for operates the same way within the Snippet Framework. This value is specified in minutes before a cached entry is considered stale. If this value is specified, an entry is considered stale if the following criteria is met:

\[collection\_time + reuse\_for <= current\_time\]

If the newest entry is considered stale, the exception silo.apps.cache.CacheDataIsExpired will be raised.

If an invalid object is found (bad formatting within the cache), the exception MetadataError will be raised.

Parameters
  • cache_key (str) – Specified cache_key for the step

  • reuse_for (int) – Time (in seconds) before considering an entry as stale

Return type

object

silo.low_code.framework.register_cacher(*args, **kwargs)

Decorator to register a cacher

Register a cacher that will be validated once the Framework is initialized.

Parameters
  • get_req_id (callable) – Optional. Function used for generating the request id

  • name (str) – Step Name to use for the Custom Step

  • metadata (dict) – Metadata related to the step

  • read (callable) – Callable function that performs a cache read for fast-forwarding

  • required_args (list) – List of required top-level arguments for the step. If these arguments are not present in the action_arg, the Snippet Framework will not attempt to execute the collection and log a warning message instead.

  • arg_required (bool) – If an argument is required for a step. This denotes a step must have an argument, regardless of the type. This can be used in conjunction with required_args if your step accepts a dictionary or a single value.

Returns

Original object

Return type

object

silo.low_code.framework.register_processor(*args, **kwargs)

Decorator to register a processor

Register a processor that will be validated once the Framework is initialized. There are no sanity checks on a processor so it should always be valid.

Parameters
  • get_req_id (callable) – Optional. Function used for generating the request id

  • name (str) – Step Name to use for the Custom Step

  • metadata (dict) – Metadata related to the step

  • type (str) – Type of the step.

  • required_args (list) – List of required top-level arguments for the step. If these arguments are not present in the action_arg, the Snippet Framework will not attempt to execute the collection and log a warning message instead.

  • arg_required (bool) – If an argument is required for a step. This denotes a step must have an argument, regardless of the type. This can be used in conjunction with required_args if your step accepts a dictionary or a single value.

Returns

Original object

Return type

object

silo.low_code.framework.register_requestor(*args, **kwargs)

Decorator for registering Requesters

Register a Requester that will be validated once the Framework is initialized. A Requester must inherit from the class silo.low_code.RequestMaker.

Parameters
  • get_req_id (callable) – Optional. Function used for generating the request id

  • name (str) – Step Name to use for the Custom Step

  • metadata (dict) – Metadata related to the step

  • rewind (callable) – Callable function that updates the action_arg to start the rewinding process

  • required_args (list) – List of required top-level arguments for the step. If these arguments are not present in the action_arg, the Snippet Framework will not attempt to execute the collection and log a warning message instead.

  • arg_required (bool) – If an argument is required for a step. This denotes a step must have an argument, regardless of the type. This can be used in conjunction with required_args if your step accepts a dictionary or a single value.

Returns

Original object

Return type

object

silo.low_code.framework.register_syntax(*args, **kwargs)

Decorator for registering a Syntax

Register a Syntax that will be validated once the Framework is initialized. An Argument Parser must inherit from the class silo.low_code.ArgParser.

Parameters
  • get_req_id (callable) – Optional. Function used for generating the request id

  • name (str) – Step Name to use for the Custom Step

  • metadata (dict) – Metadata related to the step

Returns

Original object

Return type

object

silo.low_code.framework.set_typechecking(enabled)

Set the global typechecking flag.

Parameters

enabled (bool) – True enables the Type Checking. False disables the Type Checking.

silo.low_code.framework.snippet_framework(*args, **kwargs)
silo.low_code.framework.snippet_framework_single(*args, **kwargs)
silo.low_code.framework.time_execution(func)

Times the execution from start to finish

silo.low_code.framework.typechecked(*v, **k)

Decorator to check the input and output type of a function or method.

Perform type-checking at run-time to ensure the parameters have the correct types. If an incorrect type is provided, an exception will be raised stating the parameter and type issue.

Parameters
  • input (object) – The expected input type. If the typechecking is running against a Requestor it will use request as input. If the typechecking is running against a Processor it will use result as input. If the input is not correct, the exception InputTypeError will be raised.

  • output (object) – The expected output type. If the output is not correct, the exception OutputTypeError will be raised.

  • **extra (object) – Used when checking additional parameters. The name must match the parameter. If the input is not correct, the exception InputTypeError will be raised.

silo.low_code.framework.unique_id_execution(func)

Ensure a unique id is present for each execution

Submodules