config
This module contains code to standardize the configuration of Panorama applications via deploy-time parameters. It also contains a CLI (command-line interface) that generates configuration snippets for the metadata and descriptor json files of your Panorama project.
Defining config structures
This module defines ConfigBase
, a base class for Panorama application
configurations. The class offers two basic functionalities:
parse parameters from the Panorama application input ports (
panoramasdk.node.inputs
)generate configuration file snippets for
graph.json
andpackage.json
in your Panorama project. For more information about how to use the CLI, refer totool()
.
- class backpack.config.ConfigBase
Bases:
object
Base class for configuration structures.
Subclasses must be also dataclasses.
- get_panorama_definitions(serde_metadata={})
Generate the
nodeGraph.nodes
snippet ingraph.json
.
- get_panorama_edges(code_node_name)
Generate the
nodeGraph.edges
snippet ingraph.json
- get_panorama_app_interface()
Generate the application interface snippet in app node
package.json
.
- get_panorama_markdown_doc(serde_metadata={})
Generates a markdown table of the parameters that can be used in documentation.
- classmethod from_panorama_params(inputs, serde_metadata={})
Parses the config values form AWS Panorama input parameters.
A new Config object is created with the default values. If a particular value is found in the input parameter, its value will override the default value.
Command-line interface
The config.tool
module defines a simple command-line interface (CLI) program that can be
used as a development tool. It creates snippets that you can copy-paste into the Panorama
application project files like graph.json, or package.json of the business logic package.
- config.cli(config)
Creates a simple command line interface for printing config snippets.
- Parameters:
name (str) – The name of your Panorama app
config (ConfigBase) – Instance of your configuration structure, subclass of ConfigBase.
- Return type:
None
Defining serializers/deserializers
Serializers/Deserializers (SerDe) convert between configuration strings (or numbers) and different Python structures.
You should subclass ConfigSerDeBase
and override the following static fields:
name
: the description of the structure this serde can convert, for example “Comma-separated list of integers”. This text will be used in the documentation generated by the ConfigBase CLI.serialize
: Take the Python structure and returns a string representation.deserialize
: Take a string representation of the value and return a Python structure.
- class backpack.config.ConfigSerDeBase
Bases:
ABC
Defines a serializer / deserializer interface.
- description: str = 'The base serde encodes and decodes strings to themselves.'
A textual description how the object is encoded in the string. Will be used in docs.
- abstract static serialize(value, metadata={})
Serializes a config value to a string.
- abstract static deserialize(value, metadata={})
Deserializes a string to a config value.
List of SerDe implementations
- class backpack.config.IntegerListSerDe
Bases:
ConfigSerDeBase
De/serializes a string containing a comma-separated list of integers.
- description: str = 'Comma-separated list of integers'
A textual description how the object is encoded in the string. Will be used in docs.
- static serialize(value, metadata={})
Serializes a list of integers into a string.
- static deserialize(value, metadata={})
Restores a list of integers from a string.
- class backpack.config.geometry.PolyLineSerDe
Bases:
ConfigSerDeBase
De/serializes a json string containing a polygon definition.
Example string:
[[0.1, 0.1], [0.9, 0.1], [0.9, 0.9], [0.5, 0.5], [0.1, 0.9]]
- description: str = 'JSON encoded Polygon'
A textual description how the object is encoded in the string. Will be used in docs.
- example: str = '[[0.1, 0.1], [0.9, 0.1], [0.9, 0.9], [0.5, 0.5], [0.1, 0.9]]'
Provide a textual example of the encoded string. Will be used in docs.
- static serialize(value, metadata={})
Serializes a PolyLine into a string.
- static deserialize(value, metadata={})
Restores a PolyLine from a string.