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.
Files changed (199) hide show
  1. maproom/__init__.py +14 -0
  2. maproom/__main__.py +10 -0
  3. maproom/analyze/__init__.py +1 -0
  4. maproom/analyze/accel_families.py +45 -0
  5. maproom/analyze/account_azure_activity.py +260 -0
  6. maproom/analyze/account_azure_quota_requests.py +177 -0
  7. maproom/analyze/account_cloudtrail.py +316 -0
  8. maproom/analyze/account_quota_requests.py +180 -0
  9. maproom/analyze/analyze_v1_orchestration.py +1194 -0
  10. maproom/analyze/catalog.py +353 -0
  11. maproom/analyze/change_detection.py +652 -0
  12. maproom/analyze/context_client.py +99 -0
  13. maproom/analyze/context_lookup.py +142 -0
  14. maproom/analyze/cover_analyze.py +344 -0
  15. maproom/analyze/cover_client.py +65 -0
  16. maproom/analyze/cover_lookup.py +242 -0
  17. maproom/analyze/engine.py +644 -0
  18. maproom/analyze/fleetfit_endpoints.py +217 -0
  19. maproom/analyze/fleetfit_policy.py +66 -0
  20. maproom/analyze/instance_price_analyze.py +221 -0
  21. maproom/analyze/instance_price_client.py +108 -0
  22. maproom/analyze/instance_price_lookup.py +60 -0
  23. maproom/analyze/local_reads.py +484 -0
  24. maproom/analyze/lookup_http.py +280 -0
  25. maproom/analyze/metric_format.py +20 -0
  26. maproom/analyze/migration_method.py +130 -0
  27. maproom/analyze/move_list.py +93 -0
  28. maproom/analyze/operator_context.py +156 -0
  29. maproom/analyze/performance_rank.py +97 -0
  30. maproom/analyze/primary_recommendation.py +422 -0
  31. maproom/analyze/provider_comparison.py +401 -0
  32. maproom/analyze/quota_analyze.py +481 -0
  33. maproom/analyze/quota_client.py +75 -0
  34. maproom/analyze/quota_lookup.py +110 -0
  35. maproom/analyze/quota_outcome_steer.py +105 -0
  36. maproom/analyze/recommend_batch.py +199 -0
  37. maproom/analyze/recommend_client.py +362 -0
  38. maproom/analyze/recommend_share.py +118 -0
  39. maproom/analyze/recommendation.py +591 -0
  40. maproom/analyze/reservation_pack.py +883 -0
  41. maproom/analyze/reservation_read.py +461 -0
  42. maproom/analyze/safe_analyze.py +1134 -0
  43. maproom/analyze/safe_move.py +195 -0
  44. maproom/analyze/safe_moves.py +571 -0
  45. maproom/analyze/safe_moves_catalog.py +127 -0
  46. maproom/analyze/safe_moves_client.py +70 -0
  47. maproom/analyze/series_analyze.py +491 -0
  48. maproom/analyze/series_client.py +106 -0
  49. maproom/analyze/series_lookup.py +663 -0
  50. maproom/analyze/shape.py +254 -0
  51. maproom/analyze/size_analyze.py +883 -0
  52. maproom/analyze/size_client.py +81 -0
  53. maproom/analyze/size_keep.py +409 -0
  54. maproom/analyze/size_lookup.py +368 -0
  55. maproom/analyze/specs.py +325 -0
  56. maproom/analyze/spot_analyze.py +392 -0
  57. maproom/analyze/spot_client.py +74 -0
  58. maproom/analyze/spot_lookup.py +213 -0
  59. maproom/analyze/token_client.py +97 -0
  60. maproom/analyze/utilization.py +190 -0
  61. maproom/analyze/workload.py +104 -0
  62. maproom/analyze/workset.py +762 -0
  63. maproom/aws_region.py +78 -0
  64. maproom/cache/__init__.py +1 -0
  65. maproom/cache/catalog.py +372 -0
  66. maproom/cache/commands.py +215 -0
  67. maproom/cache/instances.py +460 -0
  68. maproom/cli.py +2084 -0
  69. maproom/cli_argv.py +329 -0
  70. maproom/cli_floors.py +89 -0
  71. maproom/cliio/__init__.py +1 -0
  72. maproom/cliio/registry.py +377 -0
  73. maproom/cliio/runner.py +489 -0
  74. maproom/consent/__init__.py +33 -0
  75. maproom/consent/gate.py +238 -0
  76. maproom/consent/policy.py +20 -0
  77. maproom/consent/prompt.py +61 -0
  78. maproom/consent/service_upload_gate.py +318 -0
  79. maproom/consent/service_upload_prompt.py +62 -0
  80. maproom/consent/stdin.py +45 -0
  81. maproom/consent/storage.py +24 -0
  82. maproom/consent/write_token.py +29 -0
  83. maproom/contracts/__init__.py +6 -0
  84. maproom/contracts/schema_diff.py +119 -0
  85. maproom/contracts/validate.py +113 -0
  86. maproom/data/__init__.py +1 -0
  87. maproom/data/clear.py +76 -0
  88. maproom/data/commands.py +14 -0
  89. maproom/doctor/__init__.py +1 -0
  90. maproom/doctor/aws_session.py +226 -0
  91. maproom/doctor/checks.py +701 -0
  92. maproom/doctor/context.py +32 -0
  93. maproom/doctor/display.py +96 -0
  94. maproom/doctor/inventory_display.py +377 -0
  95. maproom/doctor/runner.py +1467 -0
  96. maproom/errors.py +43 -0
  97. maproom/exitcodes.py +70 -0
  98. maproom/inventory/__init__.py +1 -0
  99. maproom/inventory/account_identity.py +79 -0
  100. maproom/inventory/accounts.py +155 -0
  101. maproom/inventory/command.py +961 -0
  102. maproom/inventory/messages.py +264 -0
  103. maproom/inventory/reservations_refresh.py +37 -0
  104. maproom/mock_environment/__init__.py +28 -0
  105. maproom/mock_environment/load.py +241 -0
  106. maproom/mock_environment/runner.py +387 -0
  107. maproom/output/__init__.py +1 -0
  108. maproom/output/json_envelope.py +241 -0
  109. maproom/output/redact.py +11 -0
  110. maproom/output/terminal.py +129 -0
  111. maproom/parsers.py +284 -0
  112. maproom/paths.py +105 -0
  113. maproom/plan/__init__.py +1 -0
  114. maproom/plan/accept.py +59 -0
  115. maproom/plan/analysis_context.py +78 -0
  116. maproom/plan/analyze_selection.py +279 -0
  117. maproom/plan/commands.py +586 -0
  118. maproom/plan/current.py +59 -0
  119. maproom/plan/errors.py +10 -0
  120. maproom/plan/export.py +36 -0
  121. maproom/plan/formatting.py +91 -0
  122. maproom/plan/ids.py +13 -0
  123. maproom/plan/migration_options.py +75 -0
  124. maproom/plan/model.py +265 -0
  125. maproom/plan/names.py +24 -0
  126. maproom/plan/store.py +193 -0
  127. maproom/plan/tty.py +34 -0
  128. maproom/pricing/__init__.py +5 -0
  129. maproom/pricing/prices.py +119 -0
  130. maproom/privacy/__init__.py +6 -0
  131. maproom/privacy/commands.py +159 -0
  132. maproom/privacy/delete_uploads.py +204 -0
  133. maproom/privacy/fleetfit_policy.py +125 -0
  134. maproom/privacy/fleetfit_statement.py +104 -0
  135. maproom/privacy/format.py +76 -0
  136. maproom/privacy/manifests.py +342 -0
  137. maproom/privacy/statement.py +58 -0
  138. maproom/quotas/__init__.py +21 -0
  139. maproom/quotas/aws.py +204 -0
  140. maproom/quotas/azure.py +75 -0
  141. maproom/quotas/commands.py +240 -0
  142. maproom/quotas/family_coverage.py +122 -0
  143. maproom/quotas/fetch.py +124 -0
  144. maproom/quotas/load.py +41 -0
  145. maproom/quotas/model.py +178 -0
  146. maproom/quotas/outcome_ledger.py +245 -0
  147. maproom/quotas/quota_request_sync.py +221 -0
  148. maproom/quotas/show.py +73 -0
  149. maproom/quotas/status.py +206 -0
  150. maproom/quotas/store.py +161 -0
  151. maproom/redaction.py +157 -0
  152. maproom/reference_data/__init__.py +1 -0
  153. maproom/reference_data/aws/aws_prices.csv +25562 -0
  154. maproom/reference_data/aws/capabilities.csv +1346 -0
  155. maproom/reference_data/aws/instance_types.csv +1346 -0
  156. maproom/reference_data/azure/azure_prices.csv +1 -0
  157. maproom/reference_data/azure/vm_types.csv +1 -0
  158. maproom/reference_data/benchmarks/cpu-lscpu-v2-instances.json +27 -0
  159. maproom/reference_data/benchmarks/safe-moves-v1.json +328 -0
  160. maproom/reference_data/manifest.json +174 -0
  161. maproom/reference_data/manifest.py +69 -0
  162. maproom/reservations/__init__.py +17 -0
  163. maproom/reservations/aws.py +76 -0
  164. maproom/reservations/azure.py +36 -0
  165. maproom/reservations/commands.py +149 -0
  166. maproom/reservations/load.py +41 -0
  167. maproom/reservations/model.py +316 -0
  168. maproom/reservations/show.py +64 -0
  169. maproom/reservations/status.py +181 -0
  170. maproom/reservations/store.py +391 -0
  171. maproom/resources.py +54 -0
  172. maproom/root_help.py +251 -0
  173. maproom/saving_plans/__init__.py +15 -0
  174. maproom/saving_plans/aws.py +73 -0
  175. maproom/saving_plans/commands.py +122 -0
  176. maproom/saving_plans/load.py +41 -0
  177. maproom/saving_plans/model.py +101 -0
  178. maproom/saving_plans/show.py +64 -0
  179. maproom/saving_plans/status.py +118 -0
  180. maproom/saving_plans/store.py +173 -0
  181. maproom/secret_egress_gate.py +108 -0
  182. maproom/service/install_id.py +60 -0
  183. maproom/settings/__init__.py +1 -0
  184. maproom/settings/defaults.py +73 -0
  185. maproom/settings/init.py +143 -0
  186. maproom/settings/model.py +105 -0
  187. maproom/settings/product_version_change.py +343 -0
  188. maproom/settings/product_versions.py +68 -0
  189. maproom/settings/set.py +347 -0
  190. maproom/settings/show.py +227 -0
  191. maproom/settings/write.py +273 -0
  192. maproom/snapshot_time.py +27 -0
  193. maproom-0.2.0.dist-info/METADATA +263 -0
  194. maproom-0.2.0.dist-info/RECORD +199 -0
  195. maproom-0.2.0.dist-info/WHEEL +5 -0
  196. maproom-0.2.0.dist-info/entry_points.txt +2 -0
  197. maproom-0.2.0.dist-info/licenses/LICENSE +201 -0
  198. maproom-0.2.0.dist-info/licenses/NOTICE +72 -0
  199. maproom-0.2.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,347 @@
1
+ """Minimal settings set command for consent keys."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import math
6
+ import sys
7
+ from datetime import datetime, timezone
8
+
9
+ from maproom.analyze.fleetfit_endpoints import (
10
+ ANALYZE_SETTING,
11
+ PROTOCOL_HOSTNAME_PORT_SETTINGS,
12
+ ProtocolHostnamePortError,
13
+ normalize_protocol_hostname_port,
14
+ )
15
+ from maproom.consent.prompt import cloud_read_prompt
16
+ from maproom.consent.service_upload_prompt import service_upload_prompt
17
+ from maproom.exitcodes import RUNTIME, SUCCESS, USAGE
18
+ from maproom.paths import prepare_settings_write, settings_file
19
+ from maproom.settings.defaults import (
20
+ DEFAULT_SETTINGS,
21
+ FLEETFIT_POLICY_OVERLAY_KEYS,
22
+ SETTINGS_INIT_ONLY_KEYS,
23
+ )
24
+ from maproom.settings.model import (
25
+ load_consent_state,
26
+ load_effective_settings,
27
+ load_service_upload_state,
28
+ )
29
+ from maproom.settings.product_version_change import (
30
+ print_product_version_operator_block,
31
+ prompt_product_version_consent_changes,
32
+ )
33
+ from maproom.settings.product_versions import (
34
+ MAX_PRODUCT_VERSION,
35
+ PRODUCT_VERSION_NAMES,
36
+ product_version_choices,
37
+ product_version_name,
38
+ )
39
+ from maproom.settings.write import (
40
+ persist_cloud_read_grant,
41
+ persist_service_upload_grant,
42
+ persist_settings,
43
+ revoke_cloud_read_consent,
44
+ revoke_service_upload_consent,
45
+ )
46
+
47
+ _CONSENT_KEYS = frozenset({"cloud_read_consent", "service_upload_consent"})
48
+
49
+ SETTINGS_SET_KEY_LINES: tuple[tuple[str, str], ...] = (
50
+ ("cloud_read_consent", "true or false"),
51
+ ("service_upload_consent", "true or false"),
52
+ ("product_version", f"integer {product_version_choices()}"),
53
+ ("desired_cpu_p99", "positive number (max projected CPU p99 after migration)"),
54
+ ("desired_memory_p99", "positive number (max projected memory p99 after migration)"),
55
+ (
56
+ "desired_network_headroom_pct",
57
+ "number in (0, 100] (network IOPS and throughput as % of capacity)",
58
+ ),
59
+ (
60
+ "desired_disk_headroom_pct",
61
+ "number in (0, 100] (disk IOPS and throughput as % of capacity)",
62
+ ),
63
+ ("cache_max_age_hours", "non-negative integer (hours; 0 always refreshes)"),
64
+ (
65
+ "cloud_authorize_protocol_hostname_port",
66
+ 'protocol://hostname:port with no path ("" turns it off)',
67
+ ),
68
+ (
69
+ "cloud_analyze_protocol_hostname_port",
70
+ 'protocol://hostname:port with no path ("" turns it off)',
71
+ ),
72
+ )
73
+
74
+
75
+ def settings_set_key_names_csv() -> str:
76
+ return ", ".join(key for key, _ in SETTINGS_SET_KEY_LINES)
77
+
78
+
79
+ def settings_set_value_epilog() -> str:
80
+ lines = ["Keys and value forms:"]
81
+ lines.extend(f" {key}: {desc}" for key, desc in SETTINGS_SET_KEY_LINES)
82
+ return "\n".join(lines)
83
+
84
+
85
+ def settings_set_remediation_hint() -> str:
86
+ """One-line key list for argparse usage errors (matches settings set --help)."""
87
+ parts = [f"{key} ({desc})" for key, desc in SETTINGS_SET_KEY_LINES]
88
+ return "supported keys: " + "; ".join(parts)
89
+
90
+
91
+ def settings_set_short_help() -> str:
92
+ return (
93
+ "Set consent, product_version, desired_* headroom keys, "
94
+ "cache_max_age_hours, or cloud_*_protocol_hostname_port keys"
95
+ )
96
+
97
+
98
+ def _format_utc(ts: datetime) -> str:
99
+ return ts.astimezone(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
100
+
101
+
102
+ def _parse_bool(value: str) -> bool | None:
103
+ lowered = value.strip().lower()
104
+ if lowered in ("true", "1", "yes"):
105
+ return True
106
+ if lowered in ("false", "0", "no"):
107
+ return False
108
+ return None
109
+
110
+
111
+ def _set_product_version(value: str) -> int:
112
+ text = value.strip()
113
+ try:
114
+ version = int(text)
115
+ except ValueError:
116
+ version = None
117
+ if version not in PRODUCT_VERSION_NAMES:
118
+ print(
119
+ f"error: product_version must be an integer from 1 to {MAX_PRODUCT_VERSION}: {value}",
120
+ file=sys.stderr,
121
+ )
122
+ print(f"hint: {product_version_choices()}", file=sys.stderr)
123
+ return USAGE
124
+
125
+ path = prepare_settings_write()
126
+ before, _ = load_effective_settings(path)
127
+ old = int(before.get("product_version", 1))
128
+ if old == version:
129
+ print(
130
+ f"product_version: {version} ({product_version_name(version)}) (unchanged)"
131
+ )
132
+ print_product_version_operator_block(version, before)
133
+ return SUCCESS
134
+ err = persist_settings(path, {"product_version": version})
135
+ if err is not None:
136
+ print(f"error: {err.message}", file=sys.stderr)
137
+ return RUNTIME
138
+ print(
139
+ "product_version: "
140
+ f"{old} ({product_version_name(old)}) -> {version} ({product_version_name(version)})"
141
+ )
142
+ after, _ = load_effective_settings(path)
143
+ print_product_version_operator_block(version, after)
144
+ prompt_product_version_consent_changes(
145
+ path,
146
+ old_version=old,
147
+ new_version=version,
148
+ settings=after,
149
+ )
150
+ return SUCCESS
151
+
152
+
153
+ def _set_cache_max_age_hours(value: str) -> int:
154
+ text = value.strip()
155
+ if not text.isdigit():
156
+ print(
157
+ f"error: cache_max_age_hours must be a non-negative integer: {value}",
158
+ file=sys.stderr,
159
+ )
160
+ return USAGE
161
+ number = int(text)
162
+ path = prepare_settings_write()
163
+ before, _ = load_effective_settings(path)
164
+ old = before.get("cache_max_age_hours", 1)
165
+ if old == number:
166
+ print(f"cache_max_age_hours: {number} (unchanged)")
167
+ return SUCCESS
168
+ err = persist_settings(path, {"cache_max_age_hours": number})
169
+ if err is not None:
170
+ print(f"error: {err.message}", file=sys.stderr)
171
+ return RUNTIME
172
+ print(f"cache_max_age_hours: {old} -> {number}")
173
+ return SUCCESS
174
+
175
+
176
+ _POSITIVE_HEADROOM_KEYS = frozenset(
177
+ {
178
+ "desired_cpu_p99",
179
+ "desired_memory_p99",
180
+ }
181
+ )
182
+ _PERCENT_HEADROOM_KEYS = frozenset(
183
+ {
184
+ "desired_network_headroom_pct",
185
+ "desired_disk_headroom_pct",
186
+ }
187
+ )
188
+
189
+
190
+ def _set_positive_number(key: str, value: str, *, default: float) -> int:
191
+ text = value.strip()
192
+ try:
193
+ number = float(text)
194
+ except ValueError:
195
+ number = math.nan
196
+ if not math.isfinite(number) or number <= 0:
197
+ print(
198
+ f"error: {key} must be a positive number: {value}",
199
+ file=sys.stderr,
200
+ )
201
+ return USAGE
202
+ stored: int | float = int(number) if number.is_integer() else number
203
+ path = prepare_settings_write()
204
+ before, _ = load_effective_settings(path)
205
+ old = before.get(key, default)
206
+ if old == stored:
207
+ print(f"{key}: {stored} (unchanged)")
208
+ return SUCCESS
209
+ err = persist_settings(path, {key: stored})
210
+ if err is not None:
211
+ print(f"error: {err.message}", file=sys.stderr)
212
+ return RUNTIME
213
+ print(f"{key}: {old} -> {stored}")
214
+ return SUCCESS
215
+
216
+
217
+ def _set_percent_headroom(key: str, value: str, *, default: float) -> int:
218
+ text = value.strip()
219
+ try:
220
+ number = float(text)
221
+ except ValueError:
222
+ number = math.nan
223
+ if not math.isfinite(number) or number <= 0 or number > 100:
224
+ print(
225
+ f"error: {key} must be a number in (0, 100]: {value}",
226
+ file=sys.stderr,
227
+ )
228
+ return USAGE
229
+ stored: int | float = int(number) if number.is_integer() else number
230
+ path = prepare_settings_write()
231
+ before, _ = load_effective_settings(path)
232
+ old = before.get(key, default)
233
+ if old == stored:
234
+ print(f"{key}: {stored} (unchanged)")
235
+ return SUCCESS
236
+ err = persist_settings(path, {key: stored})
237
+ if err is not None:
238
+ print(f"error: {err.message}", file=sys.stderr)
239
+ return RUNTIME
240
+ print(f"{key}: {old} -> {stored}")
241
+ return SUCCESS
242
+
243
+
244
+ def _set_protocol_hostname_port(key: str, value: str) -> int:
245
+ try:
246
+ stored = normalize_protocol_hostname_port(value)
247
+ except ProtocolHostnamePortError as exc:
248
+ print(f"error: {key} {exc}", file=sys.stderr)
249
+ print(
250
+ 'hint: use protocol, hostname, and port only, for example '
251
+ 'https://fleetfit-gate-dev.internal:443 or http://127.0.0.1:8080; "" turns it off',
252
+ file=sys.stderr,
253
+ )
254
+ return USAGE
255
+ path = prepare_settings_write()
256
+ before, _ = load_effective_settings(path)
257
+ old = before.get(key, "")
258
+ if old == stored:
259
+ print(f'{key}: "{stored}" (unchanged)')
260
+ return SUCCESS
261
+ updates: dict[str, object] = {key: stored}
262
+ if key == ANALYZE_SETTING:
263
+ for policy_key in FLEETFIT_POLICY_OVERLAY_KEYS:
264
+ updates[policy_key] = None
265
+ err = persist_settings(path, updates)
266
+ if err is not None:
267
+ print(f"error: {err.message}", file=sys.stderr)
268
+ return RUNTIME
269
+ print(f'{key}: "{old}" -> "{stored}"')
270
+ return SUCCESS
271
+
272
+
273
+ def run_settings_set(key: str, value: str) -> int:
274
+ if key in PROTOCOL_HOSTNAME_PORT_SETTINGS:
275
+ return _set_protocol_hostname_port(key, value)
276
+ if key == "product_version":
277
+ return _set_product_version(value)
278
+ if key in _POSITIVE_HEADROOM_KEYS:
279
+ return _set_positive_number(
280
+ key, value, default=float(DEFAULT_SETTINGS[key])
281
+ )
282
+ if key in _PERCENT_HEADROOM_KEYS:
283
+ return _set_percent_headroom(
284
+ key, value, default=float(DEFAULT_SETTINGS[key])
285
+ )
286
+ if key == "cache_max_age_hours":
287
+ return _set_cache_max_age_hours(value)
288
+ if key in SETTINGS_INIT_ONLY_KEYS:
289
+ path = settings_file()
290
+ print(
291
+ f"error: {key} is not writable via maproom settings set",
292
+ file=sys.stderr,
293
+ )
294
+ print(f"hint: edit {path} directly", file=sys.stderr)
295
+ return USAGE
296
+ if key not in _CONSENT_KEYS:
297
+ supported = ", ".join(sorted(_CONSENT_KEYS))
298
+ print(f"error: unknown settings key: {key}", file=sys.stderr)
299
+ print("hint: supported keys:", file=sys.stderr)
300
+ for name, desc in SETTINGS_SET_KEY_LINES:
301
+ print(f" {name}: {desc}", file=sys.stderr)
302
+ return USAGE
303
+
304
+ parsed = _parse_bool(value)
305
+ if parsed is None:
306
+ print(f"error: invalid boolean value for {key}: {value}", file=sys.stderr)
307
+ return USAGE
308
+
309
+ path = prepare_settings_write()
310
+ if key == "cloud_read_consent":
311
+ before = load_consent_state(path)
312
+ old_value = before.get("cloud_read_consent", False)
313
+ if parsed:
314
+ effective, _ = load_effective_settings(path)
315
+ prompt = cloud_read_prompt(settings=effective)
316
+ print(prompt)
317
+ err = persist_cloud_read_grant(
318
+ path,
319
+ approved_text=prompt,
320
+ approved_at=_format_utc(datetime.now(timezone.utc)),
321
+ )
322
+ else:
323
+ err = revoke_cloud_read_consent(path)
324
+ else:
325
+ before = load_service_upload_state(path)
326
+ old_value = before.get("service_upload_consent", False)
327
+ if parsed:
328
+ effective, _ = load_effective_settings(path)
329
+ prompt = service_upload_prompt(settings=effective)
330
+ print(prompt)
331
+ err = persist_service_upload_grant(
332
+ path,
333
+ approved_text=prompt,
334
+ approved_at=_format_utc(datetime.now(timezone.utc)),
335
+ )
336
+ else:
337
+ err = revoke_service_upload_consent(path)
338
+
339
+ if err is not None:
340
+ print(f"error: {err.message}", file=sys.stderr)
341
+ return RUNTIME
342
+
343
+ if old_value == parsed:
344
+ print(f"{key}: {str(parsed).lower()} (unchanged)")
345
+ return SUCCESS
346
+ print(f"{key}: {str(old_value).lower()} -> {str(parsed).lower()}")
347
+ return SUCCESS
@@ -0,0 +1,227 @@
1
+ """Show settings path and effective values (read-only)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+ from typing import Any
7
+
8
+ import os
9
+
10
+ from maproom.analyze.recommend_client import resolve_recommend_url
11
+ from maproom.exitcodes import SUCCESS
12
+ from maproom.settings.model import product_version
13
+ from maproom.output.json_envelope import build_document, command_metadata, print_json
14
+ from maproom.paths import settings_read_file
15
+ from maproom.settings.defaults import (
16
+ CONSENT_OVERLAY_KEYS,
17
+ DEFAULTS_MESSAGE,
18
+ DEFAULT_SETTINGS,
19
+ SETTINGS_INIT_ONLY_KEYS,
20
+ settings_init_only_keys_csv,
21
+ )
22
+ from maproom.settings.model import load_effective_settings
23
+ from maproom.settings.product_versions import product_version_settings_comment
24
+
25
+ _LEGACY_SERVICE_LOOKUP_URL_KEYS: tuple[str, ...] = (
26
+ "spot_lookup_url",
27
+ "size_lookup_url",
28
+ "reservation_cover_url",
29
+ "safe_moves_url",
30
+ "series_lookup_url",
31
+ "quota_lookup_url",
32
+ )
33
+
34
+
35
+ def _format_scalar(key: str, value: Any) -> str:
36
+ if key == "product_version":
37
+ return f"{key} = {value} # {product_version_settings_comment(int(value))}"
38
+ if value == "":
39
+ return f'{key} = ""'
40
+ if isinstance(value, bool):
41
+ return f"{key} = {str(value).lower()}"
42
+ return f"{key} = {value}"
43
+
44
+
45
+ def _recommend_url_source(settings: dict[str, Any], url: str) -> str:
46
+ env_recommend = os.environ.get("MAPROOM_RECOMMEND_URL", "").strip()
47
+ if env_recommend and url == env_recommend:
48
+ return "MAPROOM_RECOMMEND_URL"
49
+ service = settings.get("service")
50
+ if isinstance(service, dict):
51
+ configured = service.get("recommend_url")
52
+ if isinstance(configured, str) and configured.strip() and url == configured.strip():
53
+ return "service.recommend_url"
54
+ return "cloud_analyze_protocol_hostname_port"
55
+
56
+
57
+ def _analyses_status_line(settings: dict[str, Any]) -> str:
58
+ url = resolve_recommend_url(settings)
59
+ if url:
60
+ source = _recommend_url_source(settings, url)
61
+ return f"Recommend URL: {url} (from {source})"
62
+ host = settings.get("cloud_analyze_protocol_hostname_port", "")
63
+ if isinstance(host, str) and host.strip():
64
+ return (
65
+ "Recommend URL: not configured "
66
+ "(set cloud_analyze_protocol_hostname_port; path is /v1/recommend)"
67
+ )
68
+ return "Recommend URL: not configured (set cloud_analyze_protocol_hostname_port)"
69
+
70
+
71
+ def _format_engine_table(engine: dict[str, Any]) -> list[str]:
72
+ lines = [" [engine]"]
73
+ for subkey, subval in engine.items():
74
+ display = (
75
+ str(subval).lower()
76
+ if isinstance(subval, bool)
77
+ else (f'"{subval}"' if subval == "" else subval)
78
+ )
79
+ lines.append(f" {subkey} = {display}")
80
+ return lines
81
+
82
+
83
+ def _format_human(
84
+ path: str,
85
+ settings: dict[str, Any],
86
+ defaults_in_use: bool,
87
+ *,
88
+ include_consent_text: bool,
89
+ file_exists: bool,
90
+ ) -> str:
91
+ path_line = f"Settings file: {path}"
92
+ if not file_exists:
93
+ path_line += " (not created)"
94
+ lines = [path_line, ""]
95
+ lines.append("Local recommendations")
96
+ lines.append(" Computed on this machine. Engine thresholds apply only here.")
97
+ pv = settings.get("product_version", DEFAULT_SETTINGS["product_version"])
98
+ lines.append(_format_scalar("product_version", pv))
99
+ for key in (
100
+ "desired_cpu_p99",
101
+ "desired_memory_p99",
102
+ "desired_network_headroom_pct",
103
+ "desired_disk_headroom_pct",
104
+ ):
105
+ if key in settings:
106
+ lines.append(_format_scalar(key, settings[key]))
107
+ engine = settings.get("engine")
108
+ if isinstance(engine, dict):
109
+ lines.extend(_format_engine_table(engine))
110
+
111
+ lines.extend(["", "Cloud account reads"])
112
+ lines.append(" aws and az on this machine. Separate from cloud recommendations.")
113
+ lines.append(_format_scalar("cloud_read_consent", settings.get("cloud_read_consent", False)))
114
+ approved_at = settings.get("cloud_read_consent_approved_at")
115
+ if isinstance(approved_at, str) and approved_at:
116
+ lines.append(f" cloud reads granted {approved_at}")
117
+ lines.append(" revoke cloud reads: maproom settings set cloud_read_consent false")
118
+ snoozed = settings.get("cloud_read_consent_snoozed_until")
119
+ if isinstance(snoozed, str) and snoozed:
120
+ lines.append(f" cloud_read_consent_snoozed_until = {snoozed}")
121
+ if include_consent_text:
122
+ text = settings.get("cloud_read_consent_approved_text")
123
+ if isinstance(text, str) and text:
124
+ lines.append(f" cloud_read_consent_approved_text = {text}")
125
+
126
+ lines.extend(["", "Cloud recommendations"])
127
+ lines.append(" Calls use the hosts below. The analyze path is fixed.")
128
+ for key in ("cloud_authorize_protocol_hostname_port", "cloud_analyze_protocol_hostname_port"):
129
+ lines.append(_format_scalar(key, settings.get(key, "")))
130
+ lines.append(f" {_analyses_status_line(settings)}")
131
+ lines.append(_format_scalar("service_upload_consent", settings.get("service_upload_consent", False)))
132
+ upload_at = settings.get("service_upload_consent_approved_at")
133
+ if isinstance(upload_at, str) and upload_at:
134
+ lines.append(f" cloud recommendations granted {upload_at}")
135
+ lines.append(
136
+ " revoke cloud recommendations: maproom settings set service_upload_consent false"
137
+ )
138
+ if include_consent_text:
139
+ upload_text = settings.get("service_upload_consent_approved_text")
140
+ if isinstance(upload_text, str) and upload_text:
141
+ lines.append(f" service_upload_consent_approved_text = {upload_text}")
142
+ policy_id = settings.get("fleetfit_policy_id")
143
+ policy_at = settings.get("fleetfit_policy_granted_at")
144
+ if isinstance(policy_id, str) and policy_id and isinstance(policy_at, str) and policy_at:
145
+ lines.append(f" fleetfit policy {policy_id} granted {policy_at}")
146
+
147
+ lines.extend(["", "Other"])
148
+ for key in ("cache_max_age_hours", "quota_telemetry", "quota_headroom_pct", "denial_suppress_days"):
149
+ if key in settings:
150
+ lines.append(_format_scalar(key, settings[key]))
151
+ if any(key in settings for key in SETTINGS_INIT_ONLY_KEYS):
152
+ lines.append(
153
+ f" change {settings_init_only_keys_csv()} by editing {path} "
154
+ "(not via maproom settings set)"
155
+ )
156
+
157
+ if defaults_in_use:
158
+ lines.extend(["", DEFAULTS_MESSAGE])
159
+ return "\n".join(lines)
160
+
161
+
162
+ def _settings_for_json(
163
+ settings: dict[str, Any],
164
+ *,
165
+ include_consent_text: bool,
166
+ ) -> dict[str, Any]:
167
+ payload = dict(DEFAULT_SETTINGS)
168
+ for key in DEFAULT_SETTINGS:
169
+ if key in settings:
170
+ payload[key] = settings[key]
171
+ service = payload.get("service")
172
+ if isinstance(service, dict):
173
+ service.pop("recommendation_url", None)
174
+ for key in _LEGACY_SERVICE_LOOKUP_URL_KEYS:
175
+ service.pop(key, None)
176
+ if not service:
177
+ payload["service"] = {}
178
+ for key in CONSENT_OVERLAY_KEYS:
179
+ if key not in settings or settings[key] is None:
180
+ continue
181
+ if key.endswith("_approved_text") and not include_consent_text:
182
+ continue
183
+ payload[key] = settings[key]
184
+ return payload
185
+
186
+
187
+ def run_settings_show(*, as_json: bool = False, include_consent_text: bool = False) -> int:
188
+ path = settings_read_file()
189
+ settings, defaults_in_use = load_effective_settings(path)
190
+ file_exists = path.is_file()
191
+
192
+ if as_json:
193
+ from maproom.analyze.fleetfit_endpoints import configured_fleetfit_endpoints
194
+
195
+ fleetfit = configured_fleetfit_endpoints(
196
+ settings, product_version=product_version()
197
+ )
198
+ print_json(
199
+ build_document(
200
+ schema_type="settings",
201
+ schema_id="maproom.settings",
202
+ metadata=command_metadata("settings"),
203
+ errors=[],
204
+ warnings=[],
205
+ payload={
206
+ "path": str(path),
207
+ "settings": _settings_for_json(
208
+ settings, include_consent_text=include_consent_text
209
+ ),
210
+ "fleetfit_lookups": fleetfit,
211
+ "file_exists": file_exists,
212
+ "defaults_in_use": defaults_in_use,
213
+ },
214
+ )
215
+ )
216
+ else:
217
+ print(
218
+ _format_human(
219
+ str(path),
220
+ settings,
221
+ defaults_in_use,
222
+ include_consent_text=include_consent_text,
223
+ file_exists=file_exists,
224
+ ),
225
+ file=sys.stdout,
226
+ )
227
+ return SUCCESS