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
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"""Closed reservation_cover body, fleetfit response, and local candidate ranking."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from maproom.analyze.size_lookup import _reject_id_shaped
|
|
10
|
+
|
|
11
|
+
REQUEST_TYPE = "reservation_cover"
|
|
12
|
+
|
|
13
|
+
COVER_BODY_KEYS: tuple[str, ...] = (
|
|
14
|
+
"request_type",
|
|
15
|
+
"provider",
|
|
16
|
+
"region",
|
|
17
|
+
"instance",
|
|
18
|
+
"family",
|
|
19
|
+
"size",
|
|
20
|
+
"unused_linux_family",
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
COVER_RESPONSE_KEYS: tuple[str, ...] = (
|
|
24
|
+
"request_type",
|
|
25
|
+
"instance",
|
|
26
|
+
"covered_by_unused_reservation",
|
|
27
|
+
"size_flexibility_covers",
|
|
28
|
+
"cheaper_on_demand_only",
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
INCOMPLETE_LINE = "The reservation cover description was incomplete."
|
|
32
|
+
DECLINED_LINE = "The reservation cover lookup was declined."
|
|
33
|
+
NOT_SENT_LINE = "The reservation cover lookup was not sent."
|
|
34
|
+
CHECKED_NONE = "No matching reservation coverage was found."
|
|
35
|
+
IDLE_COVERAGE_WARNING = (
|
|
36
|
+
"An unused reservation would cover the version-1 type; the chosen type may leave "
|
|
37
|
+
"that reservation idle."
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@dataclass(frozen=True)
|
|
42
|
+
class CoverCandidate:
|
|
43
|
+
instance_type: str
|
|
44
|
+
source: str
|
|
45
|
+
response: dict[str, Any]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def parse_type_parts(instance_type: str) -> tuple[str, str] | None:
|
|
49
|
+
text = instance_type.strip()
|
|
50
|
+
if "." not in text:
|
|
51
|
+
return None
|
|
52
|
+
family, size = text.split(".", 1)
|
|
53
|
+
if not family or not size:
|
|
54
|
+
return None
|
|
55
|
+
return family, size
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _platform_is_linux(platform: str) -> bool:
|
|
59
|
+
return "linux" in platform.lower()
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _record_unused_linux(record: dict[str, Any]) -> bool:
|
|
63
|
+
platform = str(record.get("platform") or "")
|
|
64
|
+
if not _platform_is_linux(platform):
|
|
65
|
+
return False
|
|
66
|
+
fraction = record.get("utilization_fraction")
|
|
67
|
+
if isinstance(fraction, (int, float)) and not isinstance(fraction, bool):
|
|
68
|
+
return float(fraction) < 1.0
|
|
69
|
+
unused = record.get("unused_quantity")
|
|
70
|
+
if isinstance(unused, (int, float)) and not isinstance(unused, bool):
|
|
71
|
+
return float(unused) > 0.0
|
|
72
|
+
return False
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def unused_linux_family_in_snapshot(
|
|
76
|
+
records: list[dict[str, Any]],
|
|
77
|
+
*,
|
|
78
|
+
region: str,
|
|
79
|
+
family: str,
|
|
80
|
+
) -> bool:
|
|
81
|
+
wanted_region = region.strip().lower()
|
|
82
|
+
wanted_family = family.strip().lower()
|
|
83
|
+
for record in records:
|
|
84
|
+
if str(record.get("region") or "").strip().lower() != wanted_region:
|
|
85
|
+
continue
|
|
86
|
+
if str(record.get("instance_family") or "").strip().lower() != wanted_family:
|
|
87
|
+
continue
|
|
88
|
+
if _record_unused_linux(record):
|
|
89
|
+
return True
|
|
90
|
+
return False
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def build_cover_body(
|
|
94
|
+
*,
|
|
95
|
+
region: str,
|
|
96
|
+
instance: str,
|
|
97
|
+
records: list[dict[str, Any]],
|
|
98
|
+
) -> dict[str, Any]:
|
|
99
|
+
parts = parse_type_parts(instance)
|
|
100
|
+
if parts is None:
|
|
101
|
+
raise ValueError("cover lookup body has an empty field")
|
|
102
|
+
family, size = parts
|
|
103
|
+
body: dict[str, Any] = {
|
|
104
|
+
"request_type": REQUEST_TYPE,
|
|
105
|
+
"provider": "aws",
|
|
106
|
+
"region": region.strip(),
|
|
107
|
+
"instance": instance.strip(),
|
|
108
|
+
"family": family,
|
|
109
|
+
"size": size,
|
|
110
|
+
"unused_linux_family": unused_linux_family_in_snapshot(
|
|
111
|
+
records,
|
|
112
|
+
region=region.strip(),
|
|
113
|
+
family=family,
|
|
114
|
+
),
|
|
115
|
+
}
|
|
116
|
+
_require_closed_cover_body(body)
|
|
117
|
+
return body
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _require_closed_cover_body(body: dict[str, Any]) -> None:
|
|
121
|
+
if not isinstance(body, dict):
|
|
122
|
+
raise ValueError("cover lookup body must be an object")
|
|
123
|
+
keys = set(body)
|
|
124
|
+
expected = set(COVER_BODY_KEYS)
|
|
125
|
+
if keys - expected:
|
|
126
|
+
raise ValueError("cover lookup body has an extra key")
|
|
127
|
+
if expected - keys:
|
|
128
|
+
raise ValueError("cover lookup body is missing a key")
|
|
129
|
+
_reject_id_shaped(body)
|
|
130
|
+
if body.get("request_type") != REQUEST_TYPE:
|
|
131
|
+
raise ValueError("request_type must be reservation_cover")
|
|
132
|
+
if body.get("provider") != "aws":
|
|
133
|
+
raise ValueError("provider must be aws")
|
|
134
|
+
for key in ("region", "instance", "family", "size"):
|
|
135
|
+
value = body.get(key)
|
|
136
|
+
if not isinstance(value, str) or value.strip() == "":
|
|
137
|
+
raise ValueError("cover lookup body has an empty field")
|
|
138
|
+
if not isinstance(body.get("unused_linux_family"), bool):
|
|
139
|
+
raise ValueError("unused_linux_family must be a boolean")
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def require_cover_response(payload: object) -> dict[str, Any]:
|
|
143
|
+
if not isinstance(payload, dict):
|
|
144
|
+
raise ValueError("cover lookup response must be an object")
|
|
145
|
+
keys = set(payload)
|
|
146
|
+
expected = set(COVER_RESPONSE_KEYS)
|
|
147
|
+
if keys - expected:
|
|
148
|
+
raise ValueError("cover lookup response has an extra key")
|
|
149
|
+
if expected - keys:
|
|
150
|
+
raise ValueError("cover lookup response is missing a key")
|
|
151
|
+
_reject_id_shaped(payload)
|
|
152
|
+
if payload.get("request_type") != REQUEST_TYPE:
|
|
153
|
+
raise ValueError("request_type must be reservation_cover")
|
|
154
|
+
instance = payload.get("instance")
|
|
155
|
+
if not isinstance(instance, str) or not instance.strip():
|
|
156
|
+
raise ValueError("cover lookup response has an empty instance")
|
|
157
|
+
for key in (
|
|
158
|
+
"covered_by_unused_reservation",
|
|
159
|
+
"size_flexibility_covers",
|
|
160
|
+
"cheaper_on_demand_only",
|
|
161
|
+
):
|
|
162
|
+
if not isinstance(payload.get(key), bool):
|
|
163
|
+
raise ValueError(f"cover lookup response has an invalid {key}")
|
|
164
|
+
return payload
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _rank_tuple(response: dict[str, Any]) -> tuple[int, int]:
|
|
168
|
+
covered = 1 if response.get("covered_by_unused_reservation") else 0
|
|
169
|
+
cheaper = 1 if response.get("cheaper_on_demand_only") else 0
|
|
170
|
+
return (-covered, -cheaper)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def choose_candidate(candidates: list[CoverCandidate]) -> CoverCandidate | None:
|
|
174
|
+
if not candidates:
|
|
175
|
+
return None
|
|
176
|
+
source_rank = {"v1": 0, "v3": 1}
|
|
177
|
+
|
|
178
|
+
def sort_key(entry: CoverCandidate) -> tuple[tuple[int, int], int]:
|
|
179
|
+
return (_rank_tuple(entry.response), source_rank.get(entry.source, 9))
|
|
180
|
+
|
|
181
|
+
return min(candidates, key=sort_key)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def idle_coverage_warning(
|
|
185
|
+
*,
|
|
186
|
+
v1_type: str | None,
|
|
187
|
+
v1_response: dict[str, Any] | None,
|
|
188
|
+
chosen: CoverCandidate,
|
|
189
|
+
current_family: str,
|
|
190
|
+
) -> str | None:
|
|
191
|
+
if not v1_type or v1_response is None:
|
|
192
|
+
return None
|
|
193
|
+
if chosen.instance_type == v1_type:
|
|
194
|
+
return None
|
|
195
|
+
if not v1_response.get("covered_by_unused_reservation"):
|
|
196
|
+
return None
|
|
197
|
+
chosen_parts = parse_type_parts(chosen.instance_type)
|
|
198
|
+
v1_parts = parse_type_parts(v1_type)
|
|
199
|
+
if chosen_parts and v1_parts and chosen_parts[0] == v1_parts[0]:
|
|
200
|
+
if chosen.response.get("size_flexibility_covers"):
|
|
201
|
+
return None
|
|
202
|
+
if chosen_parts and chosen_parts[0] != current_family.strip().lower():
|
|
203
|
+
return IDLE_COVERAGE_WARNING
|
|
204
|
+
if chosen.source == "v3" and v1_response.get("covered_by_unused_reservation"):
|
|
205
|
+
if chosen.response.get("size_flexibility_covers"):
|
|
206
|
+
return None
|
|
207
|
+
return IDLE_COVERAGE_WARNING
|
|
208
|
+
return None
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def replace_unchecked_coverage(text: str, replacement: str) -> str:
|
|
212
|
+
from maproom.analyze.safe_move import UNCHECKED_COVERAGE
|
|
213
|
+
|
|
214
|
+
if UNCHECKED_COVERAGE not in text:
|
|
215
|
+
return text
|
|
216
|
+
lines = text.splitlines()
|
|
217
|
+
updated: list[str] = []
|
|
218
|
+
suffix = f" {UNCHECKED_COVERAGE}"
|
|
219
|
+
for line in lines:
|
|
220
|
+
if line == UNCHECKED_COVERAGE:
|
|
221
|
+
if replacement:
|
|
222
|
+
updated.append(replacement)
|
|
223
|
+
elif line.endswith(suffix):
|
|
224
|
+
prefix = line[: -len(UNCHECKED_COVERAGE)].rstrip()
|
|
225
|
+
if replacement:
|
|
226
|
+
updated.append(f"{prefix} {replacement}" if prefix else replacement)
|
|
227
|
+
elif prefix:
|
|
228
|
+
updated.append(prefix)
|
|
229
|
+
elif UNCHECKED_COVERAGE in line:
|
|
230
|
+
replaced = line.replace(UNCHECKED_COVERAGE, replacement)
|
|
231
|
+
if replaced.strip():
|
|
232
|
+
updated.append(replaced)
|
|
233
|
+
else:
|
|
234
|
+
updated.append(line)
|
|
235
|
+
return "\n".join(updated)
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def scrub_buy_recommendation(text: str) -> str:
|
|
239
|
+
lowered = text.lower()
|
|
240
|
+
if "buy" in lowered and "reservation" in lowered:
|
|
241
|
+
raise ValueError("unexpected reservation purchase recommendation")
|
|
242
|
+
return text
|