Workload
This script defines the Workload class for creating and managing workloads and the AccessRightRule class for managing access rights.
Classes
- Workload:
Represents a workload with various attributes and methods to update them.
- AccessRightRule:
Represents an access right rule for a workload. It can be either a state rule or a log rule.
Usage
- Create a workload using the WorkloadBuilder:
workload = Workload.builder().build()
- Update fields of the workload:
workload.update_agent_name("agent_B")
- Update dependencies:
deps = workload.get_dependencies() deps["other_workload"] = "ADD_COND_SUCCEEDED" workload.update_dependencies(deps)
- Update tags:
tags = workload.get_tags() tags.pop("key1") workload.update_tags(tags)
- Print the updated workload:
print(workload)
- Create an access state rule:
rule = AccessRightRule.state_rule("Read", ["*"])
- Create an access log rule:
rule = AccessRightRule.log_rule(['workload_A'])
Workload Class
- class ankaios_sdk._components.workload.Workload(name)[source]
Bases:
object
A class to represent a workload.
- name
The workload name.
- Type:
str
- __init__(name)[source]
Initialize a Workload object.
The Workload object should be created using the Workload.builder() method.
- Parameters:
name (str) – The workload name.
- __str__()[source]
Return a string representation of the Workload object.
- Returns:
String representation of the Workload object.
- Return type:
str
- static builder()[source]
Return a WorkloadBuilder object.
- Returns:
A builder object to create a Workload.
- Return type:
- update_workload_name(name)[source]
Set the workload name.
- Parameters:
name (str) – The workload name to update.
- Return type:
None
- update_agent_name(agent_name)[source]
Set the agent name for the workload.
- Parameters:
agent_name (str) – The agent name to update.
- Return type:
None
- update_runtime(runtime)[source]
Set the runtime for the workload.
- Parameters:
runtime (str) – The runtime to update.
- Return type:
None
- update_runtime_config(config)[source]
Set the runtime-specific configuration for the workload.
- Parameters:
config (str) – The runtime configuration to update.
- Return type:
None
- update_runtime_config_from_file(config_file)[source]
Set the runtime-specific configuration for the workload from a file.
- Parameters:
config_file (str) – The path to the configuration file.
- Return type:
None
- update_restart_policy(policy)[source]
Set the restart policy for the workload. Supported values: NEVER, ON_FAILURE, ALWAYS.
- Parameters:
policy (str) – The restart policy to update.
- Raises:
WorkloadFieldException – If an invalid restart policy is provided.
- Return type:
None
- get_dependencies()[source]
Return the dependencies of the workload.
- Returns:
A dictionary of dependencies with workload names as keys and conditions as values.
- Return type:
dict
- update_dependencies(dependencies)[source]
Update the dependencies of the workload. Supported conditions: ADD_COND_RUNNING, ADD_COND_SUCCEEDED, ADD_COND_FAILED.
- Parameters:
dependencies (dict) – A dictionary of dependencies with workload names and condition as values.
- Raises:
WorkloadFieldException – If an invalid condition is provided.
- Return type:
None
- add_tag(key, value)[source]
Add a tag to the workload.
- Parameters:
key (str) – The key of the tag.
value (str) – The value of the tag.
- Return type:
None
- get_tags()[source]
Return the tags of the workload.
- Returns:
A list of tuples containing tag keys and values.
- Return type:
list
- update_tags(tags)[source]
Update the tags of the workload.
- Parameters:
tags (list) – A list of tuples containing tag keys and values.
- Return type:
None
- get_allow_rules()[source]
Return the allow rules of the workload.
- Returns:
A list of AccessRightRules
- Return type:
list
- update_allow_rules(rules)[source]
Update the allow rules of the workload.
- Parameters:
rules (list) – A list of AccessRightRules.
- Return type:
None
- get_deny_rules()[source]
Return the deny rules of the workload.
- Returns:
A list of AccessRightRules
- Return type:
list
- update_deny_rules(rules)[source]
Update the deny rules of the workload.
- Parameters:
rules (list) – A list of AccessRightRules.
- Return type:
None
- 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.
- Return type:
None
- get_configs()[source]
Return the configurations linked to the workload.
- Returns:
- A dict containing the alias as key and name of the
configuration as value.
- Return type:
dict[str, str]
- update_configs(configs)[source]
Update the configurations linked to the workload.
- Parameters:
configs (dict[str, str]) – A tuple containing the alias and name of the configurations.
- Return type:
None
- add_file(file)[source]
Link a workload file to the workload.
- Parameters:
file (File) – The File object to mount to the workload.
- Return type:
None
- get_files()[source]
Return the files linked to the workload.
Returns: list[File]: A list of File objects mounted to the workload.
- Return type:
list
[File
]
AccessRightRule Class
- class ankaios_sdk._components.workload.AccessRightRule(rule)[source]
Represents an access right rule for a workload. It can be either a state rule or a log rule.
- __init__(rule)[source]
Initializes the AccessRightRule. For initialization, use the static methods state_rule or log_rule, depending on the type of rule you want to create.
- Parameters:
rule (_ank_base.AccessRightsRule) – The access right rule.
- __str__()[source]
Returns the string representation of the access right rule.
- Returns:
The string representation of the access right rule.
- Return type:
str
- property type: str
Returns the type of the access right rule.
- Returns:
The type of the access right rule.
- Return type:
str
- static state_rule(operation, filter_masks)[source]
Create an access state rule for a workload. Supported operations: Nothing, Write, Read, ReadWrite.
- Parameters:
operation (str) – The operation the rule allows.
filter_masks (list) – The list of filter masks.
- Returns:
The access right rule object.
- Return type:
- Raises:
WorkloadFieldException – If an invalid operation is provided.