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,254 @@
1
+ """User-declared recommendation shape: attributes to modify or keep."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+
7
+ from maproom.analyze.engine import Candidate, EngineResult
8
+ from maproom.analyze.specs import InstanceSpec, SpecCatalog
9
+ from maproom.plan.errors import PlanError
10
+
11
+
12
+ @dataclass(frozen=True)
13
+ class ShapeAttribute:
14
+ name: str
15
+ summary: str
16
+
17
+
18
+ SHAPE_ATTRIBUTES: tuple[ShapeAttribute, ...] = (
19
+ ShapeAttribute(
20
+ "burstable",
21
+ "Whether the instance is a burstable CPU type.",
22
+ ),
23
+ ShapeAttribute(
24
+ "has_instance_disks",
25
+ "Whether the instance has local instance-store disks.",
26
+ ),
27
+ ShapeAttribute(
28
+ "instance_family",
29
+ "Family name, such as m5, c6i, or r6g.",
30
+ ),
31
+ ShapeAttribute(
32
+ "instance_generation",
33
+ "Generation number inside the family, such as 5 in m5 or 6 in c6i.",
34
+ ),
35
+ ShapeAttribute(
36
+ "instance_quantity",
37
+ "How many servers are in the VMSS or Auto Scaling group.",
38
+ ),
39
+ ShapeAttribute(
40
+ "instance_size",
41
+ "Size suffix, such as large or 2xlarge.",
42
+ ),
43
+ ShapeAttribute(
44
+ "processor_architecture",
45
+ "Processor architecture, such as x86_64 or arm64.",
46
+ ),
47
+ )
48
+
49
+
50
+ _BY_NAME = {item.name: item for item in SHAPE_ATTRIBUTES}
51
+ _MODIFY = {f"modify_{item.name}" for item in SHAPE_ATTRIBUTES}
52
+ _KEEP = {f"keep_{item.name}" for item in SHAPE_ATTRIBUTES}
53
+ _ALL_TOKENS = _MODIFY | _KEEP
54
+
55
+
56
+ @dataclass(frozen=True)
57
+ class ShapeConstraint:
58
+ """Attributes the operator will allow to change, and attributes they want kept."""
59
+
60
+ modify: frozenset[str]
61
+ keep: frozenset[str]
62
+
63
+ def summary(self) -> str:
64
+ modify = ", ".join(sorted(self.modify)) or "(none)"
65
+ keep = ", ".join(sorted(self.keep)) or "(none)"
66
+ return f"modify {modify}; keep {keep}"
67
+
68
+
69
+ def shape_in_effect(shape: ShapeConstraint | None) -> ShapeConstraint:
70
+ """Every attribute except burstable may change until the operator names a list."""
71
+ if shape is None:
72
+ return ShapeConstraint(
73
+ modify=frozenset(
74
+ item.name for item in SHAPE_ATTRIBUTES if item.name != "burstable"
75
+ ),
76
+ keep=frozenset({"burstable"}),
77
+ )
78
+ return shape
79
+
80
+
81
+ def format_active_shapes(shape: ShapeConstraint | None) -> str:
82
+ """List the shape settings in effect for this analyze run."""
83
+ lines = [
84
+ "Shape settings for this analyze run:",
85
+ "",
86
+ ]
87
+ if shape is None:
88
+ for item in SHAPE_ATTRIBUTES:
89
+ if item.name == "burstable":
90
+ lines.append(f" keep_{item.name}")
91
+ else:
92
+ lines.append(f" modify_{item.name}")
93
+ lines.append(
94
+ "Pass --shape to name the attributes allowed to change. "
95
+ "Burstable stays fixed when --shape is omitted; name modify_burstable "
96
+ "to let burstable change."
97
+ )
98
+ return "\n".join(lines)
99
+ for item in SHAPE_ATTRIBUTES:
100
+ if item.name in shape.modify:
101
+ lines.append(f" modify_{item.name}")
102
+ elif item.name in shape.keep:
103
+ lines.append(f" keep_{item.name}")
104
+ return "\n".join(lines)
105
+
106
+
107
+ def format_shape_catalog() -> str:
108
+ """Teach the modify_* and keep_* tokens."""
109
+ lines = [
110
+ "A shape is the set of instance attributes you will let a recommendation change,",
111
+ "and the set you want kept.",
112
+ "",
113
+ "With no --shape, every attribute except burstable may change.",
114
+ "Burstable stays fixed by default. Name modify_burstable to let it change.",
115
+ "Pass --shape to limit the lookup to the attributes you name.",
116
+ "Tokens are comma-separated and repeatable.",
117
+ "",
118
+ "Each attribute is one choice. Pass keep_<name> or modify_<name>.",
119
+ "Attributes you leave out stay fixed.",
120
+ "",
121
+ "Attributes:",
122
+ ]
123
+ for item in SHAPE_ATTRIBUTES:
124
+ lines.append(f" {{keep|modify}}_{item.name}")
125
+ lines.append(f" {item.summary}")
126
+ lines.append("")
127
+ lines.append("modify_* and keep_* for the same attribute is treated as keep.")
128
+ lines.append("")
129
+ lines.append("Example:")
130
+ lines.append(
131
+ " maproom analyze aws --shape modify_instance_size,modify_processor_architecture"
132
+ )
133
+ lines.append(
134
+ " Fits the instance size to the most price-efficient Graviton or x86 type."
135
+ )
136
+ return "\n".join(lines) + "\n"
137
+
138
+
139
+ def _normalize_token(token: str) -> str:
140
+ return token.strip().replace("-", "_").lower()
141
+
142
+
143
+ def parse_shape_values(raw_values: list[str]) -> ShapeConstraint | PlanError:
144
+ modify: set[str] = set()
145
+ keep: set[str] = set()
146
+ for raw in raw_values:
147
+ for piece in raw.split(","):
148
+ token = _normalize_token(piece)
149
+ if not token:
150
+ continue
151
+ if token not in _ALL_TOKENS:
152
+ allowed = ", ".join(sorted(_ALL_TOKENS))
153
+ return PlanError(
154
+ f'unrecognized shape token "{piece.strip()}". '
155
+ f"Run `maproom analyze -h` for the list. Valid values: {allowed}"
156
+ )
157
+ name = token.split("_", 1)[1]
158
+ if token in _MODIFY:
159
+ if name not in keep:
160
+ modify.add(name)
161
+ else:
162
+ modify.discard(name)
163
+ keep.add(name)
164
+ if not modify and not keep:
165
+ return PlanError(
166
+ "at least one --shape value is required. Run `maproom analyze -h`."
167
+ )
168
+ return ShapeConstraint(modify=frozenset(modify), keep=frozenset(keep))
169
+
170
+
171
+ def _same_architecture(current: InstanceSpec, candidate: InstanceSpec) -> bool:
172
+ if not current.architectures or not candidate.architectures:
173
+ return True
174
+ return bool(set(current.architectures) & set(candidate.architectures))
175
+
176
+
177
+ def _changed_names(current: InstanceSpec, candidate: InstanceSpec) -> set[str]:
178
+ changed: set[str] = set()
179
+ if candidate.family != current.family:
180
+ changed.add("instance_family")
181
+ if candidate.generation != current.generation:
182
+ changed.add("instance_generation")
183
+ if candidate.size != current.size:
184
+ changed.add("instance_size")
185
+ if not _same_architecture(current, candidate):
186
+ changed.add("processor_architecture")
187
+ if candidate.instance_storage != current.instance_storage:
188
+ changed.add("has_instance_disks")
189
+ if candidate.burstable != current.burstable:
190
+ changed.add("burstable")
191
+ return changed
192
+
193
+
194
+ def attribute_tokens(
195
+ current: InstanceSpec,
196
+ candidate: InstanceSpec,
197
+ ) -> tuple[list[str], list[str]]:
198
+ """Return (modify_* tokens, keep_* tokens) for one candidate versus current."""
199
+ changed = _changed_names(current, candidate)
200
+ modifies = [f"modify_{item.name}" for item in SHAPE_ATTRIBUTES if item.name in changed]
201
+ keeps = [f"keep_{item.name}" for item in SHAPE_ATTRIBUTES if item.name not in changed]
202
+ return modifies, keeps
203
+
204
+
205
+ def shape_allows(
206
+ constraint: ShapeConstraint,
207
+ current: InstanceSpec,
208
+ candidate: InstanceSpec,
209
+ ) -> bool:
210
+ """True when every change is allowed and every requested keep still holds.
211
+
212
+ Attributes the operator did not list as modify_* are kept.
213
+ """
214
+ changed = _changed_names(current, candidate)
215
+ if not changed <= constraint.modify:
216
+ return False
217
+ if not constraint.keep <= (set(_BY_NAME) - changed):
218
+ return False
219
+ return True
220
+
221
+
222
+ def restrict_engine_result(
223
+ result: EngineResult,
224
+ *,
225
+ current: InstanceSpec,
226
+ catalog: SpecCatalog,
227
+ shape: ShapeConstraint,
228
+ ) -> EngineResult:
229
+ """Drop candidates that change an attribute the operator did not allow."""
230
+
231
+ def _keep(candidate: Candidate) -> bool:
232
+ spec = catalog.specs.get(candidate.instance_type)
233
+ if spec is None:
234
+ return False
235
+ return shape_allows(shape, current, spec)
236
+
237
+ recommendations = [item for item in result.recommendations if _keep(item)]
238
+ conditional = [item for item in result.conditional if _keep(item)]
239
+ dropped = (len(result.recommendations) - len(recommendations)) + (
240
+ len(result.conditional) - len(conditional)
241
+ )
242
+ rejected_by_reason = dict(result.rejected_by_reason)
243
+ if dropped:
244
+ rejected_by_reason["outside_shape"] = (
245
+ rejected_by_reason.get("outside_shape", 0) + dropped
246
+ )
247
+ return EngineResult(
248
+ recommendations=recommendations,
249
+ conditional=conditional,
250
+ rejected=result.rejected,
251
+ rejected_total=result.rejected_total + dropped,
252
+ rejected_by_reason=rejected_by_reason,
253
+ evaluated_total=result.evaluated_total,
254
+ )