maproom 0.2.0__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.
- maproom/__init__.py +14 -0
- maproom/__main__.py +10 -0
- maproom/analyze/__init__.py +1 -0
- maproom/analyze/accel_families.py +45 -0
- maproom/analyze/account_azure_activity.py +260 -0
- maproom/analyze/account_azure_quota_requests.py +177 -0
- maproom/analyze/account_cloudtrail.py +316 -0
- maproom/analyze/account_quota_requests.py +180 -0
- maproom/analyze/analyze_v1_orchestration.py +1194 -0
- maproom/analyze/catalog.py +353 -0
- maproom/analyze/change_detection.py +652 -0
- maproom/analyze/context_client.py +99 -0
- maproom/analyze/context_lookup.py +142 -0
- maproom/analyze/cover_analyze.py +344 -0
- maproom/analyze/cover_client.py +65 -0
- maproom/analyze/cover_lookup.py +242 -0
- maproom/analyze/engine.py +644 -0
- maproom/analyze/fleetfit_endpoints.py +217 -0
- maproom/analyze/fleetfit_policy.py +66 -0
- maproom/analyze/instance_price_analyze.py +221 -0
- maproom/analyze/instance_price_client.py +108 -0
- maproom/analyze/instance_price_lookup.py +60 -0
- maproom/analyze/local_reads.py +484 -0
- maproom/analyze/lookup_http.py +280 -0
- maproom/analyze/metric_format.py +20 -0
- maproom/analyze/migration_method.py +130 -0
- maproom/analyze/move_list.py +93 -0
- maproom/analyze/operator_context.py +156 -0
- maproom/analyze/performance_rank.py +97 -0
- maproom/analyze/primary_recommendation.py +422 -0
- maproom/analyze/provider_comparison.py +401 -0
- maproom/analyze/quota_analyze.py +481 -0
- maproom/analyze/quota_client.py +75 -0
- maproom/analyze/quota_lookup.py +110 -0
- maproom/analyze/quota_outcome_steer.py +105 -0
- maproom/analyze/recommend_batch.py +199 -0
- maproom/analyze/recommend_client.py +362 -0
- maproom/analyze/recommend_share.py +118 -0
- maproom/analyze/recommendation.py +591 -0
- maproom/analyze/reservation_pack.py +883 -0
- maproom/analyze/reservation_read.py +461 -0
- maproom/analyze/safe_analyze.py +1134 -0
- maproom/analyze/safe_move.py +195 -0
- maproom/analyze/safe_moves.py +571 -0
- maproom/analyze/safe_moves_catalog.py +127 -0
- maproom/analyze/safe_moves_client.py +70 -0
- maproom/analyze/series_analyze.py +491 -0
- maproom/analyze/series_client.py +106 -0
- maproom/analyze/series_lookup.py +663 -0
- maproom/analyze/shape.py +254 -0
- maproom/analyze/size_analyze.py +883 -0
- maproom/analyze/size_client.py +81 -0
- maproom/analyze/size_keep.py +409 -0
- maproom/analyze/size_lookup.py +368 -0
- maproom/analyze/specs.py +325 -0
- maproom/analyze/spot_analyze.py +392 -0
- maproom/analyze/spot_client.py +74 -0
- maproom/analyze/spot_lookup.py +213 -0
- maproom/analyze/token_client.py +97 -0
- maproom/analyze/utilization.py +190 -0
- maproom/analyze/workload.py +104 -0
- maproom/analyze/workset.py +762 -0
- maproom/aws_region.py +78 -0
- maproom/cache/__init__.py +1 -0
- maproom/cache/catalog.py +372 -0
- maproom/cache/commands.py +215 -0
- maproom/cache/instances.py +460 -0
- maproom/cli.py +2084 -0
- maproom/cli_argv.py +329 -0
- maproom/cli_floors.py +89 -0
- maproom/cliio/__init__.py +1 -0
- maproom/cliio/registry.py +377 -0
- maproom/cliio/runner.py +489 -0
- maproom/consent/__init__.py +33 -0
- maproom/consent/gate.py +238 -0
- maproom/consent/policy.py +20 -0
- maproom/consent/prompt.py +61 -0
- maproom/consent/service_upload_gate.py +318 -0
- maproom/consent/service_upload_prompt.py +62 -0
- maproom/consent/stdin.py +45 -0
- maproom/consent/storage.py +24 -0
- maproom/consent/write_token.py +29 -0
- maproom/contracts/__init__.py +6 -0
- maproom/contracts/schema_diff.py +119 -0
- maproom/contracts/validate.py +113 -0
- maproom/data/__init__.py +1 -0
- maproom/data/clear.py +76 -0
- maproom/data/commands.py +14 -0
- maproom/doctor/__init__.py +1 -0
- maproom/doctor/aws_session.py +226 -0
- maproom/doctor/checks.py +701 -0
- maproom/doctor/context.py +32 -0
- maproom/doctor/display.py +96 -0
- maproom/doctor/inventory_display.py +377 -0
- maproom/doctor/runner.py +1467 -0
- maproom/errors.py +43 -0
- maproom/exitcodes.py +70 -0
- maproom/inventory/__init__.py +1 -0
- maproom/inventory/account_identity.py +79 -0
- maproom/inventory/accounts.py +155 -0
- maproom/inventory/command.py +961 -0
- maproom/inventory/messages.py +264 -0
- maproom/inventory/reservations_refresh.py +37 -0
- maproom/mock_environment/__init__.py +28 -0
- maproom/mock_environment/load.py +241 -0
- maproom/mock_environment/runner.py +387 -0
- maproom/output/__init__.py +1 -0
- maproom/output/json_envelope.py +241 -0
- maproom/output/redact.py +11 -0
- maproom/output/terminal.py +129 -0
- maproom/parsers.py +284 -0
- maproom/paths.py +105 -0
- maproom/plan/__init__.py +1 -0
- maproom/plan/accept.py +59 -0
- maproom/plan/analysis_context.py +78 -0
- maproom/plan/analyze_selection.py +279 -0
- maproom/plan/commands.py +586 -0
- maproom/plan/current.py +59 -0
- maproom/plan/errors.py +10 -0
- maproom/plan/export.py +36 -0
- maproom/plan/formatting.py +91 -0
- maproom/plan/ids.py +13 -0
- maproom/plan/migration_options.py +75 -0
- maproom/plan/model.py +265 -0
- maproom/plan/names.py +24 -0
- maproom/plan/store.py +193 -0
- maproom/plan/tty.py +34 -0
- maproom/pricing/__init__.py +5 -0
- maproom/pricing/prices.py +119 -0
- maproom/privacy/__init__.py +6 -0
- maproom/privacy/commands.py +159 -0
- maproom/privacy/delete_uploads.py +204 -0
- maproom/privacy/fleetfit_policy.py +125 -0
- maproom/privacy/fleetfit_statement.py +104 -0
- maproom/privacy/format.py +76 -0
- maproom/privacy/manifests.py +342 -0
- maproom/privacy/statement.py +58 -0
- maproom/quotas/__init__.py +21 -0
- maproom/quotas/aws.py +204 -0
- maproom/quotas/azure.py +75 -0
- maproom/quotas/commands.py +240 -0
- maproom/quotas/family_coverage.py +122 -0
- maproom/quotas/fetch.py +124 -0
- maproom/quotas/load.py +41 -0
- maproom/quotas/model.py +178 -0
- maproom/quotas/outcome_ledger.py +245 -0
- maproom/quotas/quota_request_sync.py +221 -0
- maproom/quotas/show.py +73 -0
- maproom/quotas/status.py +206 -0
- maproom/quotas/store.py +161 -0
- maproom/redaction.py +157 -0
- maproom/reference_data/__init__.py +1 -0
- maproom/reference_data/aws/aws_prices.csv +25562 -0
- maproom/reference_data/aws/capabilities.csv +1346 -0
- maproom/reference_data/aws/instance_types.csv +1346 -0
- maproom/reference_data/azure/azure_prices.csv +1 -0
- maproom/reference_data/azure/vm_types.csv +1 -0
- maproom/reference_data/benchmarks/cpu-lscpu-v2-instances.json +27 -0
- maproom/reference_data/benchmarks/safe-moves-v1.json +328 -0
- maproom/reference_data/manifest.json +174 -0
- maproom/reference_data/manifest.py +69 -0
- maproom/reservations/__init__.py +17 -0
- maproom/reservations/aws.py +76 -0
- maproom/reservations/azure.py +36 -0
- maproom/reservations/commands.py +149 -0
- maproom/reservations/load.py +41 -0
- maproom/reservations/model.py +316 -0
- maproom/reservations/show.py +64 -0
- maproom/reservations/status.py +181 -0
- maproom/reservations/store.py +391 -0
- maproom/resources.py +54 -0
- maproom/root_help.py +251 -0
- maproom/saving_plans/__init__.py +15 -0
- maproom/saving_plans/aws.py +73 -0
- maproom/saving_plans/commands.py +122 -0
- maproom/saving_plans/load.py +41 -0
- maproom/saving_plans/model.py +101 -0
- maproom/saving_plans/show.py +64 -0
- maproom/saving_plans/status.py +118 -0
- maproom/saving_plans/store.py +173 -0
- maproom/secret_egress_gate.py +108 -0
- maproom/service/install_id.py +60 -0
- maproom/settings/__init__.py +1 -0
- maproom/settings/defaults.py +73 -0
- maproom/settings/init.py +143 -0
- maproom/settings/model.py +105 -0
- maproom/settings/product_version_change.py +343 -0
- maproom/settings/product_versions.py +68 -0
- maproom/settings/set.py +347 -0
- maproom/settings/show.py +227 -0
- maproom/settings/write.py +273 -0
- maproom/snapshot_time.py +27 -0
- maproom-0.2.0.dist-info/METADATA +263 -0
- maproom-0.2.0.dist-info/RECORD +199 -0
- maproom-0.2.0.dist-info/WHEEL +5 -0
- maproom-0.2.0.dist-info/entry_points.txt +2 -0
- maproom-0.2.0.dist-info/licenses/LICENSE +201 -0
- maproom-0.2.0.dist-info/licenses/NOTICE +72 -0
- maproom-0.2.0.dist-info/top_level.txt +1 -0
maproom/cli_argv.py
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
"""argv normalization for global flags, command case, and legacy plan syntax."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import re
|
|
8
|
+
|
|
9
|
+
from maproom.output.json_envelope import build_error_document
|
|
10
|
+
from maproom.redaction import redact_tree
|
|
11
|
+
from maproom.settings.set import settings_set_remediation_hint
|
|
12
|
+
|
|
13
|
+
_ROOT_FLAGS_WITH_VALUE: frozenset[str] = frozenset()
|
|
14
|
+
_ROOT_BOOLEAN_FLAGS: frozenset[str] = frozenset(
|
|
15
|
+
{"--json", "-h", "--help", "--version"}
|
|
16
|
+
)
|
|
17
|
+
_BOOLEAN_FLAGS: frozenset[str] = frozenset(
|
|
18
|
+
{
|
|
19
|
+
"--json",
|
|
20
|
+
"--force",
|
|
21
|
+
"--all",
|
|
22
|
+
"--no-color",
|
|
23
|
+
"--color",
|
|
24
|
+
"--local-only",
|
|
25
|
+
"--create",
|
|
26
|
+
"--consent-cloud-reads",
|
|
27
|
+
"--consent-fleetfit-recommendations",
|
|
28
|
+
"--launch-relevant",
|
|
29
|
+
"--include-consent-text",
|
|
30
|
+
"--redact-identity",
|
|
31
|
+
"-h",
|
|
32
|
+
"--help",
|
|
33
|
+
}
|
|
34
|
+
)
|
|
35
|
+
_VALUE_FLAGS: frozenset[str] = frozenset(
|
|
36
|
+
{
|
|
37
|
+
"--region",
|
|
38
|
+
"--location",
|
|
39
|
+
"--cloud",
|
|
40
|
+
"--format",
|
|
41
|
+
"--accept",
|
|
42
|
+
"--shape",
|
|
43
|
+
"--reservation-pack",
|
|
44
|
+
"--share",
|
|
45
|
+
"--omit",
|
|
46
|
+
"--recommend-kinds",
|
|
47
|
+
}
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
COMMANDS: dict[str, frozenset[str]] = {
|
|
51
|
+
"doctor": frozenset(),
|
|
52
|
+
"identity": frozenset(),
|
|
53
|
+
"version": frozenset(),
|
|
54
|
+
"inventory": frozenset({"get", "status", "clear", "load"}),
|
|
55
|
+
"analyze": frozenset(),
|
|
56
|
+
"plan": frozenset({"list", "show", "use", "create", "export", "remove", "clear"}),
|
|
57
|
+
"data": frozenset({"clear"}),
|
|
58
|
+
"settings": frozenset({"init", "set"}),
|
|
59
|
+
"privacy": frozenset({"analyze", "doctor", "inventory", "fleetfit"}),
|
|
60
|
+
"help": frozenset(
|
|
61
|
+
{
|
|
62
|
+
"doctor",
|
|
63
|
+
"identity",
|
|
64
|
+
"version",
|
|
65
|
+
"inventory",
|
|
66
|
+
"analyze",
|
|
67
|
+
"plan",
|
|
68
|
+
"data",
|
|
69
|
+
"settings",
|
|
70
|
+
"privacy",
|
|
71
|
+
"help",
|
|
72
|
+
}
|
|
73
|
+
),
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
_CHOICE_RE = re.compile(r"invalid choice: '([^']*)'")
|
|
77
|
+
|
|
78
|
+
_PREPARED_ARGV: list[str] = []
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
_LONG_FLAGS: frozenset[str] = _BOOLEAN_FLAGS | _VALUE_FLAGS | _ROOT_BOOLEAN_FLAGS
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def prepare_argv(argv: list[str]) -> list[str]:
|
|
85
|
+
promoted = _promote_single_dash_long_flags(list(argv))
|
|
86
|
+
folded = _fold_case(promoted)
|
|
87
|
+
plan = _rewrite_legacy_plan(folded)
|
|
88
|
+
prepared = _rewrite_analyze(plan)
|
|
89
|
+
global _PREPARED_ARGV
|
|
90
|
+
_PREPARED_ARGV = prepared
|
|
91
|
+
return prepared
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def prepared_argv_has_json() -> bool:
|
|
95
|
+
"""True when the current prepared argv includes ``--json``."""
|
|
96
|
+
return "--json" in _PREPARED_ARGV
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def prepared_invoked_command() -> str | None:
|
|
100
|
+
"""Top-level maproom subcommand from the current prepared argv, if any."""
|
|
101
|
+
for token in _PREPARED_ARGV:
|
|
102
|
+
if token in COMMANDS:
|
|
103
|
+
return token
|
|
104
|
+
return None
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _promote_single_dash_long_flags(argv: list[str]) -> list[str]:
|
|
108
|
+
"""Treat ``-all`` as ``--all`` when that long option exists."""
|
|
109
|
+
promoted: list[str] = []
|
|
110
|
+
for token in argv:
|
|
111
|
+
if token.startswith("-") and not token.startswith("--") and len(token) > 2:
|
|
112
|
+
long_form = f"-{token}"
|
|
113
|
+
name, sep, value = long_form.partition("=")
|
|
114
|
+
if name in _LONG_FLAGS:
|
|
115
|
+
promoted.append(f"{name}={value}" if sep else name)
|
|
116
|
+
continue
|
|
117
|
+
promoted.append(token)
|
|
118
|
+
return promoted
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _fold_case(argv: list[str]) -> list[str]:
|
|
122
|
+
command_index = _first_positional(argv, boolean=_ROOT_BOOLEAN_FLAGS, valued=_ROOT_FLAGS_WITH_VALUE)
|
|
123
|
+
if command_index is None:
|
|
124
|
+
return argv
|
|
125
|
+
command = argv[command_index]
|
|
126
|
+
canonical = command.lower()
|
|
127
|
+
if canonical not in COMMANDS:
|
|
128
|
+
return argv
|
|
129
|
+
argv[command_index] = canonical
|
|
130
|
+
sub_index = _first_positional(
|
|
131
|
+
argv[command_index + 1 :],
|
|
132
|
+
boolean=_BOOLEAN_FLAGS,
|
|
133
|
+
valued=_VALUE_FLAGS,
|
|
134
|
+
)
|
|
135
|
+
if sub_index is None:
|
|
136
|
+
return argv
|
|
137
|
+
absolute = command_index + 1 + sub_index
|
|
138
|
+
sub = argv[absolute]
|
|
139
|
+
if sub.lower() in COMMANDS[canonical]:
|
|
140
|
+
argv[absolute] = sub.lower()
|
|
141
|
+
return argv
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _first_positional(
|
|
145
|
+
argv: list[str],
|
|
146
|
+
*,
|
|
147
|
+
boolean: frozenset[str],
|
|
148
|
+
valued: frozenset[str],
|
|
149
|
+
) -> int | None:
|
|
150
|
+
index = 0
|
|
151
|
+
while index < len(argv):
|
|
152
|
+
token = argv[index]
|
|
153
|
+
if token == "--":
|
|
154
|
+
next_index = index + 1
|
|
155
|
+
return next_index if next_index < len(argv) else None
|
|
156
|
+
if token in boolean:
|
|
157
|
+
index += 1
|
|
158
|
+
continue
|
|
159
|
+
if token in valued or any(token.startswith(f"{flag}=") for flag in valued):
|
|
160
|
+
if "=" not in token and token in valued:
|
|
161
|
+
index += 2
|
|
162
|
+
else:
|
|
163
|
+
index += 1
|
|
164
|
+
continue
|
|
165
|
+
if token.startswith("-"):
|
|
166
|
+
index += 1
|
|
167
|
+
continue
|
|
168
|
+
return index
|
|
169
|
+
return None
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _rewrite_legacy_plan(argv: list[str]) -> list[str]:
|
|
173
|
+
command_index = _first_positional(
|
|
174
|
+
argv, boolean=_ROOT_BOOLEAN_FLAGS, valued=_ROOT_FLAGS_WITH_VALUE
|
|
175
|
+
)
|
|
176
|
+
if command_index is None or argv[command_index] != "plan":
|
|
177
|
+
return argv
|
|
178
|
+
head = argv[: command_index + 1]
|
|
179
|
+
rest = argv[command_index + 1 :]
|
|
180
|
+
flags: list[str] = []
|
|
181
|
+
positionals: list[str] = []
|
|
182
|
+
index = 0
|
|
183
|
+
while index < len(rest):
|
|
184
|
+
token = rest[index]
|
|
185
|
+
if token in _BOOLEAN_FLAGS:
|
|
186
|
+
flags.append(token)
|
|
187
|
+
index += 1
|
|
188
|
+
continue
|
|
189
|
+
if token in _VALUE_FLAGS and index + 1 < len(rest):
|
|
190
|
+
flags.extend((token, rest[index + 1]))
|
|
191
|
+
index += 2
|
|
192
|
+
continue
|
|
193
|
+
if any(token.startswith(f"{flag}=") for flag in _VALUE_FLAGS):
|
|
194
|
+
flags.append(token)
|
|
195
|
+
index += 1
|
|
196
|
+
continue
|
|
197
|
+
if token.startswith("-"):
|
|
198
|
+
flags.append(token)
|
|
199
|
+
index += 1
|
|
200
|
+
continue
|
|
201
|
+
positionals.append(token)
|
|
202
|
+
index += 1
|
|
203
|
+
if not positionals:
|
|
204
|
+
return head + flags
|
|
205
|
+
if positionals[0] in COMMANDS["plan"]:
|
|
206
|
+
return head + positionals + flags
|
|
207
|
+
if "--create" in flags:
|
|
208
|
+
kept = [flag for flag in flags if flag != "--create"]
|
|
209
|
+
return head + ["create", positionals[0], *kept, *positionals[1:]]
|
|
210
|
+
if len(positionals) >= 2 and positionals[1] == "clear":
|
|
211
|
+
return head + ["clear", positionals[0], *flags, *positionals[2:]]
|
|
212
|
+
return head + positionals + flags
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def _rewrite_analyze(argv: list[str]) -> list[str]:
|
|
216
|
+
"""Move analyze flags after selectors so region and *text work in either order."""
|
|
217
|
+
command_index = _first_positional(
|
|
218
|
+
argv, boolean=_ROOT_BOOLEAN_FLAGS, valued=_ROOT_FLAGS_WITH_VALUE
|
|
219
|
+
)
|
|
220
|
+
if command_index is None or argv[command_index] != "analyze":
|
|
221
|
+
return argv
|
|
222
|
+
head = argv[: command_index + 1]
|
|
223
|
+
rest = argv[command_index + 1 :]
|
|
224
|
+
flags: list[str] = []
|
|
225
|
+
positionals: list[str] = []
|
|
226
|
+
index = 0
|
|
227
|
+
while index < len(rest):
|
|
228
|
+
token = rest[index]
|
|
229
|
+
if token in _BOOLEAN_FLAGS:
|
|
230
|
+
flags.append(token)
|
|
231
|
+
index += 1
|
|
232
|
+
continue
|
|
233
|
+
if token in _VALUE_FLAGS and index + 1 < len(rest):
|
|
234
|
+
flags.extend((token, rest[index + 1]))
|
|
235
|
+
index += 2
|
|
236
|
+
continue
|
|
237
|
+
if any(token.startswith(f"{flag}=") for flag in _VALUE_FLAGS):
|
|
238
|
+
flags.append(token)
|
|
239
|
+
index += 1
|
|
240
|
+
continue
|
|
241
|
+
if token.startswith("-"):
|
|
242
|
+
flags.append(token)
|
|
243
|
+
index += 1
|
|
244
|
+
continue
|
|
245
|
+
positionals.append(token)
|
|
246
|
+
index += 1
|
|
247
|
+
return head + positionals + flags
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
class MaproomArgumentParser(argparse.ArgumentParser):
|
|
251
|
+
"""Usage errors name the fix instead of dumping the parser synopsis."""
|
|
252
|
+
|
|
253
|
+
def error(self, message: str) -> None:
|
|
254
|
+
text, hint = _friendly_error(self.prog, message)
|
|
255
|
+
if prepared_argv_has_json():
|
|
256
|
+
doc = build_error_document(
|
|
257
|
+
"usage",
|
|
258
|
+
text,
|
|
259
|
+
invoked=_invoked_from_prog(self.prog),
|
|
260
|
+
hint=hint,
|
|
261
|
+
)
|
|
262
|
+
print(
|
|
263
|
+
json.dumps(redact_tree(doc), indent=2, ensure_ascii=False),
|
|
264
|
+
)
|
|
265
|
+
self.exit(2)
|
|
266
|
+
self.exit(2, f"error: {text}\nhint: {hint}\n")
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def _invoked_from_prog(prog: str) -> str:
|
|
270
|
+
parts = prog.split()
|
|
271
|
+
if not parts or parts[0] != "maproom":
|
|
272
|
+
return prog
|
|
273
|
+
return " ".join(parts[1:])
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def _friendly_error(prog: str, message: str) -> tuple[str, str]:
|
|
277
|
+
choice = _CHOICE_RE.search(message)
|
|
278
|
+
if "data_command" in message:
|
|
279
|
+
return ('choose a data command: clear', "maproom data clear")
|
|
280
|
+
if "cache_command" in message:
|
|
281
|
+
return ('choose a cache command: show or clear', "maproom cache clear aws*")
|
|
282
|
+
if prog.endswith("plan use"):
|
|
283
|
+
if "required: name" in message:
|
|
284
|
+
return (
|
|
285
|
+
"the following arguments are required: name",
|
|
286
|
+
"maproom plan use NAME (run maproom plan -h)",
|
|
287
|
+
)
|
|
288
|
+
return (message, "maproom plan -h")
|
|
289
|
+
if prog.endswith("plan") or ".plan." in prog or prog.endswith(" plan"):
|
|
290
|
+
return (message, "maproom plan -h")
|
|
291
|
+
if choice and prog.endswith("plan"):
|
|
292
|
+
name = choice.group(1)
|
|
293
|
+
return (
|
|
294
|
+
f'plan "{name}" does not exist',
|
|
295
|
+
f"maproom plan create {name}",
|
|
296
|
+
)
|
|
297
|
+
if choice and "argument command:" in message:
|
|
298
|
+
name = choice.group(1)
|
|
299
|
+
if name in {"quotas", "reservations", "saving-plans", "savings-plans"}:
|
|
300
|
+
return (
|
|
301
|
+
f'"{name}" is part of inventory',
|
|
302
|
+
"maproom inventory get",
|
|
303
|
+
)
|
|
304
|
+
return (f'unknown command "{name}"', 'run "maproom -h"')
|
|
305
|
+
if "inventory_command" in message:
|
|
306
|
+
return (
|
|
307
|
+
"choose an inventory command: status, get, clear, or load",
|
|
308
|
+
"maproom inventory get",
|
|
309
|
+
)
|
|
310
|
+
if "required: resource" in message:
|
|
311
|
+
return (
|
|
312
|
+
message,
|
|
313
|
+
"maproom analyze i-0123456789abcdef0 --region us-east-1",
|
|
314
|
+
)
|
|
315
|
+
if prog.endswith("settings set") and "required" in message:
|
|
316
|
+
return (message, settings_set_remediation_hint())
|
|
317
|
+
if message.startswith("unrecognized arguments:"):
|
|
318
|
+
token = message.split(":", 1)[1].strip().split()[0]
|
|
319
|
+
if token.startswith("-") and not token.startswith("--"):
|
|
320
|
+
long_form = f"-{token.split('=', 1)[0]}"
|
|
321
|
+
if long_form in _LONG_FLAGS:
|
|
322
|
+
return (message, f"use {long_form}")
|
|
323
|
+
if (
|
|
324
|
+
prog == "maproom doctor"
|
|
325
|
+
or prog.endswith(" doctor")
|
|
326
|
+
or prepared_invoked_command() == "doctor"
|
|
327
|
+
):
|
|
328
|
+
return (message, 'run "maproom doctor -h"')
|
|
329
|
+
return (message, 'run "maproom -h"')
|
maproom/cli_floors.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""Shared AWS/Azure CLI floor detection."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import shutil
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from maproom.cliio.runner import AWS_FLOOR, AZURE_FLOOR, CliBelowFloorError, Runner
|
|
10
|
+
from maproom.mock_environment.runner import MockEnvironmentRunner
|
|
11
|
+
|
|
12
|
+
FRIENDLY_UPGRADE = (
|
|
13
|
+
"Your {cloud} CLI {version} is below the supported floor {floor}. "
|
|
14
|
+
"Please upgrade and retry."
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
AWS_CLI_INSTALL_REMEDIATION = (
|
|
18
|
+
"Install the AWS CLI (https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)"
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def ensure_cli_floors(*, runner: Runner | None = None) -> None:
|
|
23
|
+
"""Probe aws once; raise CliBelowFloorError if below floor."""
|
|
24
|
+
r = runner or Runner()
|
|
25
|
+
r.detect_version("aws", check_floor=True)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def fail_cli_floor(exc: CliBelowFloorError, *, as_json: bool, invoked: str = "") -> int:
|
|
29
|
+
"""Report a CLI floor failure. ``--json`` writes one error document to stdout."""
|
|
30
|
+
message = format_below_floor(exc)
|
|
31
|
+
if as_json:
|
|
32
|
+
from maproom.output.json_envelope import print_error_envelope
|
|
33
|
+
|
|
34
|
+
return print_error_envelope("runtime", message, invoked=invoked)
|
|
35
|
+
print(message, file=sys.stderr)
|
|
36
|
+
from maproom.exitcodes import exit_code_for_error
|
|
37
|
+
|
|
38
|
+
return exit_code_for_error("runtime")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def format_below_floor(exc: CliBelowFloorError) -> str:
|
|
42
|
+
floor = (
|
|
43
|
+
".".join(str(p) for p in AWS_FLOOR)
|
|
44
|
+
if exc.cloud == "aws"
|
|
45
|
+
else ".".join(str(p) for p in AZURE_FLOOR)
|
|
46
|
+
)
|
|
47
|
+
return FRIENDLY_UPGRADE.format(cloud=exc.cloud, version=exc.version, floor=floor)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def check_aws_floor(*, runner: Runner | None = None) -> tuple[str, str | None, str | None]:
|
|
51
|
+
"""Return (status, message, reason_code) for doctor aws floor check."""
|
|
52
|
+
r = runner or Runner()
|
|
53
|
+
overridden = bool(os.environ.get("CLOUD_CLI_AWS") or os.environ.get("MAPROOM_AWS_CLI"))
|
|
54
|
+
mock_runner = isinstance(r, MockEnvironmentRunner)
|
|
55
|
+
if not overridden and not mock_runner and shutil.which("aws") is None:
|
|
56
|
+
return "fail", "AWS CLI not installed", "not_installed"
|
|
57
|
+
try:
|
|
58
|
+
version = r.detect_version("aws", check_floor=True)
|
|
59
|
+
except CliBelowFloorError as exc:
|
|
60
|
+
return "fail", format_below_floor(exc), "cli_too_old"
|
|
61
|
+
if version is None:
|
|
62
|
+
return (
|
|
63
|
+
"fail",
|
|
64
|
+
"Could not read AWS CLI version; upgrade aws CLI and retry.",
|
|
65
|
+
"cli_too_old",
|
|
66
|
+
)
|
|
67
|
+
return "pass", f"aws CLI {version} >= {'.'.join(str(p) for p in AWS_FLOOR)}", None
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def check_az_floor(*, runner: Runner | None = None) -> tuple[str, str | None, str | None]:
|
|
71
|
+
"""Return (status, message, reason_code) for doctor az floor check."""
|
|
72
|
+
r = runner or Runner()
|
|
73
|
+
overridden = bool(os.environ.get("CLOUD_CLI_AZ") or os.environ.get("MAPROOM_AZ_CLI"))
|
|
74
|
+
mock_runner = isinstance(r, MockEnvironmentRunner)
|
|
75
|
+
if not overridden and not mock_runner and shutil.which("az") is None:
|
|
76
|
+
return "skipped", "Azure CLI not installed", "not_installed"
|
|
77
|
+
try:
|
|
78
|
+
version = r.detect_version("azure", check_floor=True)
|
|
79
|
+
except CliBelowFloorError as exc:
|
|
80
|
+
return "fail", format_below_floor(exc), "cli_too_old"
|
|
81
|
+
if version is None:
|
|
82
|
+
if mock_runner:
|
|
83
|
+
return "skipped", "Azure CLI not installed", "not_installed"
|
|
84
|
+
return (
|
|
85
|
+
"skipped",
|
|
86
|
+
"Could not read Azure CLI version; assuming az meets the supported floor.",
|
|
87
|
+
"version_unreadable",
|
|
88
|
+
)
|
|
89
|
+
return "pass", f"az CLI {version} >= {'.'.join(str(p) for p in AZURE_FLOOR)}", None
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""CLI I/O adapters."""
|