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,174 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema_version": 1,
|
|
3
|
+
"files": [
|
|
4
|
+
{
|
|
5
|
+
"path": "aws/aws_prices.csv",
|
|
6
|
+
"kind": "pricing",
|
|
7
|
+
"cloud": "aws",
|
|
8
|
+
"published_at": "2026-10-01",
|
|
9
|
+
"source": "data-investigator/share/aws-ec2-ondemand-linux-v1.json",
|
|
10
|
+
"source_kind": "share",
|
|
11
|
+
"source_ref": "aws-ec2-ondemand-linux-v1.json",
|
|
12
|
+
"generator": "maproom/reference_data/scripts/import_price_file.py",
|
|
13
|
+
"generated_at": "2026-11-01T22:21:22Z",
|
|
14
|
+
"row_count": 25561,
|
|
15
|
+
"regions": [
|
|
16
|
+
"af-south-1",
|
|
17
|
+
"af-south-1-los-1",
|
|
18
|
+
"ap-east-1",
|
|
19
|
+
"ap-east-2",
|
|
20
|
+
"ap-northeast-1",
|
|
21
|
+
"ap-northeast-1-tpe-1",
|
|
22
|
+
"ap-northeast-1-wl1-kix1",
|
|
23
|
+
"ap-northeast-1-wl1-nrt1",
|
|
24
|
+
"ap-northeast-2",
|
|
25
|
+
"ap-northeast-2-wl1-cjj1",
|
|
26
|
+
"ap-northeast-2-wl1-sel1",
|
|
27
|
+
"ap-northeast-3",
|
|
28
|
+
"ap-south-1",
|
|
29
|
+
"ap-south-1-ccu-1",
|
|
30
|
+
"ap-south-1-del-1",
|
|
31
|
+
"ap-south-2",
|
|
32
|
+
"ap-southeast-1",
|
|
33
|
+
"ap-southeast-1-bkk-1",
|
|
34
|
+
"ap-southeast-1-han-1",
|
|
35
|
+
"ap-southeast-1-mnl-1",
|
|
36
|
+
"ap-southeast-2",
|
|
37
|
+
"ap-southeast-2-akl-1",
|
|
38
|
+
"ap-southeast-2-per-1",
|
|
39
|
+
"ap-southeast-3",
|
|
40
|
+
"ap-southeast-4",
|
|
41
|
+
"ap-southeast-5",
|
|
42
|
+
"ap-southeast-6",
|
|
43
|
+
"ap-southeast-7",
|
|
44
|
+
"ca-central-1",
|
|
45
|
+
"ca-central-1-wl1-yto1",
|
|
46
|
+
"ca-west-1",
|
|
47
|
+
"eu-central-1",
|
|
48
|
+
"eu-central-1-ath-1",
|
|
49
|
+
"eu-central-1-ham-1",
|
|
50
|
+
"eu-central-1-ist-1",
|
|
51
|
+
"eu-central-1-waw-1",
|
|
52
|
+
"eu-central-1-wl1-ber1",
|
|
53
|
+
"eu-central-1-wl1-dtm1",
|
|
54
|
+
"eu-central-1-wl1-muc1",
|
|
55
|
+
"eu-central-2",
|
|
56
|
+
"eu-north-1",
|
|
57
|
+
"eu-north-1-cph-1",
|
|
58
|
+
"eu-north-1-hel-1",
|
|
59
|
+
"eu-south-1",
|
|
60
|
+
"eu-south-2",
|
|
61
|
+
"eu-west-1",
|
|
62
|
+
"eu-west-2",
|
|
63
|
+
"eu-west-2-wl1-lon1",
|
|
64
|
+
"eu-west-2-wl1-man1",
|
|
65
|
+
"eu-west-2-wl2-man1",
|
|
66
|
+
"eu-west-3",
|
|
67
|
+
"eu-west-3-wl1-cmn1",
|
|
68
|
+
"eu-west-3-wl1-dss1",
|
|
69
|
+
"il-central-1",
|
|
70
|
+
"me-central-1",
|
|
71
|
+
"me-south-1",
|
|
72
|
+
"me-south-1-mct-1",
|
|
73
|
+
"mx-central-1",
|
|
74
|
+
"sa-east-1",
|
|
75
|
+
"us-east-1",
|
|
76
|
+
"us-east-1-atl-1",
|
|
77
|
+
"us-east-1-bos-1",
|
|
78
|
+
"us-east-1-bue-1",
|
|
79
|
+
"us-east-1-chi-1",
|
|
80
|
+
"us-east-1-dfw-1",
|
|
81
|
+
"us-east-1-iah-1",
|
|
82
|
+
"us-east-1-lim-1",
|
|
83
|
+
"us-east-1-mci-1",
|
|
84
|
+
"us-east-1-mia-1",
|
|
85
|
+
"us-east-1-msp-1",
|
|
86
|
+
"us-east-1-nyc-1",
|
|
87
|
+
"us-east-1-phl-1",
|
|
88
|
+
"us-east-1-qro-1",
|
|
89
|
+
"us-east-1-scl-1",
|
|
90
|
+
"us-east-1-wl1",
|
|
91
|
+
"us-east-1-wl1-atl1",
|
|
92
|
+
"us-east-1-wl1-bna1",
|
|
93
|
+
"us-east-1-wl1-chi1",
|
|
94
|
+
"us-east-1-wl1-clt1",
|
|
95
|
+
"us-east-1-wl1-dfw1",
|
|
96
|
+
"us-east-1-wl1-dtw1",
|
|
97
|
+
"us-east-1-wl1-foe1",
|
|
98
|
+
"us-east-1-wl1-iah1",
|
|
99
|
+
"us-east-1-wl1-mia1",
|
|
100
|
+
"us-east-1-wl1-msp1",
|
|
101
|
+
"us-east-1-wl1-nyc1",
|
|
102
|
+
"us-east-1-wl1-tpa1",
|
|
103
|
+
"us-east-1-wl1-was1",
|
|
104
|
+
"us-east-2",
|
|
105
|
+
"us-gov-east-1",
|
|
106
|
+
"us-gov-west-1",
|
|
107
|
+
"us-west-1",
|
|
108
|
+
"us-west-2",
|
|
109
|
+
"us-west-2-den-1",
|
|
110
|
+
"us-west-2-hnl-1",
|
|
111
|
+
"us-west-2-las-1",
|
|
112
|
+
"us-west-2-lax-1",
|
|
113
|
+
"us-west-2-pdx-1",
|
|
114
|
+
"us-west-2-phx-1",
|
|
115
|
+
"us-west-2-sea-1",
|
|
116
|
+
"us-west-2-wl1",
|
|
117
|
+
"us-west-2-wl1-den1",
|
|
118
|
+
"us-west-2-wl1-las1",
|
|
119
|
+
"us-west-2-wl1-lax1",
|
|
120
|
+
"us-west-2-wl1-phx1",
|
|
121
|
+
"us-west-2-wl1-sea1"
|
|
122
|
+
]
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"path": "aws/instance_types.csv",
|
|
126
|
+
"kind": "instance_types",
|
|
127
|
+
"cloud": "aws",
|
|
128
|
+
"source": "compute-benchmarking/vended-results/instance_specs.csv",
|
|
129
|
+
"source_kind": "share",
|
|
130
|
+
"row_count": 1345
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"path": "aws/capabilities.csv",
|
|
134
|
+
"kind": "capabilities",
|
|
135
|
+
"cloud": "aws",
|
|
136
|
+
"source": "compute-benchmarking/vended-results/instance_specs.csv",
|
|
137
|
+
"source_kind": "share",
|
|
138
|
+
"row_count": 1345
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"path": "azure/azure_prices.csv",
|
|
142
|
+
"kind": "pricing",
|
|
143
|
+
"cloud": "azure",
|
|
144
|
+
"published_at": null,
|
|
145
|
+
"source_kind": "local",
|
|
146
|
+
"row_count": 0
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
"path": "azure/vm_types.csv",
|
|
150
|
+
"kind": "vm_types",
|
|
151
|
+
"cloud": "azure",
|
|
152
|
+
"source_kind": "local",
|
|
153
|
+
"row_count": 0
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
"path": "benchmarks/safe-moves-v1.json",
|
|
157
|
+
"kind": "safe_moves",
|
|
158
|
+
"source": "compute-benchmarking/vended-results/safe-moves-v1.json",
|
|
159
|
+
"source_kind": "share"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"path": "benchmarks/cpu-lscpu-v2-instances.json",
|
|
163
|
+
"kind": "lscpu",
|
|
164
|
+
"source_kind": "local"
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
"path": "benchmarks/forbidden_terms.json",
|
|
168
|
+
"kind": "forbidden_terms",
|
|
169
|
+
"source": "compute-benchmarking/vended-results/maproom-proprietary-tokens-v1.json",
|
|
170
|
+
"source_kind": "share",
|
|
171
|
+
"in_wheel": false
|
|
172
|
+
}
|
|
173
|
+
]
|
|
174
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""Read and update maproom/reference_data/manifest.json."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from datetime import datetime, timezone
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
REFERENCE_DATA_DIR = Path(__file__).resolve().parent
|
|
11
|
+
MANIFEST_PATH = REFERENCE_DATA_DIR / "manifest.json"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def utc_now_iso() -> str:
|
|
15
|
+
return datetime.now(timezone.utc).replace(microsecond=0).isoformat().replace(
|
|
16
|
+
"+00:00", "Z"
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def load_manifest(path: Path | None = None) -> dict[str, Any]:
|
|
21
|
+
target = path or MANIFEST_PATH
|
|
22
|
+
if not target.is_file():
|
|
23
|
+
return {"schema_version": 1, "files": []}
|
|
24
|
+
document = json.loads(target.read_text(encoding="utf-8"))
|
|
25
|
+
if not isinstance(document, dict):
|
|
26
|
+
return {"schema_version": 1, "files": []}
|
|
27
|
+
return document
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def file_entry(manifest: dict[str, Any], relative_path: str) -> dict[str, Any] | None:
|
|
31
|
+
files = manifest.get("files")
|
|
32
|
+
if not isinstance(files, list):
|
|
33
|
+
return None
|
|
34
|
+
for item in files:
|
|
35
|
+
if isinstance(item, dict) and str(item.get("path") or "") == relative_path:
|
|
36
|
+
return item
|
|
37
|
+
return None
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def upsert_file_entry(
|
|
41
|
+
relative_path: str,
|
|
42
|
+
*,
|
|
43
|
+
kind: str,
|
|
44
|
+
updates: dict[str, Any],
|
|
45
|
+
path: Path | None = None,
|
|
46
|
+
) -> dict[str, Any]:
|
|
47
|
+
target = path or MANIFEST_PATH
|
|
48
|
+
manifest = load_manifest(target)
|
|
49
|
+
files = manifest.setdefault("files", [])
|
|
50
|
+
if not isinstance(files, list):
|
|
51
|
+
files = []
|
|
52
|
+
manifest["files"] = files
|
|
53
|
+
entry = file_entry(manifest, relative_path)
|
|
54
|
+
if entry is None:
|
|
55
|
+
entry = {"path": relative_path, "kind": kind}
|
|
56
|
+
files.append(entry)
|
|
57
|
+
entry["kind"] = kind
|
|
58
|
+
entry.update(updates)
|
|
59
|
+
manifest["schema_version"] = int(manifest.get("schema_version") or 1)
|
|
60
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
61
|
+
target.write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
|
|
62
|
+
return entry
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def published_at_for(relative_path: str, *, path: Path | None = None) -> str:
|
|
66
|
+
entry = file_entry(load_manifest(path), relative_path)
|
|
67
|
+
if entry is None:
|
|
68
|
+
return ""
|
|
69
|
+
return str(entry.get("published_at") or "")
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Reservation inventory get, load, and read-side status."""
|
|
2
|
+
|
|
3
|
+
from maproom.reservations.status import (
|
|
4
|
+
InventoryState,
|
|
5
|
+
read_inventory_state,
|
|
6
|
+
reservation_coverage_missing,
|
|
7
|
+
reservations_tty_segment,
|
|
8
|
+
stale_reservation_warning,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"InventoryState",
|
|
13
|
+
"read_inventory_state",
|
|
14
|
+
"reservation_coverage_missing",
|
|
15
|
+
"reservations_tty_segment",
|
|
16
|
+
"stale_reservation_warning",
|
|
17
|
+
]
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""AWS reservation inventory collection."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from maproom.reservations.model import ReservationError, normalize_records_from_aws
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _parse_runner_json(result: Any, operation: str) -> dict[str, Any]:
|
|
12
|
+
if result.exit_code != 0:
|
|
13
|
+
detail = (result.stderr or "").strip() or f"exit code {result.exit_code}"
|
|
14
|
+
raise ReservationError(f"{operation} failed: {detail}")
|
|
15
|
+
if not result.stdout.strip():
|
|
16
|
+
raise ReservationError(f"{operation} returned empty output")
|
|
17
|
+
try:
|
|
18
|
+
data = json.loads(result.stdout)
|
|
19
|
+
except json.JSONDecodeError as exc:
|
|
20
|
+
raise ReservationError(f"{operation} returned invalid JSON: {exc}") from exc
|
|
21
|
+
if not isinstance(data, dict):
|
|
22
|
+
raise ReservationError(f"{operation} returned unexpected JSON shape")
|
|
23
|
+
return data
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _default_region(runner: Any) -> str:
|
|
27
|
+
result = runner.run(
|
|
28
|
+
"aws",
|
|
29
|
+
["configure", "get", "region"],
|
|
30
|
+
record=False,
|
|
31
|
+
api_id="aws_configure_get_region",
|
|
32
|
+
)
|
|
33
|
+
if result.exit_code == 0 and result.stdout.strip():
|
|
34
|
+
return result.stdout.strip()
|
|
35
|
+
return "us-east-1"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _list_from_payload(data: dict[str, Any], key: str, operation: str) -> list[dict[str, Any]]:
|
|
39
|
+
raw = data.get(key)
|
|
40
|
+
if raw is None:
|
|
41
|
+
return []
|
|
42
|
+
if not isinstance(raw, list):
|
|
43
|
+
raise ReservationError(f"{operation} {key} is not a list")
|
|
44
|
+
return [item for item in raw if isinstance(item, dict)]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def fetch_reserved_instances(runner: Any, *, region: str) -> list[dict[str, Any]]:
|
|
48
|
+
"""Every EC2 Reserved Instance the regional API returns, any state."""
|
|
49
|
+
result = runner.run(
|
|
50
|
+
"aws",
|
|
51
|
+
[
|
|
52
|
+
"ec2",
|
|
53
|
+
"describe-reserved-instances",
|
|
54
|
+
"--region",
|
|
55
|
+
region,
|
|
56
|
+
"--output",
|
|
57
|
+
"json",
|
|
58
|
+
],
|
|
59
|
+
record=False,
|
|
60
|
+
pagination="merge",
|
|
61
|
+
api_id="aws_ec2_describe_reserved_instances",
|
|
62
|
+
)
|
|
63
|
+
data = _parse_runner_json(result, f"aws ec2 describe-reserved-instances ({region})")
|
|
64
|
+
return _list_from_payload(data, "ReservedInstances", "describe-reserved-instances")
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def fetch_aws_inventory(
|
|
68
|
+
runner: Any,
|
|
69
|
+
*,
|
|
70
|
+
region: str | None = None,
|
|
71
|
+
) -> tuple[list[dict[str, Any]], str]:
|
|
72
|
+
"""Every EC2 Reserved Instance in the current region, any state."""
|
|
73
|
+
resolved_region = region or _default_region(runner)
|
|
74
|
+
reserved = fetch_reserved_instances(runner, region=resolved_region)
|
|
75
|
+
records = normalize_records_from_aws(reserved, region=resolved_region)
|
|
76
|
+
return records, resolved_region
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Azure reserved VM instance inventory."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from maproom.reservations.model import ReservationError, normalize_records_from_azure
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def fetch_azure_reservations(runner: Any) -> list[dict[str, Any]]:
|
|
12
|
+
"""Every reserved VM the subscription list returns."""
|
|
13
|
+
result = runner.run(
|
|
14
|
+
"azure",
|
|
15
|
+
["reservations", "list", "--output", "json", "--only-show-errors"],
|
|
16
|
+
record=False,
|
|
17
|
+
api_id="azure_reservations_list",
|
|
18
|
+
)
|
|
19
|
+
if int(result.exit_code) != 0:
|
|
20
|
+
detail = (result.stderr or "").strip() or f"exit code {result.exit_code}"
|
|
21
|
+
raise ReservationError(f"az reservations list failed: {detail}")
|
|
22
|
+
if not (result.stdout or "").strip():
|
|
23
|
+
return []
|
|
24
|
+
try:
|
|
25
|
+
payload = json.loads(result.stdout)
|
|
26
|
+
except json.JSONDecodeError as exc:
|
|
27
|
+
raise ReservationError(f"az reservations list returned invalid JSON: {exc}") from exc
|
|
28
|
+
items = payload if isinstance(payload, list) else []
|
|
29
|
+
if isinstance(payload, dict):
|
|
30
|
+
raw = payload.get("value") or payload.get("reservations") or []
|
|
31
|
+
items = raw if isinstance(raw, list) else []
|
|
32
|
+
return [item for item in items if isinstance(item, dict)]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def fetch_azure_inventory(runner: Any) -> list[dict[str, Any]]:
|
|
36
|
+
return normalize_records_from_azure(fetch_azure_reservations(runner))
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"""Fetch and save helpers used by maproom inventory."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from maproom.cliio.runner import CliBelowFloorError
|
|
11
|
+
|
|
12
|
+
from maproom.cli_floors import ensure_cli_floors, fail_cli_floor
|
|
13
|
+
from maproom.consent import require_cloud_read_consent
|
|
14
|
+
from maproom.exitcodes import SUCCESS
|
|
15
|
+
from maproom.mock_environment import MockEnvironmentError, command_runner
|
|
16
|
+
from maproom.inventory.account_identity import resolve_aws_account
|
|
17
|
+
from maproom.inventory.accounts import AccountIdentityError
|
|
18
|
+
from maproom.inventory.messages import (
|
|
19
|
+
reservations_fetch_progress_line,
|
|
20
|
+
reservations_get_human_lines,
|
|
21
|
+
reservations_get_summary_message,
|
|
22
|
+
)
|
|
23
|
+
from maproom.output.json_envelope import (
|
|
24
|
+
finish_consent_gate,
|
|
25
|
+
print_command_error as _print_error,
|
|
26
|
+
print_command_success as _print_success,
|
|
27
|
+
)
|
|
28
|
+
from maproom.reservations import aws, store
|
|
29
|
+
from maproom.reservations.load import load_payer_file
|
|
30
|
+
from maproom.reservations.model import ReservationError, build_snapshot
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def cmd_reservations_get(args: argparse.Namespace) -> int:
|
|
34
|
+
as_json = bool(args.json)
|
|
35
|
+
invoked = "reservations get"
|
|
36
|
+
try:
|
|
37
|
+
runner = command_runner()
|
|
38
|
+
except MockEnvironmentError as exc:
|
|
39
|
+
return _print_error(exc.message, as_json=as_json, invoked=invoked)
|
|
40
|
+
try:
|
|
41
|
+
ensure_cli_floors(runner=runner)
|
|
42
|
+
except CliBelowFloorError as exc:
|
|
43
|
+
return fail_cli_floor(exc, as_json=as_json, invoked=invoked)
|
|
44
|
+
|
|
45
|
+
gate = require_cloud_read_consent(
|
|
46
|
+
consent_cloud_reads=bool(getattr(args, "consent_cloud_reads", False)),
|
|
47
|
+
quiet=as_json,
|
|
48
|
+
)
|
|
49
|
+
if not gate.allowed:
|
|
50
|
+
return finish_consent_gate(gate, as_json=as_json, invoked=invoked)
|
|
51
|
+
|
|
52
|
+
aws_region = getattr(args, "region", None) or None
|
|
53
|
+
if not as_json:
|
|
54
|
+
print(reservations_fetch_progress_line(), file=sys.stderr)
|
|
55
|
+
|
|
56
|
+
try:
|
|
57
|
+
account = resolve_aws_account(runner)
|
|
58
|
+
except AccountIdentityError as exc:
|
|
59
|
+
return _print_error(exc.message, as_json=as_json, invoked=invoked)
|
|
60
|
+
|
|
61
|
+
try:
|
|
62
|
+
records, region = aws.fetch_aws_inventory(runner, region=aws_region)
|
|
63
|
+
except ReservationError as exc:
|
|
64
|
+
return _print_error(exc.message, as_json=as_json, invoked=invoked)
|
|
65
|
+
|
|
66
|
+
snapshot = build_snapshot(records, source="aws_get", region=region)
|
|
67
|
+
snapshot["cloud"] = account.cloud
|
|
68
|
+
snapshot["account_id"] = account.account_id
|
|
69
|
+
if account.alias:
|
|
70
|
+
snapshot["account_alias"] = account.alias
|
|
71
|
+
err = store.write_account_snapshot(snapshot, account)
|
|
72
|
+
if err is not None:
|
|
73
|
+
return _print_error(err.message, as_json=as_json, invoked=invoked)
|
|
74
|
+
|
|
75
|
+
path = store.account_snapshot_path(account)
|
|
76
|
+
record_count = int(snapshot["record_count"])
|
|
77
|
+
loaded_as_of = str(snapshot["loaded_as_of"])
|
|
78
|
+
pool = store.pool_summary()
|
|
79
|
+
pool_records = int(pool.get("record_count") or 0)
|
|
80
|
+
pool_accounts = int(pool.get("account_count") or 0)
|
|
81
|
+
if as_json:
|
|
82
|
+
_print_success(
|
|
83
|
+
"reservations_get",
|
|
84
|
+
"maproom.reservations_get",
|
|
85
|
+
invoked,
|
|
86
|
+
{
|
|
87
|
+
"snapshot_path": str(path),
|
|
88
|
+
"loaded_as_of": loaded_as_of,
|
|
89
|
+
"record_count": record_count,
|
|
90
|
+
"source": snapshot["source"],
|
|
91
|
+
"region": region,
|
|
92
|
+
"pool_record_count": pool_records,
|
|
93
|
+
"pool_account_count": pool_accounts,
|
|
94
|
+
"message": reservations_get_summary_message(
|
|
95
|
+
record_count,
|
|
96
|
+
region=region,
|
|
97
|
+
pool_record_count=pool_records,
|
|
98
|
+
pool_account_count=pool_accounts,
|
|
99
|
+
),
|
|
100
|
+
},
|
|
101
|
+
)
|
|
102
|
+
else:
|
|
103
|
+
for line in reservations_get_human_lines(
|
|
104
|
+
record_count=record_count,
|
|
105
|
+
path=str(path),
|
|
106
|
+
loaded_as_of=loaded_as_of,
|
|
107
|
+
region=region,
|
|
108
|
+
records=list(snapshot.get("records") or []),
|
|
109
|
+
account_record_count=record_count,
|
|
110
|
+
pool_record_count=pool_records,
|
|
111
|
+
pool_account_count=pool_accounts,
|
|
112
|
+
):
|
|
113
|
+
print(line)
|
|
114
|
+
return SUCCESS
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def cmd_reservations_load(args: argparse.Namespace) -> int:
|
|
118
|
+
as_json = bool(args.json)
|
|
119
|
+
invoked = "reservations load"
|
|
120
|
+
payer_path = Path(args.path)
|
|
121
|
+
try:
|
|
122
|
+
records = load_payer_file(payer_path)
|
|
123
|
+
except ReservationError as exc:
|
|
124
|
+
return _print_error(exc.message, as_json=as_json, invoked=invoked)
|
|
125
|
+
|
|
126
|
+
snapshot = build_snapshot(records, source="payer_file")
|
|
127
|
+
err = store.write_snapshot(snapshot)
|
|
128
|
+
if err is not None:
|
|
129
|
+
return _print_error(err.message, as_json=as_json, invoked=invoked)
|
|
130
|
+
|
|
131
|
+
path = store.inventory_path()
|
|
132
|
+
if as_json:
|
|
133
|
+
_print_success(
|
|
134
|
+
"reservations_load",
|
|
135
|
+
"maproom.reservations_load",
|
|
136
|
+
invoked,
|
|
137
|
+
{
|
|
138
|
+
"snapshot_path": str(path),
|
|
139
|
+
"loaded_as_of": snapshot["loaded_as_of"],
|
|
140
|
+
"record_count": snapshot["record_count"],
|
|
141
|
+
"source": snapshot["source"],
|
|
142
|
+
},
|
|
143
|
+
)
|
|
144
|
+
else:
|
|
145
|
+
print(
|
|
146
|
+
f"Saved {snapshot['record_count']} reservation record(s) to {path} "
|
|
147
|
+
f"(loaded as of {snapshot['loaded_as_of']})"
|
|
148
|
+
)
|
|
149
|
+
return SUCCESS
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Payer-file reservation inventory load."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from maproom.reservations.model import ReservationError, normalize_records_from_payload
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _file_loaded_as_of(data: dict[str, Any]) -> str | None:
|
|
13
|
+
raw = data.get("loaded_as_of")
|
|
14
|
+
if isinstance(raw, str) and raw.strip():
|
|
15
|
+
return raw.strip()
|
|
16
|
+
return None
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def load_payer_file_with_timestamp(path: Path) -> tuple[list[dict[str, Any]], str | None]:
|
|
20
|
+
if not path.exists():
|
|
21
|
+
raise ReservationError(f"file not found: {path}")
|
|
22
|
+
if path.is_dir():
|
|
23
|
+
raise ReservationError(f"path is a directory: {path}")
|
|
24
|
+
try:
|
|
25
|
+
text = path.read_text(encoding="utf-8")
|
|
26
|
+
except OSError as exc:
|
|
27
|
+
raise ReservationError(f"could not read {path}: {exc}") from exc
|
|
28
|
+
if not text.strip():
|
|
29
|
+
raise ReservationError(f"file is empty: {path}")
|
|
30
|
+
try:
|
|
31
|
+
data = json.loads(text)
|
|
32
|
+
except json.JSONDecodeError as exc:
|
|
33
|
+
raise ReservationError(f"invalid JSON in {path}: {exc}") from exc
|
|
34
|
+
if not isinstance(data, dict):
|
|
35
|
+
raise ReservationError(f"expected JSON object in {path}")
|
|
36
|
+
return normalize_records_from_payload(data), _file_loaded_as_of(data)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def load_payer_file(path: Path) -> list[dict[str, Any]]:
|
|
40
|
+
records, _ = load_payer_file_with_timestamp(path)
|
|
41
|
+
return records
|