42 lines
1008 B
Python
42 lines
1008 B
Python
from .adapters import Endpoint, NormalizedObject, PlanAction
|
|
|
|
|
|
def require_endpoint_plugin(
|
|
endpoint: Endpoint,
|
|
plugin_name: str,
|
|
) -> None:
|
|
expected = plugin_name.strip().lower()
|
|
|
|
if not expected:
|
|
raise ValueError("Adapter plugin name cannot be empty")
|
|
|
|
if endpoint.plugin != expected:
|
|
raise RuntimeError(
|
|
f"Adapter {expected!r} cannot use endpoint "
|
|
f"{endpoint.identity!r}"
|
|
)
|
|
|
|
|
|
def require_action_endpoint(
|
|
action: PlanAction,
|
|
endpoint: Endpoint,
|
|
) -> None:
|
|
if action.endpoint_id != endpoint.identity:
|
|
raise RuntimeError(
|
|
f"Plan action for {action.endpoint_id!r} does not belong "
|
|
f"to adapter endpoint {endpoint.identity!r}"
|
|
)
|
|
|
|
|
|
def require_desired(
|
|
action: PlanAction,
|
|
*,
|
|
context: str = "Adapter apply",
|
|
) -> NormalizedObject:
|
|
if action.desired is None:
|
|
raise RuntimeError(
|
|
f"{context} requires desired state"
|
|
)
|
|
|
|
return action.desired
|