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,32 @@
|
|
|
1
|
+
"""Shared context for doctor checks."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Callable
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
|
|
8
|
+
from maproom.cliio.runner import Runner
|
|
9
|
+
|
|
10
|
+
from maproom.consent import (
|
|
11
|
+
CloudReadGateOutcome,
|
|
12
|
+
ServiceUploadGateOutcome,
|
|
13
|
+
consent_storage_available,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
ProgressFn = Callable[[str], None]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass
|
|
20
|
+
class DoctorContext:
|
|
21
|
+
runner: Runner = field(default_factory=Runner)
|
|
22
|
+
cloud_read_gate_outcome: CloudReadGateOutcome | None = None
|
|
23
|
+
gate_evaluated: bool = False
|
|
24
|
+
fleetfit_gate_outcome: ServiceUploadGateOutcome | None = None
|
|
25
|
+
fleetfit_evaluated: bool = False
|
|
26
|
+
cloud_read_allowed: bool = False
|
|
27
|
+
progress: ProgressFn | None = None
|
|
28
|
+
# Populated during prerequisite probes so identity checks avoid a second az version call.
|
|
29
|
+
az_cli_floor: tuple[str, str | None, str | None] | None = None
|
|
30
|
+
|
|
31
|
+
def consent_available(self) -> bool:
|
|
32
|
+
return consent_storage_available()
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""Interactive TTY display keys and short facts for grouped doctor output."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from maproom.doctor.checks import CheckResult
|
|
6
|
+
from maproom.doctor.inventory_display import QUOTAS_GET_HINT
|
|
7
|
+
|
|
8
|
+
INTERACTIVE_DISPLAY_KEYS: dict[str, str] = {
|
|
9
|
+
"python_version": "PYTHON_VERSION",
|
|
10
|
+
"platform_info": "PLATFORM",
|
|
11
|
+
"aws_cli_version_floor": "AWS_CLI",
|
|
12
|
+
"az_cli_version_floor": "AZ_CLI",
|
|
13
|
+
"consent_cloud_reads": "CLOUD_READS",
|
|
14
|
+
"fleetfit_ai": "FLEETFIT_AI",
|
|
15
|
+
"cloud_identity_aws": "AWS",
|
|
16
|
+
"cloud_identity_azure": "AZURE",
|
|
17
|
+
"aws_price_file": "AWS_PRICES",
|
|
18
|
+
"user_local_data": "LOCAL_DATA",
|
|
19
|
+
"inventory": "INVENTORY",
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def interactive_display_key(check_name: str) -> str:
|
|
24
|
+
return INTERACTIVE_DISPLAY_KEYS.get(check_name, check_name.upper())
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
_INVENTORY_REFRESH_LINE = "Refresh: maproom inventory get"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _consent_authorized_message(message: str | None) -> str | None:
|
|
31
|
+
if not message:
|
|
32
|
+
return message
|
|
33
|
+
prefix = "Cloud reads allowed on "
|
|
34
|
+
if message.startswith(prefix):
|
|
35
|
+
return f"Authorized {message.removeprefix(prefix)}"
|
|
36
|
+
if message == "allowed by managed policy":
|
|
37
|
+
return "Authorized by managed policy"
|
|
38
|
+
return message
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def interactive_check_fact(result: CheckResult) -> str:
|
|
42
|
+
if result.name == "consent_cloud_reads" and result.status == "pass":
|
|
43
|
+
return _consent_authorized_message(result.message) or result.name
|
|
44
|
+
if result.name == "inventory":
|
|
45
|
+
if result.status in ("optional", "warn"):
|
|
46
|
+
if result.reason_code == "stale":
|
|
47
|
+
return "Potentially stale"
|
|
48
|
+
if result.reason_code == "no_snapshot":
|
|
49
|
+
return (
|
|
50
|
+
result.impact
|
|
51
|
+
or "Quota, reservation, and Savings Plans snapshots are missing."
|
|
52
|
+
)
|
|
53
|
+
if result.status == "pass":
|
|
54
|
+
return "Snapshots loaded"
|
|
55
|
+
if result.message:
|
|
56
|
+
return result.message
|
|
57
|
+
return result.impact or result.name
|
|
58
|
+
if result.status == "pass" and result.message:
|
|
59
|
+
return result.message
|
|
60
|
+
remediation = (result.remediation or "").strip()
|
|
61
|
+
impact = (result.impact or result.message or "").strip()
|
|
62
|
+
message = (result.message or "").strip()
|
|
63
|
+
if remediation:
|
|
64
|
+
if message and message == remediation:
|
|
65
|
+
return impact or remediation
|
|
66
|
+
if impact:
|
|
67
|
+
return f"{impact} {remediation}"
|
|
68
|
+
return remediation
|
|
69
|
+
return impact or message or result.name
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def interactive_muted_detail_lines(result: CheckResult) -> tuple[str, ...]:
|
|
73
|
+
if result.name in ("cloud_identity_aws", "cloud_identity_azure") and result.status == "pass":
|
|
74
|
+
principal = (result.message or "").strip()
|
|
75
|
+
if principal and principal != "redacted":
|
|
76
|
+
label = (
|
|
77
|
+
"Identity/Subscription"
|
|
78
|
+
if result.name == "cloud_identity_azure"
|
|
79
|
+
else "Account/Role"
|
|
80
|
+
)
|
|
81
|
+
return (f"{label}: {principal}",)
|
|
82
|
+
return ()
|
|
83
|
+
if result.name == "aws_price_file" and result.status in ("pass", "warn"):
|
|
84
|
+
lines: list[str] = []
|
|
85
|
+
if result.published_at:
|
|
86
|
+
lines.append(f"Published: {result.published_at}")
|
|
87
|
+
if result.row_count is not None:
|
|
88
|
+
lines.append(f"Rows: {result.row_count}")
|
|
89
|
+
return tuple(lines)
|
|
90
|
+
if result.name == "inventory" and result.status in ("optional", "warn"):
|
|
91
|
+
lines: list[str] = []
|
|
92
|
+
if result.reason_code == "stale" and result.loaded_at:
|
|
93
|
+
lines.append(f"Oldest snapshot: {result.loaded_at}")
|
|
94
|
+
lines.append(_INVENTORY_REFRESH_LINE)
|
|
95
|
+
return tuple(lines)
|
|
96
|
+
return ()
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
"""Human-readable inventory breakdown lines for doctor and bare show commands."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from datetime import datetime, timezone
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from maproom.quotas.azure import AZURE_GENERAL_USAGE_CODES
|
|
9
|
+
from maproom.quotas.family_coverage import (
|
|
10
|
+
family_coverage_summary_line,
|
|
11
|
+
quota_record_name_preview,
|
|
12
|
+
)
|
|
13
|
+
from maproom.quotas.model import LAUNCH_RELEVANT_QUOTA_CODES, count_launch_relevant_records
|
|
14
|
+
from maproom.quotas.status import QuotaState
|
|
15
|
+
from maproom.reservations.status import InventoryState
|
|
16
|
+
from maproom.saving_plans.status import SavingPlanState
|
|
17
|
+
from maproom.snapshot_time import parse_loaded_as_of
|
|
18
|
+
|
|
19
|
+
INVENTORY_FETCH_LINES: tuple[str, ...] = (
|
|
20
|
+
"Downloading AWS EC2 quotas...",
|
|
21
|
+
"Downloading reservations from AWS...",
|
|
22
|
+
"Downloading Savings Plans from AWS...",
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
_AZURE_RESERVATIONS_LINE = "Azure reservations: not collected yet"
|
|
26
|
+
|
|
27
|
+
QUOTAS_GET_HINT = "Refresh with: maproom inventory get"
|
|
28
|
+
_QUOTA_DETAIL_LINE_LIMIT = 40
|
|
29
|
+
RESERVATIONS_GET_HINT = "Refresh with: maproom inventory get"
|
|
30
|
+
SAVING_PLANS_GET_HINT = "Refresh with: maproom inventory get"
|
|
31
|
+
USER_LOCAL_DATA_CLEAR_HINT = "To clear cached data: maproom data clear"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def format_age_ago(loaded_as_of: str | None, *, now: datetime | None = None) -> str:
|
|
35
|
+
parsed = parse_loaded_as_of(loaded_as_of)
|
|
36
|
+
if parsed is None:
|
|
37
|
+
return "unknown"
|
|
38
|
+
current = now or datetime.now(timezone.utc)
|
|
39
|
+
seconds = max(0, int((current - parsed).total_seconds()))
|
|
40
|
+
if seconds < 60:
|
|
41
|
+
unit = "second" if seconds == 1 else "seconds"
|
|
42
|
+
return f"{seconds} {unit}"
|
|
43
|
+
minutes = seconds // 60
|
|
44
|
+
if minutes < 60:
|
|
45
|
+
unit = "minute" if minutes == 1 else "minutes"
|
|
46
|
+
return f"{minutes} {unit}"
|
|
47
|
+
hours = minutes // 60
|
|
48
|
+
if hours < 24:
|
|
49
|
+
unit = "hour" if hours == 1 else "hours"
|
|
50
|
+
return f"{hours} {unit}"
|
|
51
|
+
days = hours // 24
|
|
52
|
+
unit = "day" if days == 1 else "days"
|
|
53
|
+
return f"{days} {unit}"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _is_azure_record(record: dict[str, Any]) -> bool:
|
|
57
|
+
cloud = str(record.get("cloud") or record.get("provider") or "").lower()
|
|
58
|
+
if cloud == "azure":
|
|
59
|
+
return True
|
|
60
|
+
kind = str(record.get("kind") or "").lower()
|
|
61
|
+
return kind.startswith("azure_")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _aws_quota_summary_line(state: QuotaState) -> str:
|
|
65
|
+
if state.parse_error or not state.exists:
|
|
66
|
+
return "AWS EC2 limits: not downloaded yet"
|
|
67
|
+
aws_records = [r for r in state.records if not _is_azure_record(r)]
|
|
68
|
+
if not aws_records:
|
|
69
|
+
if state.record_count == 0:
|
|
70
|
+
return "AWS EC2 limits: empty file (last AWS read succeeded)"
|
|
71
|
+
return "AWS EC2 limits: not downloaded yet"
|
|
72
|
+
launch_count = count_launch_relevant_records(aws_records)
|
|
73
|
+
total = len(aws_records)
|
|
74
|
+
line = f"AWS EC2 limits: {total} saved locally"
|
|
75
|
+
if launch_count and launch_count == total:
|
|
76
|
+
line += " (only the main CPU limits maproom checks for resizes)"
|
|
77
|
+
return line
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _azure_quota_summary_line(state: QuotaState) -> str:
|
|
81
|
+
if state.parse_error or not state.exists:
|
|
82
|
+
return "Azure VM limits: not downloaded yet"
|
|
83
|
+
azure_records = [r for r in state.records if _is_azure_record(r)]
|
|
84
|
+
if not azure_records:
|
|
85
|
+
aws_records = [r for r in state.records if not _is_azure_record(r)]
|
|
86
|
+
if aws_records:
|
|
87
|
+
return (
|
|
88
|
+
"Azure VM limits: not in this file (last download was AWS only -- "
|
|
89
|
+
"run `maproom inventory get` after `az login` to add Azure)"
|
|
90
|
+
)
|
|
91
|
+
return "Azure VM limits: not downloaded yet"
|
|
92
|
+
total = len(azure_records)
|
|
93
|
+
general = sum(
|
|
94
|
+
1
|
|
95
|
+
for record in azure_records
|
|
96
|
+
if str(record.get("quota_code") or "") in AZURE_GENERAL_USAGE_CODES
|
|
97
|
+
)
|
|
98
|
+
line = f"Azure VM limits: {total} saved locally"
|
|
99
|
+
if general and general == total:
|
|
100
|
+
line += " (only the main CPU limits maproom checks for resizes)"
|
|
101
|
+
return line
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _reservation_region_label(state: InventoryState) -> str:
|
|
105
|
+
if state.region:
|
|
106
|
+
return state.region
|
|
107
|
+
for record in state.records:
|
|
108
|
+
if record.get("kind") == "ec2_reserved_instance":
|
|
109
|
+
region = str(record.get("region") or "")
|
|
110
|
+
if region and region != "unknown":
|
|
111
|
+
return region
|
|
112
|
+
return "the configured region"
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _aws_reservation_summary_line(state: InventoryState) -> str:
|
|
116
|
+
if state.parse_error or not state.exists:
|
|
117
|
+
return "AWS reservations: not loaded"
|
|
118
|
+
reserved = [
|
|
119
|
+
record
|
|
120
|
+
for record in state.records
|
|
121
|
+
if isinstance(record, dict)
|
|
122
|
+
and not _is_azure_record(record)
|
|
123
|
+
and record.get("kind") == "ec2_reserved_instance"
|
|
124
|
+
]
|
|
125
|
+
if not reserved:
|
|
126
|
+
region = _reservation_region_label(state)
|
|
127
|
+
return (
|
|
128
|
+
f"EC2 Reserved Instances: none in {region} "
|
|
129
|
+
"(read succeeded)"
|
|
130
|
+
)
|
|
131
|
+
count = len(reserved)
|
|
132
|
+
unit = "instance" if count == 1 else "instances"
|
|
133
|
+
region = _reservation_region_label(state)
|
|
134
|
+
return f"EC2 Reserved Instances: {count} {unit} in {region}"
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _saving_plan_summary_line(state: SavingPlanState) -> str:
|
|
138
|
+
if state.parse_error or not state.exists:
|
|
139
|
+
return "Savings Plans: not loaded"
|
|
140
|
+
plans = [
|
|
141
|
+
record
|
|
142
|
+
for record in state.records
|
|
143
|
+
if isinstance(record, dict) and record.get("kind") == "savings_plan"
|
|
144
|
+
]
|
|
145
|
+
if not plans:
|
|
146
|
+
return (
|
|
147
|
+
"Savings Plans: none in this account "
|
|
148
|
+
"(read succeeded)"
|
|
149
|
+
)
|
|
150
|
+
count = len(plans)
|
|
151
|
+
unit = "plan" if count == 1 else "plans"
|
|
152
|
+
return f"Savings Plans: {count} {unit} in this account"
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def quota_inventory_detail_lines(state: QuotaState) -> tuple[str, ...]:
|
|
156
|
+
if state.parse_error or not state.exists:
|
|
157
|
+
return (
|
|
158
|
+
"AWS EC2 limits: not downloaded yet",
|
|
159
|
+
"Azure VM limits: not downloaded yet",
|
|
160
|
+
"Last updated: not available",
|
|
161
|
+
)
|
|
162
|
+
age = format_age_ago(state.loaded_as_of)
|
|
163
|
+
loaded_line = f"Last updated {age} ago"
|
|
164
|
+
if state.is_stale:
|
|
165
|
+
loaded_line += " (getting old -- consider refreshing)"
|
|
166
|
+
return (
|
|
167
|
+
str(state.snapshot_path),
|
|
168
|
+
"",
|
|
169
|
+
_aws_quota_summary_line(state),
|
|
170
|
+
_azure_quota_summary_line(state),
|
|
171
|
+
loaded_line,
|
|
172
|
+
"",
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _append_quota_detail_block(
|
|
177
|
+
lines: list[str],
|
|
178
|
+
*,
|
|
179
|
+
heading: str,
|
|
180
|
+
records: list[dict],
|
|
181
|
+
priority_codes: frozenset[str],
|
|
182
|
+
) -> None:
|
|
183
|
+
if not records:
|
|
184
|
+
return
|
|
185
|
+
if lines and lines[-1] != "":
|
|
186
|
+
lines.append("")
|
|
187
|
+
lines.append(f" {heading}")
|
|
188
|
+
|
|
189
|
+
def _sort_key(record: dict) -> tuple[int, str, str]:
|
|
190
|
+
code = str(record.get("quota_code") or "")
|
|
191
|
+
name = str(record.get("quota_name") or code)
|
|
192
|
+
launch = 0 if code in priority_codes else 1
|
|
193
|
+
return (launch, name.lower(), code)
|
|
194
|
+
|
|
195
|
+
detail_records = sorted(records, key=_sort_key)
|
|
196
|
+
omitted = 0
|
|
197
|
+
if len(detail_records) > _QUOTA_DETAIL_LINE_LIMIT:
|
|
198
|
+
omitted = len(detail_records) - _QUOTA_DETAIL_LINE_LIMIT
|
|
199
|
+
detail_records = detail_records[:_QUOTA_DETAIL_LINE_LIMIT]
|
|
200
|
+
|
|
201
|
+
for record in detail_records:
|
|
202
|
+
code = str(record.get("quota_code") or "")
|
|
203
|
+
name = str(record.get("quota_name") or code)
|
|
204
|
+
limit = float(record.get("value") or 0)
|
|
205
|
+
usage = float(record.get("usage") or 0)
|
|
206
|
+
headroom = limit - usage
|
|
207
|
+
region = str(record.get("region") or "unknown")
|
|
208
|
+
marker = ""
|
|
209
|
+
if code in priority_codes:
|
|
210
|
+
marker = " [used when maproom checks resize CPU headroom]"
|
|
211
|
+
lines.append(
|
|
212
|
+
f" {name} ({region}) -- cap {limit:g}, in use {usage:g}, "
|
|
213
|
+
f"room left {headroom:g}{marker}"
|
|
214
|
+
)
|
|
215
|
+
if omitted:
|
|
216
|
+
lines.append(
|
|
217
|
+
f" ... and {omitted} more in the local snapshot"
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def quota_record_lines(state: QuotaState, *, show_all: bool = False) -> list[str]:
|
|
222
|
+
if state.parse_error or not state.exists or not state.records:
|
|
223
|
+
return []
|
|
224
|
+
aws_records = [
|
|
225
|
+
record
|
|
226
|
+
for record in state.records
|
|
227
|
+
if isinstance(record, dict) and not _is_azure_record(record)
|
|
228
|
+
]
|
|
229
|
+
azure_records = [
|
|
230
|
+
record
|
|
231
|
+
for record in state.records
|
|
232
|
+
if isinstance(record, dict) and _is_azure_record(record)
|
|
233
|
+
]
|
|
234
|
+
lines: list[str] = ["", "Quota limits:"]
|
|
235
|
+
if show_all:
|
|
236
|
+
coverage = family_coverage_summary_line(aws_records)
|
|
237
|
+
if coverage:
|
|
238
|
+
lines.append(f" {coverage}")
|
|
239
|
+
catalog = quota_record_name_preview(aws_records)
|
|
240
|
+
if catalog:
|
|
241
|
+
lines.append(f" {catalog}")
|
|
242
|
+
detail_aws = aws_records
|
|
243
|
+
detail_azure = azure_records
|
|
244
|
+
else:
|
|
245
|
+
detail_aws = [
|
|
246
|
+
record
|
|
247
|
+
for record in aws_records
|
|
248
|
+
if str(record.get("quota_code") or "") in LAUNCH_RELEVANT_QUOTA_CODES
|
|
249
|
+
]
|
|
250
|
+
detail_azure = [
|
|
251
|
+
record
|
|
252
|
+
for record in azure_records
|
|
253
|
+
if str(record.get("quota_code") or "") in AZURE_GENERAL_USAGE_CODES
|
|
254
|
+
]
|
|
255
|
+
if not detail_aws and not detail_azure:
|
|
256
|
+
lines.append(" Launch-relevant limits: none in this file.")
|
|
257
|
+
_append_quota_detail_block(
|
|
258
|
+
lines,
|
|
259
|
+
heading="AWS EC2:",
|
|
260
|
+
records=detail_aws,
|
|
261
|
+
priority_codes=LAUNCH_RELEVANT_QUOTA_CODES,
|
|
262
|
+
)
|
|
263
|
+
_append_quota_detail_block(
|
|
264
|
+
lines,
|
|
265
|
+
heading="Azure VMs:",
|
|
266
|
+
records=detail_azure,
|
|
267
|
+
priority_codes=AZURE_GENERAL_USAGE_CODES,
|
|
268
|
+
)
|
|
269
|
+
hidden = (len(aws_records) + len(azure_records)) - (len(detail_aws) + len(detail_azure))
|
|
270
|
+
if hidden > 0:
|
|
271
|
+
lines.append(" More limits are in the local snapshot.")
|
|
272
|
+
return lines
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def reservation_inventory_detail_lines(state: InventoryState) -> tuple[str, ...]:
|
|
276
|
+
if state.parse_error or not state.exists:
|
|
277
|
+
return (
|
|
278
|
+
"AWS reservations: not loaded",
|
|
279
|
+
_AZURE_RESERVATIONS_LINE,
|
|
280
|
+
"Loaded: not available",
|
|
281
|
+
)
|
|
282
|
+
age = format_age_ago(state.loaded_as_of)
|
|
283
|
+
loaded_line = f"Loaded {age} ago"
|
|
284
|
+
if state.is_stale:
|
|
285
|
+
loaded_line += " (stale)"
|
|
286
|
+
return (
|
|
287
|
+
str(state.snapshot_path),
|
|
288
|
+
"",
|
|
289
|
+
_aws_reservation_summary_line(state),
|
|
290
|
+
_AZURE_RESERVATIONS_LINE,
|
|
291
|
+
loaded_line,
|
|
292
|
+
"",
|
|
293
|
+
)
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def _join_detail_groups(*groups: tuple[str, ...]) -> tuple[str, ...]:
|
|
297
|
+
lines: list[str] = []
|
|
298
|
+
for group in groups:
|
|
299
|
+
block = list(group)
|
|
300
|
+
while block and block[0] == "":
|
|
301
|
+
block.pop(0)
|
|
302
|
+
while block and block[-1] == "":
|
|
303
|
+
block.pop()
|
|
304
|
+
if not block:
|
|
305
|
+
continue
|
|
306
|
+
if lines:
|
|
307
|
+
lines.append("")
|
|
308
|
+
lines.extend(block)
|
|
309
|
+
return tuple(lines)
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def inventory_detail_lines(
|
|
313
|
+
quotas: QuotaState,
|
|
314
|
+
reservations: InventoryState,
|
|
315
|
+
saving_plans: SavingPlanState,
|
|
316
|
+
) -> tuple[str, ...]:
|
|
317
|
+
"""One inventory block: quotas, reservations, then savings plans."""
|
|
318
|
+
return _join_detail_groups(
|
|
319
|
+
quota_inventory_detail_lines(quotas),
|
|
320
|
+
reservation_inventory_detail_lines(reservations),
|
|
321
|
+
saving_plan_inventory_detail_lines(saving_plans),
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def saving_plan_inventory_detail_lines(state: SavingPlanState) -> tuple[str, ...]:
|
|
326
|
+
if state.parse_error or not state.exists:
|
|
327
|
+
return (
|
|
328
|
+
"Savings Plans: not loaded",
|
|
329
|
+
"Loaded: not available",
|
|
330
|
+
)
|
|
331
|
+
age = format_age_ago(state.loaded_as_of)
|
|
332
|
+
loaded_line = f"Loaded {age} ago"
|
|
333
|
+
if state.is_stale:
|
|
334
|
+
loaded_line += " (stale)"
|
|
335
|
+
return (
|
|
336
|
+
str(state.snapshot_path),
|
|
337
|
+
"",
|
|
338
|
+
_saving_plan_summary_line(state),
|
|
339
|
+
loaded_line,
|
|
340
|
+
"",
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def reservation_record_lines(state: InventoryState) -> list[str]:
|
|
345
|
+
if state.parse_error or not state.exists or not state.records:
|
|
346
|
+
return []
|
|
347
|
+
lines: list[str] = ["", "Reservations:"]
|
|
348
|
+
for record in state.records:
|
|
349
|
+
if not isinstance(record, dict):
|
|
350
|
+
continue
|
|
351
|
+
kind = record.get("kind")
|
|
352
|
+
if kind == "ec2_reserved_instance":
|
|
353
|
+
lines.append(
|
|
354
|
+
" "
|
|
355
|
+
f"{record.get('instance_type')} · {record.get('region')} · "
|
|
356
|
+
f"{record.get('quantity')} instance(s) · "
|
|
357
|
+
f"family {record.get('instance_family')} · "
|
|
358
|
+
f"{record.get('state') or 'unknown'} · "
|
|
359
|
+
f"ends {record.get('end') or 'unknown'}"
|
|
360
|
+
)
|
|
361
|
+
return lines
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
def saving_plan_record_lines(state: SavingPlanState) -> list[str]:
|
|
365
|
+
if state.parse_error or not state.exists or not state.records:
|
|
366
|
+
return []
|
|
367
|
+
lines: list[str] = ["", "Savings Plans:"]
|
|
368
|
+
for record in state.records:
|
|
369
|
+
if not isinstance(record, dict) or record.get("kind") != "savings_plan":
|
|
370
|
+
continue
|
|
371
|
+
lines.append(
|
|
372
|
+
" "
|
|
373
|
+
f"{record.get('plan_type')} · {record.get('region')} · "
|
|
374
|
+
f"{record.get('state') or 'unknown'} · "
|
|
375
|
+
f"commitment {record.get('commitment') or 'unknown'}"
|
|
376
|
+
)
|
|
377
|
+
return lines
|