netherframe.cli 0.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- netherframe/cli/__init__.py +1 -0
- netherframe/cli/__main__.py +4 -0
- netherframe/cli/commands/__init__.py +93 -0
- netherframe/cli/commands/backend.py +305 -0
- netherframe/cli/commands/config_command.py +98 -0
- netherframe/cli/commands/convert.py +40 -0
- netherframe/cli/commands/discover.py +679 -0
- netherframe/cli/commands/drift.py +499 -0
- netherframe/cli/commands/encode.py +130 -0
- netherframe/cli/commands/generation.py +861 -0
- netherframe/cli/commands/graph_state.py +439 -0
- netherframe/cli/commands/hybrid.py +461 -0
- netherframe/cli/commands/idiff.py +493 -0
- netherframe/cli/commands/infrastructure.py +1182 -0
- netherframe/cli/commands/init_command.py +11 -0
- netherframe/cli/commands/lint.py +49 -0
- netherframe/cli/commands/providers.py +315 -0
- netherframe/cli/commands/shell_command.py +17 -0
- netherframe/cli/commands/skill.py +167 -0
- netherframe/cli/commands/synthesis.py +732 -0
- netherframe/cli/commands/terraform_command.py +17 -0
- netherframe/cli/commands/watch_command.py +117 -0
- netherframe/cli/entrypoint.py +18 -0
- netherframe/cli/logging.py +33 -0
- netherframe/cli/main.py +177 -0
- netherframe/cli/options.py +32 -0
- netherframe/cli/py.typed +0 -0
- netherframe/cli/services/__init__.py +1 -0
- netherframe/cli/services/app_loader.py +62 -0
- netherframe/cli/services/app_resolver.py +205 -0
- netherframe/cli/services/graph_onboarding.py +144 -0
- netherframe/cli/services/legacy_cli.py +51 -0
- netherframe/cli/services/project_config.py +107 -0
- netherframe/cli/services/provider_batch.py +620 -0
- netherframe/cli/services/stack_inventory.py +342 -0
- netherframe/cli/skills/netherframe/SKILL.md +53 -0
- netherframe/cli/skills/netherframe/agents/openai.yaml +3 -0
- netherframe/cli/skills/netherframe/references/authoring.md +77 -0
- netherframe/cli/skills/netherframe/references/execution.md +70 -0
- netherframe/cli/skills/netherframe/references/migration.md +69 -0
- netherframe/cli/state_migration.py +111 -0
- netherframe/cli/tui/__init__.py +1 -0
- netherframe/cli/tui/plan_filters.py +200 -0
- netherframe/cli/tui/plan_models.py +51 -0
- netherframe/cli/tui/plan_viewer.py +745 -0
- netherframe/cli/ui.py +25 -0
- netherframe_cli-0.2.1.dist-info/METADATA +86 -0
- netherframe_cli-0.2.1.dist-info/RECORD +92 -0
- netherframe_cli-0.2.1.dist-info/WHEEL +4 -0
- netherframe_cli-0.2.1.dist-info/entry_points.txt +3 -0
- netherframe_cli-0.2.1.dist-info/licenses/LICENSE +21 -0
- nf/cli/__init__.py +4 -0
- nf/cli/__main__.py +4 -0
- nf/cli/commands/__init__.py +4 -0
- nf/cli/commands/backend.py +4 -0
- nf/cli/commands/config_command.py +4 -0
- nf/cli/commands/convert.py +4 -0
- nf/cli/commands/discover.py +4 -0
- nf/cli/commands/drift.py +4 -0
- nf/cli/commands/encode.py +4 -0
- nf/cli/commands/generation.py +4 -0
- nf/cli/commands/graph_state.py +4 -0
- nf/cli/commands/hybrid.py +4 -0
- nf/cli/commands/idiff.py +4 -0
- nf/cli/commands/infrastructure.py +4 -0
- nf/cli/commands/init_command.py +4 -0
- nf/cli/commands/lint.py +4 -0
- nf/cli/commands/providers.py +4 -0
- nf/cli/commands/shell_command.py +4 -0
- nf/cli/commands/skill.py +4 -0
- nf/cli/commands/synthesis.py +4 -0
- nf/cli/commands/terraform_command.py +4 -0
- nf/cli/commands/watch_command.py +4 -0
- nf/cli/entrypoint.py +4 -0
- nf/cli/logging.py +4 -0
- nf/cli/main.py +4 -0
- nf/cli/options.py +4 -0
- nf/cli/py.typed +0 -0
- nf/cli/services/__init__.py +4 -0
- nf/cli/services/app_loader.py +4 -0
- nf/cli/services/app_resolver.py +4 -0
- nf/cli/services/graph_onboarding.py +4 -0
- nf/cli/services/legacy_cli.py +4 -0
- nf/cli/services/project_config.py +4 -0
- nf/cli/services/provider_batch.py +4 -0
- nf/cli/services/stack_inventory.py +4 -0
- nf/cli/state_migration.py +4 -0
- nf/cli/tui/__init__.py +4 -0
- nf/cli/tui/plan_filters.py +4 -0
- nf/cli/tui/plan_models.py +4 -0
- nf/cli/tui/plan_viewer.py +4 -0
- nf/cli/ui.py +4 -0
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
"""Helpers for direct (hybrid) execution used by the plan/apply/show/destroy/deploy commands."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
from collections.abc import Callable
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import TYPE_CHECKING, Any, cast
|
|
9
|
+
|
|
10
|
+
import click
|
|
11
|
+
from rich.markup import escape
|
|
12
|
+
from netherframe.cli.ui import console
|
|
13
|
+
from netherframe.core.config.hybrid_settings import DELETED_OBJECT_MODES, DEFERRED_APPROVAL_MODES, PROVIDER_DATA_SOURCE_MODES, GRAPH_PLAN_SCOPES
|
|
14
|
+
from netherframe.core.execution.approval import ApprovalRequest, approval_input
|
|
15
|
+
from netherframe.core.execution.hybrid_plan import deferred_change_lines, import_lines, output_change_lines, summary_has_changes
|
|
16
|
+
from netherframe.core.execution.plan_artifacts import load_plan_artifact
|
|
17
|
+
from netherframe.core.execution.provenance_report import report_lines
|
|
18
|
+
from netherframe.core.execution.graph_plan_review import inspection_lines, deleted_object_lines
|
|
19
|
+
from netherframe.core.serialization.unknown_values import KNOWN_AFTER_APPLY
|
|
20
|
+
|
|
21
|
+
from netherframe.cli.services.app_loader import load_app_from_spec
|
|
22
|
+
from netherframe.cli.services.project_config import load_project_config
|
|
23
|
+
|
|
24
|
+
if TYPE_CHECKING:
|
|
25
|
+
from netherframe.core.execution.hybrid import HybridExecutionMode
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _summary_int(data: dict[str, object], key: str) -> int:
|
|
29
|
+
"""Return a plan-summary field coerced to int when possible."""
|
|
30
|
+
value = data.get(key, 0)
|
|
31
|
+
return value if isinstance(value, int) else 0
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _summary_flag(data: dict[str, object], key: str) -> bool:
|
|
35
|
+
"""Return a boolean plan-summary field."""
|
|
36
|
+
return data.get(key) is True
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _change_value(change: object, key: str, default: Any = None) -> Any:
|
|
40
|
+
"""Return a change field while keeping dictionary key types simple for ty."""
|
|
41
|
+
if not isinstance(change, dict):
|
|
42
|
+
return default
|
|
43
|
+
return cast("dict[str, Any]", change).get(key, default)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# The hybrid settings `nf apply` / `nf deploy` flags set (see set_execution_overrides): they win
|
|
47
|
+
# over the app's own values and the NF_* environment variables
|
|
48
|
+
_EXECUTION_OVERRIDES: dict[str, object] = {}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def parallelism_options(command):
|
|
52
|
+
command = click.option("--quiet", is_flag=True, default=None, help="Hide per-resource progress; keep the final summary")(command)
|
|
53
|
+
command = click.option("--parallelism", type=click.IntRange(min=1), default=None, help="Maximum concurrent resource mutations (default 10; NF_MAX_CONCURRENT_RESOURCES)")(command)
|
|
54
|
+
return click.option("--read-parallelism", type=click.IntRange(min=1), default=None, help="Maximum concurrent refresh and plan calls (default 40; NF_MAX_CONCURRENT_READS)")(command)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def planning_options(command):
|
|
58
|
+
command = click.option("--refresh", type=bool, default=None, metavar="true|false", help="Refresh managed objects before planning (default true)")(command)
|
|
59
|
+
command = click.option("--target", "targets", multiple=True, metavar="ADDRESS", help="Plan this full resource address and its dependencies (repeatable)")(command)
|
|
60
|
+
return click.option("--plan-scope", type=click.Choice(["full", "changed"]), default=None, help="full inspects drift; changed inspects edited configurations and their dependency closure")(command)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def deferred_options[F: Callable[..., Any]](command: F) -> F:
|
|
64
|
+
"""The flags of the hybrid settings for deferred changes, provider data sources and deleted objects (see netherframe.core.config.hybrid_settings)."""
|
|
65
|
+
options = [
|
|
66
|
+
click.option(
|
|
67
|
+
"--concurrent-applies/--no-concurrent-applies",
|
|
68
|
+
default=None,
|
|
69
|
+
help="Use graph resource grants for pinned app/stack plans (default: off, NF_CONCURRENT_APPLIES); unsupported identities retain app-wide exclusion",
|
|
70
|
+
),
|
|
71
|
+
click.option(
|
|
72
|
+
"--apply-deferred/--no-apply-deferred",
|
|
73
|
+
default=None,
|
|
74
|
+
help="Plan and apply the changes a saved or auto-approved plan deferred, in the same run (default: off, NF_APPLY_DEFERRED)",
|
|
75
|
+
),
|
|
76
|
+
click.option(
|
|
77
|
+
"--deferred-approval",
|
|
78
|
+
type=click.Choice(DEFERRED_APPROVAL_MODES),
|
|
79
|
+
default=None,
|
|
80
|
+
help="How deferred rounds are approved: once (default), each_round, auto (needs --apply-deferred) or always (NF_DEFERRED_APPROVAL)",
|
|
81
|
+
),
|
|
82
|
+
click.option(
|
|
83
|
+
"--incomplete-exit-code",
|
|
84
|
+
type=int,
|
|
85
|
+
default=None,
|
|
86
|
+
help="Exit code when the apply succeeded but left deferred changes (default 2; 0 treats it as converged; NF_INCOMPLETE_EXIT_CODE)",
|
|
87
|
+
),
|
|
88
|
+
click.option(
|
|
89
|
+
"--provider-data-sources",
|
|
90
|
+
type=click.Choice(PROVIDER_DATA_SOURCE_MODES),
|
|
91
|
+
default=None,
|
|
92
|
+
help="read (default) the data sources provider settings refer to before configuring them, or take them from state (not recommended; NF_PROVIDER_DATA_SOURCES)",
|
|
93
|
+
),
|
|
94
|
+
click.option(
|
|
95
|
+
"--deleted-objects",
|
|
96
|
+
type=click.Choice(DELETED_OBJECT_MODES),
|
|
97
|
+
default=None,
|
|
98
|
+
help="Objects deleted outside Netherframe: review (default; re-created, refused under --auto-approve), recreate, or error (NF_DELETED_OBJECTS)",
|
|
99
|
+
),
|
|
100
|
+
provenance_option,
|
|
101
|
+
baseline_option,
|
|
102
|
+
prefer_mine_option,
|
|
103
|
+
graph_plan_scope_option,
|
|
104
|
+
parallelism_options,
|
|
105
|
+
planning_options,
|
|
106
|
+
]
|
|
107
|
+
for option in reversed(options):
|
|
108
|
+
command = option(command)
|
|
109
|
+
return command
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
# What `nf plan`, `nf apply` and `nf deploy` take to report what a run reads (see netherframe.core.execution.provenance_report)
|
|
113
|
+
provenance_option = click.option(
|
|
114
|
+
"--provenance-report/--no-provenance-report",
|
|
115
|
+
default=None,
|
|
116
|
+
help="Record what the plan or apply reads of state and report it, with what concurrent applies would have to lease (default: off, NF_PROVENANCE_REPORT)",
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
baseline_option = click.option("--baseline", help="Graph state origin: pinned reference file, commit sequence or run ID (default: nf.baseline when present)")
|
|
120
|
+
prefer_mine_option = click.option("--prefer-mine", multiple=True, metavar="ADDRESS", help="Resolve an intent conflict at this address using this branch's configuration (repeatable)")
|
|
121
|
+
graph_plan_scope_option = click.option("--graph-plan-scope", type=click.Choice(GRAPH_PLAN_SCOPES), default=None, help="full (default) or affected dependency closure; affected needs graph state and a retained baseline (NF_GRAPH_PLAN_SCOPE)")
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def print_provenance_report(report: object) -> None:
|
|
125
|
+
"""Render a plan's or apply's provenance report (``provenance_report``), when it has one."""
|
|
126
|
+
if not isinstance(report, dict):
|
|
127
|
+
return
|
|
128
|
+
if "error" in report:
|
|
129
|
+
console.print(f"[yellow]Provenance report could not be built: {escape(str(report['error']))}[/yellow]")
|
|
130
|
+
return
|
|
131
|
+
lines = report_lines(cast("dict[str, Any]", report))
|
|
132
|
+
console.print(f"[bold]{escape(lines[0])}[/bold]")
|
|
133
|
+
for line in lines[1:]:
|
|
134
|
+
console.print(f"[dim]{escape(line)}[/dim]")
|
|
135
|
+
console.print()
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def set_execution_overrides(**values: object) -> None:
|
|
139
|
+
"""Record the hybrid settings given as flags (None: not given), applied to every app ``get_direct_app_and_exec`` loads."""
|
|
140
|
+
_EXECUTION_OVERRIDES.clear()
|
|
141
|
+
_EXECUTION_OVERRIDES.update({name: value for name, value in values.items() if value is not None})
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def get_direct_app_and_exec(
|
|
145
|
+
app_name: str,
|
|
146
|
+
*,
|
|
147
|
+
outdir: str | None = None,
|
|
148
|
+
) -> HybridExecutionMode:
|
|
149
|
+
"""Get a configured app and attach direct execution.
|
|
150
|
+
|
|
151
|
+
This accepts either a hybrid app selector or a legacy app selector. The
|
|
152
|
+
underlying direct execution engine is the same hybrid/orchestration stack.
|
|
153
|
+
"""
|
|
154
|
+
project_config = load_project_config(allow_empty_apps=True)
|
|
155
|
+
hybrid_app_config = project_config.hybrid_apps
|
|
156
|
+
legacy_app_config = project_config.legacy_apps
|
|
157
|
+
|
|
158
|
+
if app_name in hybrid_app_config:
|
|
159
|
+
app_spec = hybrid_app_config[app_name]
|
|
160
|
+
elif app_name in legacy_app_config:
|
|
161
|
+
app_spec = legacy_app_config[app_name]
|
|
162
|
+
else:
|
|
163
|
+
raise click.ClickException(f"App '{app_name}' not found")
|
|
164
|
+
|
|
165
|
+
app = load_app_from_spec(app_spec)
|
|
166
|
+
|
|
167
|
+
direct_exec = getattr(app, "_hybrid_execution", None) or app.enable_hybrid_execution(outdir=outdir)
|
|
168
|
+
from netherframe.cli.services.graph_onboarding import attach_route
|
|
169
|
+
|
|
170
|
+
direct_exec = attach_route(direct_exec, app_name)
|
|
171
|
+
direct_exec.approval = cli_approval
|
|
172
|
+
for name, value in _EXECUTION_OVERRIDES.items():
|
|
173
|
+
if name not in {"parallelism", "read_parallelism", "quiet", "refresh", "targets", "plan_scope"}:
|
|
174
|
+
setattr(app, name, value)
|
|
175
|
+
limits = {name: value for name, value in _EXECUTION_OVERRIDES.items() if name in {"parallelism", "read_parallelism"}}
|
|
176
|
+
if limits:
|
|
177
|
+
direct_exec.configure_parallelism(**limits)
|
|
178
|
+
planning = {name: value for name, value in _EXECUTION_OVERRIDES.items() if name in {"refresh", "targets", "plan_scope"}}
|
|
179
|
+
if planning:
|
|
180
|
+
direct_exec.configure_planning(**planning)
|
|
181
|
+
direct_exec._progress_callback = None if _EXECUTION_OVERRIDES.get("quiet") or not getattr(app, "enable_progress_reporting", True) else cli_progress
|
|
182
|
+
return direct_exec
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def cli_progress(node, phase: str) -> None:
|
|
186
|
+
"""Resource addresses and status only; provider values may contain secrets."""
|
|
187
|
+
if node.action == "no-op":
|
|
188
|
+
return
|
|
189
|
+
elapsed = node.get_duration()
|
|
190
|
+
suffix = f" ({elapsed:.1f}s)" if elapsed is not None and phase != "starting" else ""
|
|
191
|
+
console.print(f"{node.resource_id}: {node.action} {phase}{suffix}", markup=False)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def incomplete_exit_code(result: object, direct_exec: object) -> int:
|
|
195
|
+
"""Report an apply that succeeded but left deferred changes; the exit code for it (0 when it converged).
|
|
196
|
+
|
|
197
|
+
As Terraform's detailed exit codes tell changes from none, CI tells a converged apply from a
|
|
198
|
+
partial one: ``incomplete_exit_code`` (2 by default; 0 to treat it as converged). The apply's
|
|
199
|
+
provenance report, when it has one, is shown first.
|
|
200
|
+
"""
|
|
201
|
+
print_provenance_report(getattr(result, "provenance_report", None))
|
|
202
|
+
if getattr(result, "success", False):
|
|
203
|
+
state = "complete" if getattr(result, "complete", True) else "incomplete"
|
|
204
|
+
console.print(f"Apply {state}: {getattr(result, 'completed', 0)} resources processed, {getattr(result, 'failed', 0)} failed.")
|
|
205
|
+
if getattr(result, "complete", True):
|
|
206
|
+
for warning in getattr(result, "warnings", ()) or ():
|
|
207
|
+
console.print(f"[yellow]{escape(str(warning))}[/yellow]")
|
|
208
|
+
if not getattr(result, "success", False) or getattr(result, "complete", True) is not False:
|
|
209
|
+
return 0
|
|
210
|
+
message = "Apply incomplete: entries need input reconciliation" if getattr(result, "stale_inputs", None) else "Apply incomplete: deferred changes were not applied"
|
|
211
|
+
console.print(f"\n[bold yellow]{message}[/bold yellow]")
|
|
212
|
+
for warning in getattr(result, "warnings", None) or []:
|
|
213
|
+
console.print(f" [yellow]{escape(str(warning))}[/yellow]")
|
|
214
|
+
for resource_id in getattr(result, "deferred", None) or []:
|
|
215
|
+
console.print(f" [cyan]~ {escape(str(resource_id))}[/cyan]")
|
|
216
|
+
code = getattr(getattr(direct_exec, "app", None), "incomplete_exit_code", 2)
|
|
217
|
+
return code if isinstance(code, int) else 2
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def exit_if_incomplete(code: int) -> None:
|
|
221
|
+
"""Exit with an incomplete apply's code, when one was incomplete and the code is not 0."""
|
|
222
|
+
if code:
|
|
223
|
+
sys.exit(code)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def print_output_changes(plan_summary: dict[str, Any]) -> None:
|
|
227
|
+
"""Render a plan summary's output changes, as Terraform shows them under "Changes to Outputs"."""
|
|
228
|
+
lines = output_change_lines(plan_summary)
|
|
229
|
+
if not lines:
|
|
230
|
+
return
|
|
231
|
+
console.print("[bold]Changes to Outputs:[/bold]")
|
|
232
|
+
for line in lines:
|
|
233
|
+
color = {"+": "green", "-": "red"}.get(line[0], "yellow")
|
|
234
|
+
console.print(f" [{color}]{escape(line)}[/{color}]")
|
|
235
|
+
if not _summary_int(plan_summary, "total_changes"):
|
|
236
|
+
console.print()
|
|
237
|
+
console.print("You can apply this plan to save these new output values to the state, without changing any real infrastructure.")
|
|
238
|
+
console.print()
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def print_deferred_changes(plan_summary: dict[str, Any]) -> None:
|
|
242
|
+
"""Render a plan summary's deferred changes: planned during apply, once their providers can be configured, and approved then."""
|
|
243
|
+
lines = deferred_change_lines(plan_summary)
|
|
244
|
+
if not lines:
|
|
245
|
+
return
|
|
246
|
+
console.print("[bold]Deferred changes[/bold] (planned during apply once their providers can be configured; approval follows the deferred policy):")
|
|
247
|
+
for line in lines:
|
|
248
|
+
console.print(f" [cyan]{escape(line)}[/cyan]")
|
|
249
|
+
console.print()
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def print_imports(plan_summary: dict[str, Any]) -> None:
|
|
253
|
+
"""Render a plan summary's imports (existing objects adopted into state), its objects not found to adopt, and adoption warnings."""
|
|
254
|
+
lines = import_lines(plan_summary)
|
|
255
|
+
if lines:
|
|
256
|
+
console.print(f"[bold]Imports[/bold] ({_summary_int(plan_summary, 'imports')} existing objects adopted into state; auto-approve does not approve them without --approve-imports):")
|
|
257
|
+
for line in lines[1:]:
|
|
258
|
+
console.print(f" [cyan]{escape(line.strip())}[/cyan]")
|
|
259
|
+
console.print()
|
|
260
|
+
not_found = plan_summary.get("adoption_not_found") or []
|
|
261
|
+
if not_found:
|
|
262
|
+
console.print(f"[bold]Not found to adopt[/bold] (created instead): {escape(', '.join(str(item) for item in not_found))}")
|
|
263
|
+
console.print()
|
|
264
|
+
for warning in plan_summary.get("adoption_warnings") or []:
|
|
265
|
+
console.print(f"[yellow]Warning:[/yellow] {escape(str(warning))}")
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def print_graph_baseline(plan_summary: dict[str, Any]) -> None:
|
|
269
|
+
"""Show which origin protects this graph plan from stale branch changes."""
|
|
270
|
+
graph = plan_summary.get("graph_state")
|
|
271
|
+
if not isinstance(graph, dict):
|
|
272
|
+
return
|
|
273
|
+
baseline = graph.get("baseline")
|
|
274
|
+
if isinstance(baseline, dict):
|
|
275
|
+
console.print(f"Graph baseline: sequence {baseline['sequence']}; keeping {len(graph.get('kept', []))} newer entries.")
|
|
276
|
+
else:
|
|
277
|
+
console.print("Graph plan: two-way (no baseline pinned; compares this configuration with current state).")
|
|
278
|
+
for key in graph.get("stale_inputs", ()):
|
|
279
|
+
console.print(f" Kept newer intent needs input reconciliation: {escape(str(key))}")
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def print_plan_counts(plan_summary: dict[str, Any]) -> bool:
|
|
283
|
+
"""Render a plan summary's counts and output changes; whether it holds changes to apply."""
|
|
284
|
+
scope = plan_summary.get("scope", {})
|
|
285
|
+
if scope.get("mode") == "changed" or scope.get("targets") or scope.get("refresh") is False:
|
|
286
|
+
console.print(
|
|
287
|
+
"Planning scope: "
|
|
288
|
+
+ str(scope.get("mode", "full"))
|
|
289
|
+
+ ("; selected targets and dependencies" if scope.get("targets") else "")
|
|
290
|
+
+ ("; refresh disabled" if scope.get("refresh") is False else "")
|
|
291
|
+
+ ". Unrelated drift may be uninspected.",
|
|
292
|
+
markup=False,
|
|
293
|
+
)
|
|
294
|
+
for reason in scope.get("fallback", ()):
|
|
295
|
+
console.print("Scope fallback: " + str(reason), markup=False)
|
|
296
|
+
print_graph_baseline(plan_summary)
|
|
297
|
+
for line in inspection_lines(plan_summary):
|
|
298
|
+
console.print(escape(line))
|
|
299
|
+
if not summary_has_changes(plan_summary):
|
|
300
|
+
console.print("[green]No changes required.[/green]")
|
|
301
|
+
print_imports(plan_summary)
|
|
302
|
+
print_provenance_report(plan_summary.get("provenance_report"))
|
|
303
|
+
return False
|
|
304
|
+
console.print("[bold]Plan Summary:[/bold]")
|
|
305
|
+
if imports := _summary_int(plan_summary, "imports"):
|
|
306
|
+
console.print(f" {imports} to import")
|
|
307
|
+
console.print(f" {plan_summary['creates']} to create")
|
|
308
|
+
console.print(f" {plan_summary['updates']} to update")
|
|
309
|
+
console.print(f" {plan_summary['deletes']} to delete")
|
|
310
|
+
for line in deleted_object_lines(plan_summary):
|
|
311
|
+
console.print(" " + escape(line))
|
|
312
|
+
console.print(f" Total: {plan_summary['total_changes']} changes")
|
|
313
|
+
if deferred := _summary_int(plan_summary, "deferred"):
|
|
314
|
+
console.print(f" {deferred} deferred")
|
|
315
|
+
console.print()
|
|
316
|
+
print_imports(plan_summary)
|
|
317
|
+
print_output_changes(plan_summary)
|
|
318
|
+
print_deferred_changes(plan_summary)
|
|
319
|
+
print_provenance_report(plan_summary.get("provenance_report"))
|
|
320
|
+
return True
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def print_plan_summary(plan_summary: dict[str, Any]) -> None:
|
|
324
|
+
"""Render a hybrid plan summary: its resource changes by stack, then its output changes."""
|
|
325
|
+
print_graph_baseline(plan_summary)
|
|
326
|
+
for line in inspection_lines(plan_summary):
|
|
327
|
+
console.print(escape(line))
|
|
328
|
+
unknown_state_resources = _summary_int(plan_summary, "unknown_state_resources")
|
|
329
|
+
|
|
330
|
+
if not summary_has_changes(plan_summary) and unknown_state_resources == 0:
|
|
331
|
+
console.print("[green]No changes required.[/green]")
|
|
332
|
+
print_imports(plan_summary)
|
|
333
|
+
return
|
|
334
|
+
|
|
335
|
+
console.print("[bold]Plan Summary:[/bold]")
|
|
336
|
+
if imports := _summary_int(plan_summary, "imports"):
|
|
337
|
+
console.print(f" {imports} to import")
|
|
338
|
+
console.print(f" {plan_summary['creates']} to create")
|
|
339
|
+
console.print(f" {plan_summary['updates']} to update")
|
|
340
|
+
console.print(f" {plan_summary['deletes']} to delete")
|
|
341
|
+
console.print(f" Total: {plan_summary['total_changes']} changes")
|
|
342
|
+
if reads := _summary_int(plan_summary, "reads"):
|
|
343
|
+
console.print(f" {reads} data sources to read during apply")
|
|
344
|
+
if deferred := _summary_int(plan_summary, "deferred"):
|
|
345
|
+
console.print(f" {deferred} deferred until their providers can be configured")
|
|
346
|
+
drift_detected = _summary_int(plan_summary, "drift_detected")
|
|
347
|
+
if drift_detected:
|
|
348
|
+
console.print(f" Drift detected: {drift_detected} resources")
|
|
349
|
+
drift_only_changes = _summary_int(plan_summary, "drift_only_changes")
|
|
350
|
+
if drift_only_changes:
|
|
351
|
+
console.print(f" Drift-only actions: {drift_only_changes}")
|
|
352
|
+
refresh_failures = _summary_int(plan_summary, "refresh_failures")
|
|
353
|
+
refresh_timeouts = _summary_int(plan_summary, "refresh_timeouts")
|
|
354
|
+
compatibility_failures = _summary_int(plan_summary, "compatibility_failures")
|
|
355
|
+
upgraded_state_resources = _summary_int(plan_summary, "upgraded_state_resources")
|
|
356
|
+
if refresh_failures or refresh_timeouts or unknown_state_resources:
|
|
357
|
+
console.print(
|
|
358
|
+
f" Refresh diagnostics: {refresh_failures} failures, {refresh_timeouts} timeouts, {unknown_state_resources} unknown",
|
|
359
|
+
)
|
|
360
|
+
if compatibility_failures:
|
|
361
|
+
console.print(f" Compatibility failures: {compatibility_failures}")
|
|
362
|
+
if upgraded_state_resources:
|
|
363
|
+
console.print(f" Upgraded stored state: {upgraded_state_resources} resources")
|
|
364
|
+
runtime_check_review_resources = _summary_int(plan_summary, "runtime_check_review_resources")
|
|
365
|
+
if runtime_check_review_resources:
|
|
366
|
+
console.print(f" Deferred runtime checks: {runtime_check_review_resources}")
|
|
367
|
+
for line in deleted_object_lines(plan_summary):
|
|
368
|
+
console.print(" " + escape(line))
|
|
369
|
+
if _summary_flag(plan_summary, "requires_refresh_review"):
|
|
370
|
+
reason = "objects were deleted outside Netherframe" if plan_summary.get("deleted_outside_resources") else "some refreshed state is unknown"
|
|
371
|
+
console.print(f" Review required before apply because {reason}")
|
|
372
|
+
plan_id = plan_summary.get("plan_id")
|
|
373
|
+
if plan_id:
|
|
374
|
+
console.print(f" Plan ID: {plan_id}")
|
|
375
|
+
console.print()
|
|
376
|
+
|
|
377
|
+
stacks = plan_summary.get("stacks", {})
|
|
378
|
+
for stack_name, changes in stacks.items() if isinstance(stacks, dict) else ():
|
|
379
|
+
console.print(f"[bold]Stack: {stack_name}[/bold]")
|
|
380
|
+
if not isinstance(changes, list):
|
|
381
|
+
continue
|
|
382
|
+
for change in changes:
|
|
383
|
+
if not isinstance(change, dict):
|
|
384
|
+
continue
|
|
385
|
+
action = str(_change_value(change, "action", "unknown"))
|
|
386
|
+
action_color = {
|
|
387
|
+
"create": "green",
|
|
388
|
+
"update": "yellow",
|
|
389
|
+
"delete": "red",
|
|
390
|
+
"import": "cyan",
|
|
391
|
+
}.get(action, "white")
|
|
392
|
+
console.print(
|
|
393
|
+
f" [{action_color}]{action:8}[/{action_color}] {_change_value(change, 'resource', '<unknown>')}",
|
|
394
|
+
)
|
|
395
|
+
description = _change_value(change, "description")
|
|
396
|
+
if description:
|
|
397
|
+
console.print(f" {description}")
|
|
398
|
+
imported_by = _change_value(change, "import")
|
|
399
|
+
if imported_by:
|
|
400
|
+
console.print(f" Adopts the existing object ({escape(str(imported_by))})")
|
|
401
|
+
known_after_apply = _change_value(change, "known_after_apply")
|
|
402
|
+
if isinstance(known_after_apply, list):
|
|
403
|
+
for path in known_after_apply:
|
|
404
|
+
console.print(f" {escape(str(path))} = [dim]{KNOWN_AFTER_APPLY}[/dim]")
|
|
405
|
+
if _change_value(change, "drift_only") is True:
|
|
406
|
+
console.print(" Drift-only correction")
|
|
407
|
+
elif _change_value(change, "drift_detected") is True:
|
|
408
|
+
console.print(" Includes refresh-detected drift")
|
|
409
|
+
replacement_reasons = _change_value(change, "replacement_reasons")
|
|
410
|
+
if isinstance(replacement_reasons, list) and replacement_reasons:
|
|
411
|
+
console.print(f" Replacement reasons: {', '.join(str(item) for item in replacement_reasons)}")
|
|
412
|
+
lifecycle_blockers = _change_value(change, "lifecycle_blockers")
|
|
413
|
+
if isinstance(lifecycle_blockers, list):
|
|
414
|
+
for blocker in lifecycle_blockers:
|
|
415
|
+
console.print(f" Blocked: {blocker}")
|
|
416
|
+
runtime_check_results = _change_value(change, "runtime_check_results")
|
|
417
|
+
if isinstance(runtime_check_results, list):
|
|
418
|
+
for outcome in runtime_check_results:
|
|
419
|
+
if not isinstance(outcome, dict):
|
|
420
|
+
continue
|
|
421
|
+
if _change_value(outcome, "status") != "deferred":
|
|
422
|
+
continue
|
|
423
|
+
console.print(
|
|
424
|
+
f" Deferred runtime check: {_change_value(outcome, 'detail', 'review required')}",
|
|
425
|
+
)
|
|
426
|
+
console.print()
|
|
427
|
+
|
|
428
|
+
print_output_changes(plan_summary)
|
|
429
|
+
print_deferred_changes(plan_summary)
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
def show_plan_artifact(plan_file: Path) -> None:
|
|
433
|
+
"""Print a saved plan artifact and its provider fingerprints."""
|
|
434
|
+
artifact = load_plan_artifact(plan_file)
|
|
435
|
+
console.print("[bold blue]Saved Plan[/bold blue]\n")
|
|
436
|
+
print_plan_summary(artifact.to_summary())
|
|
437
|
+
if artifact.provider_fingerprints:
|
|
438
|
+
console.print("[bold]Provider Fingerprints:[/bold]")
|
|
439
|
+
for fingerprint in artifact.provider_fingerprints:
|
|
440
|
+
console.print(
|
|
441
|
+
f" {fingerprint.stable_key} @ {fingerprint.version} [{fingerprint.config_fingerprint[:12]}]",
|
|
442
|
+
)
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
def print_result_errors(result: object) -> None:
|
|
446
|
+
"""Print the reasons an ExecutionResult failed (lock contention, stale plan, errors)."""
|
|
447
|
+
for error in getattr(result, "errors", None) or []:
|
|
448
|
+
console.print(f" [red]- {error}[/red]")
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
def cli_approval(request: ApprovalRequest) -> bool:
|
|
452
|
+
"""Render an approval request in the terminal; only an explicit 'yes' proceeds."""
|
|
453
|
+
console.print(f"\n[bold]{request.title}[/bold]")
|
|
454
|
+
for line in request.details:
|
|
455
|
+
console.print(line)
|
|
456
|
+
if request.remaining_seconds is None:
|
|
457
|
+
answer = click.prompt(f"\n{request.question} Only 'yes' will be accepted", default="", show_default=False)
|
|
458
|
+
else:
|
|
459
|
+
console.print(f"Approval expires in {request.remaining_seconds:.0f} seconds.")
|
|
460
|
+
answer = approval_input(request, f"\n{request.question} Only 'yes' will be accepted: ")
|
|
461
|
+
return answer.strip().lower() == "yes"
|