Skilletlib Skillet Types¶
Panos Skillet¶
-
class
skilletlib.skillet.panos.
PanosSkillet
(metadata: dict, panoply: skilletlib.panoply.Panoply = None)¶ -
get_results
() → dict¶ PanosSkillet will return a dict containing three keys: result, changed, and snippets. If any snippet failed, the result will be ‘failure’ otherwise ‘success’ If any successful snippet may have caused a change to the device, the ‘changed’ attribute will be ‘True’
A skillet that contains only the following snippet, will generate the output below:
- name: check_hostname_again cmd: op cmd_str: <show><system><info/></system></show> outputs: - name: url-db capture_pattern: ./url-db - name: pa-version capture_pattern: ./plugin_versions/entry[@name="cloud_services"]/@version
{ 'snippets': { 'check_hostname_again': { 'results': 'success', 'changed': True } }, 'outputs': { 'url-db': 'paloaltonetworks', 'pa-version': '1.5.0' }, 'result': 'success', 'changed': True }
Returns: dict containing default outputs plus the overall result and changed flag
-
get_snippets
() → List[skilletlib.snippet.panos.PanosSnippet]¶ Perform Panos Skillet specific tasks while loading each snippet
Returns: a List of PanosSnippets
-
initialize_context
(initial_context: dict) → dict¶ In this panos case, we want to stash the current configuration of the panos device in question in the context, check for online mode, offline mode, or an existing panoply object
Parameters: initial_context – dict to use to initialize the context Returns: context with additional initialized items
-
static
load_element
(snippet_def: dict, snippet_path: pathlib.Path) → dict¶ This method will load the snippet file found on disk into the ‘element’ attribute if the element is not already populated. This allows snippets to be ‘all-in-one’ i.e. there is no requirement for the snippets to be split into separate files. The meta-cnc.yaml file can contain all the snippets ‘inline’ in the ‘element’ attribute if desired. An example snippet def:
- name: template xpath: /config/devices/entry[@name=’localhost.localdomain’]/template file: ../snippets/template.xml
Parameters: snippet_def – the loaded snippet definition from the skillet.yaml file. Each snippet object in the ‘snippets’ stanza is a snippet_def and is passed in here :param snippet_path: the path on the filesystem where this skillet is located. This is used to resolve relative paths for each snippet. This allows snippet file re-use across skillets. :return: snippet_def with the element populated with the resolved and loaded snippet file contents
-
PAN Validation Skillet¶
-
class
skilletlib.skillet.pan_validation.
PanValidationSkillet
(metadata: dict, panoply: skilletlib.panoply.Panoply = None)¶ -
get_results
() → dict¶ Pan-validation skillets return a dictionary with a key for each test that was executed. Each value of those keys will be a dict containing the following keys:
- results - whether the test conditional was true or false
- label - human readable label of the test
- severity - a string that may be set to indicate the severity of a test
- documentation_link - an HTTP link where the user can get more information about this test
- output_message - A rendered output message regarding the test results
{ "update_schedule_configured": { "results": true, "label": "Ensure Update Schedules are Configured", "severity": "low", "documentation_link": "https://iron-skillet.readthedocs.io", "test": "update_schedule_object is not none", "output_message": "Snippet Validation Passed" }, }
Returns: dictionary with the aforementioned keys
-
get_snippets
() → List[skilletlib.snippet.pan_validation.PanValidationSnippet]¶ Perform Panos Skillet specific tasks while loading each snippet
Returns: a List of PanosSnippets
-
REST Skillet¶
-
class
skilletlib.skillet.rest.
RestSkillet
(metadata: dict)¶ -
get_results
() → dict¶ Gets the results from the REST skillet execution. This skillet does not add any additional attributes to the normal output.
The following snippet will generate the following output:
- name: Retrieve Remote Network Service IP from Prisma Access path: https://api.gpcloudservice.com/getAddrList/latest?fwType=gpcs_remote_network&addrType=public_ip operation: GET headers: header-api-key: '{{ api_key }}' output_type: json outputs: - name: status capture_pattern: $.status - name: fwType capture_pattern: $.result.fwType - name: addrList capture_pattern: $.result.addrList
{ 'snippets': { 'Retrieve Remote Network Service IP from Prisma Access': { 'results': 'success', 'raw': { 'status': 'success', 'result': { 'fwType': 'gpcs_remote_network', 'addrListType': 'public_ip', 'total-count': 2, 'addrList': [ 'test-XXX:x.x.x.x', 'pa220-test, pa220-test-2:x.x.x.x' ] } } } }, 'outputs': { 'status': 'success', 'fwType': 'gpcs_remote_network', 'addrList': "['test-XXX:x.x.x.x', 'pa220-test, pa220-test-2:x.x.x.x']" } }
Returns: dictionary of results from the REST Skillet execute or execute_async method
-
get_snippets
() → List[skilletlib.snippet.base.Snippet]¶ Loads and validates each Snippet in the REST skillet metadata file
Returns: List of Snippets for this Skillet Class
-
Template Skillet¶
-
class
skilletlib.skillet.template.
TemplateSkillet
(s: dict)¶ -
get_results
() → dict¶ TemplateSkillet will add an additional attribute into the results dict containing the value of the first snippet found to have been successfully executed
{ "snippets": { "config_template": "success" }, "template": "Rendered Template output" }
Returns: dict containing default outputs plus the rendered template contained in the ‘template’ attribute
-
get_snippets
() → List[skilletlib.snippet.template.TemplateSnippet]¶ Each skillet determines how it’s snippets are to be loaded and initialized. Each Skillet type must implement this method.
Returns: List of Snippets for this Skillet Class
-
Terraform Skillet¶
Base Skillet¶
This is base class from which all Skillets derive.
-
class
skilletlib.skillet.base.
Skillet
(s: dict)¶ -
dump_yaml
() → str¶ Convert this Skillet into a YAML formatted string
Returns: YAML formatted string
-
execute
(initial_context: dict) → dict¶ The heart of the Skillet class. This method executes the skillet by iterating over all the skillets returned from the ‘get_skillets’ method. Each one is checked if it should be executed if a ‘when’ conditional attribute is found, and if so, is executed using the snippet execute method.
Parameters: initial_context – context of key values pairs to use for the execution. By default this is all the variables defined in the skillet file with their default values. Updates from user input, the environment, etc will override these default values via the ‘update_context’ method. :return: a dict containing the updated context containing the output of each of the snippets
-
execute_async
(initial_context: dict) → Generator¶ Returns a generator that can be used to iterate over the output as it’s generated from each snippet. The calling application should call ‘get_results’ once the execute is complete
Parameters: initial_context – context of key values pairs to use for the execution. By default this is all the variables defined in the skillet file with their default values. Updates from user input, the environment, etc will override these default values via the ‘update_context’ method. :return: generator[str]
-
get_declared_variables
() → List[str]¶ Return a list of all variables defined in all the snippets that are not defined as an output
Returns: list of variable names
-
get_results
() → dict¶ Returns the results from the skillet execution. This must be called manually if using ‘execute_async’. The returned dict will include a ‘snippets’ dictionary that contains a key for each snippet that was executed. Each snippet dictionary will contain the ‘results’ and ‘raw’ attributes.
{ 'snippets': { 'check_hostname_again': { 'results': 'success', 'changed': True } }, 'outputs': { 'url-db': 'paloaltonetworks', 'pa-version': '1.5.0' }, 'result': 'success', 'changed': True }
Returns: dictionary of results from the Skillet execute or execute_async method
-
get_snippet_by_name
(snippet_name: str) → skilletlib.snippet.base.Snippet¶ Utility method to return the snippet with snippet_name
Parameters: snippet_name – name attribute of the snippet to return Returns: Snippet Object
-
get_snippets
() → List[skilletlib.snippet.base.Snippet]¶ Each skillet determines how it’s snippets are to be loaded and initialized. Each Skillet type must implement this method.
Returns: List of Snippets for this Skillet Class
-
get_variable_by_name
(variable_name: str) → dict¶ Utility method to return the variable with tne variable_name
Parameters: variable_name – name attribute of the variable to return Returns: dictionary of variable options
-
initialize_context
(initial_context: dict) → dict¶ Child classes can override this to provide any initialization information in the context. For example, ‘panos’ skillets use this to set up and initialize a Panos device object
Parameters: initial_context – Initial Context from user input, environment vars, etc Returns: updated context with initial context items plus any initialization items
-
load_template
(template_path: str) → str¶ Utility method to load a template file and return the contents as str
Parameters: template_path – relative path to the template to load Returns: str contents
-
update_context
(d: dict) → dict¶ Take the input dict d and update the skillet context. I.e. any variables passed in via environment variables will be used to update the context stored on this skillet.
Parameters: d – dictionary of key value pairs. Any keys that match ‘variable’ keys will be used to update the context Returns: updated context stored on this skillet
-