Software interface reference#
Complete specification of the interface a software runtime plugin must implement.
Class attributes#
Attribute |
Type |
Required |
Description |
|---|---|---|---|
|
type |
Yes |
A dataclass that defines the typed configuration for this plugin. Used by Kiso to parse and validate the config. |
|
dict |
Yes |
A JSON schema dict that Kiso uses to validate the user’s config before calling |
Methods#
__init__(self, config)#
Initialize the installer with a validated configuration instance.
Parameter |
Type |
Description |
|---|---|---|
|
instance of |
Validated configuration, already parsed from the user’s YAML |
Called once per experiment run, after config validation passes.
check(self, label_to_machines)#
Validate that the configuration is consistent with the available nodes.
Parameter |
Type |
Description |
|---|---|---|
|
|
Mapping from label name to list of machine objects |
Must raise a descriptive exception if any label in the config does not exist in label_to_machines, or if any other configuration invariant is violated.
Called during kiso check and at the start of kiso up, before any provisioning occurs.
__call__(self, env)#
Install the software on the nodes specified in the configuration.
Parameter |
Type |
Description |
|---|---|---|
|
|
EnOSlib environment dict. For e.g., |
Must be idempotent: calling this method twice on already-provisioned nodes must produce the same result as calling it once.
Must not raise an exception if the software is already installed and at the correct version.
Must raise a descriptive exception if installation fails.
Configuration dataclass conventions#
The config_type dataclass fields become the config keys users write in YAML. Follow these conventions:
Convention |
Example |
|---|---|
Field names use snake_case |
|
Required fields have no default |
|
Optional fields have a default |
|
Lists use |
|
JSON schema conventions#
Convention |
Example |
|---|---|
Top-level is |
— |
|
|
|
Prevents unknown keys |
|
— |
Example: minimal software plugin#
from dataclasses import dataclass
from typing import Optional
from pathlib import Path
from enoslib.api import run_ansible
@dataclass
class MyRuntimeConfig:
labels: list[str]
version: Optional[str] = None
class MyRuntimeInstaller:
config_type = MyRuntimeConfig
schema = {
"type": "object",
"properties": {
"labels": {"type": "array", "items": {"type": "string"}, "minItems": 1},
"version": {"type": "string"},
},
"required": ["labels"],
"additionalProperties": False,
}
def __init__(self, config: MyRuntimeConfig):
self.config = config
def check(self, label_to_machines: dict) -> None:
for label in self.config.labels:
if label not in label_to_machines:
raise ValueError(f"Unknown label: {label!r}")
def __call__(self, env) -> None:
playbook = Path(__file__).parent / "main.yml"
run_ansible(
[str(playbook)],
roles=env["roles"],
extra_vars={"labels": self.config.labels},
)
See also#
Add a software runtime — step-by-step implementation guide
How Kiso extensions work — extension model overview