Workload Builder
This script defines the WorkloadBuilder class for creating a Workload instance.
Classes
- WorkloadBuilder:
A builder class to create a Workload object with a fluent interface.
Usage
- Create a workload using the WorkloadBuilder:
workload = WorkloadBuilder() \ .workload_name("nginx") \ .agent_name("agent_A") \ .runtime("podman") \ .restart_policy("NEVER") \ .runtime_config("image: docker.io/library/nginx\n" + "commandOptions: [\"-p\", \"8080:80\"]") \ .add_dependency("other_workload", "ADD_COND_RUNNING") \ .add_tag("key1", "value1") \ .add_tag("key2", "value2") \ .build()
WorkloadBuilder Class
- class ankaios_sdk._components.workload_builder.WorkloadBuilder[source]
Bases:
object
A builder class to create a Workload object.
- wl_name
The workload name.
- Type:
str
- wl_agent_name
The agent name.
- Type:
str
- wl_runtime
The runtime.
- Type:
str
- wl_runtime_config
The runtime configuration.
- Type:
str
- wl_restart_policy
The restart policy.
- Type:
str
- dependencies
The dependencies.
- Type:
dict
- tags
The tags.
- Type:
list
- workload_name(workload_name)[source]
Set the workload name.
- Parameters:
workload_name (str) – The workload name to set.
- Returns:
The builder object.
- Return type:
- agent_name(agent_name)[source]
Set the agent name.
- Parameters:
agent_name (str) – The agent name to set.
- Returns:
The builder object.
- Return type:
- runtime(runtime)[source]
Set the runtime.
- Parameters:
runtime (str) – The runtime to set.
- Returns:
The builder object.
- Return type:
- runtime_config(runtime_config)[source]
Set the runtime configuration.
- Parameters:
runtime_config (str) – The runtime configuration to set.
- Returns:
The builder object.
- Return type:
- runtime_config_from_file(runtime_config_path)[source]
Set the runtime configuration using a file.
- Parameters:
runtime_config_path (str) – The path to the configuration file.
- Returns:
The builder object.
- Return type:
- restart_policy(restart_policy)[source]
Set the restart policy.
- Parameters:
restart_policy (str) – The restart policy to set.
- Returns:
The builder object.
- Return type:
- add_dependency(workload_name, condition)[source]
Add a dependency.
- Parameters:
workload_name (str) – The name of the dependent workload.
condition (str) – The condition for the dependency.
- Returns:
The builder object.
- Return type:
- add_tag(key, value)[source]
Add a tag.
- Parameters:
key (str) – The key of the tag.
value (str) – The value of the tag.
- Returns:
The builder object.
- Return type:
- add_allow_state_rule(operation, filter_masks)[source]
Add an allow state rule to the workload.
- Parameters:
operation (str) – The operation the rule allows.
filter_masks (list) – The list of filter masks.
- Returns:
The builder object.
- Return type:
- Raises:
WorkloadFieldException – If the operation is invalid.
- add_deny_state_rule(operation, filter_masks)[source]
Add a deny state rule to the workload.
- Parameters:
operation (str) – The operation the rule denies.
filter_masks (list) – The list of filter masks.
- Returns:
The builder object.
- Return type:
- Raises:
WorkloadFieldException – If the operation is invalid.
- add_allow_log_rule(workload_names)[source]
Add an allow log rule to the workload.
- Parameters:
workload_names (list) – The list of workload names the rule applies to.
- Returns:
The builder object.
- Return type:
- add_deny_log_rule(workload_names)[source]
Add an deny log rule to the workload.
- Parameters:
workload_names (list) – The list of workload names the rule applies to.
- Returns:
The builder object.
- Return type:
- add_config(alias, name)[source]
Link a configuration to the workload.
- Parameters:
alias (str) – The alias of the configuration.
name (str) – The name of the configuration.
- Returns:
The builder object.
- Return type:
- add_file(file)[source]
Link a workload file to the workload.
- Parameters:
file (File) – The file object to mount to the workload.
- Returns:
The builder object.
- Return type:
- build()[source]
Build the Workload object. Required fields: workload name, agent name, runtime and runtime configuration.
- Returns:
The built Workload object.
- Return type:
- Raises:
WorkloadBuilderException – If required fields are not set.