Add Coremarket: Federated Core VM sizing and cloud pricing app
Dockerised FastAPI web app that sizes a VM for a selection of Federated Computer apps (Base/Good/Better/Best tiers or custom) and prices it across 14 cloud providers and ~250 regions, grouped by continent. - Sizing model per app with shared databases, headroom and disk growth - Live pricing from Vultr, Akamai/Linode and Azure (DigitalOcean and Hetzner with tokens); dated catalog for the rest - Hand-maintained Contabo price sheet with editor and table paste, including the one-time setup fee - HIPAA/SOC2/PCI DSS/GDPR status, SMTP port 25, IPv4 and egress notes - Estimated latency to 40 cities, real RTT via Globalping probes - Versioned REST API (/api/v1) with OpenAPI docs and CSV export - Accounts with admin/user roles, first admin from ADMIN_USERNAME / ADMIN_PASSWORD, per-account API keys, SQLite storage Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
"""Hand-maintained price sheets for providers without a pricing API (currently Contabo).
|
||||
|
||||
A provider opts in by defining `manual_defaults` in app/data/providers.py. Edits made in
|
||||
the UI are saved to $DATA_DIR/manual_prices.json and take precedence over the defaults.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
DATA_DIR = Path(os.environ.get("DATA_DIR", "/data"))
|
||||
STORE = DATA_DIR / "manual_prices.json"
|
||||
|
||||
|
||||
class ManualPlan(BaseModel):
|
||||
code: str = ""
|
||||
name: str = Field(min_length=1)
|
||||
vcpu: int = Field(ge=1, le=512)
|
||||
ram_gb: float = Field(gt=0, le=4096)
|
||||
disk_gb: float = Field(ge=0, le=100000)
|
||||
price: float = Field(ge=0, le=100000)
|
||||
cpu_type: str = "shared"
|
||||
note: str = ""
|
||||
|
||||
|
||||
class ManualSheet(BaseModel):
|
||||
currency: str = Field("EUR", pattern="^(EUR|USD)$")
|
||||
fx: float = Field(1.16, gt=0, le=10) # USD per 1 unit of currency
|
||||
setup_fee: float = Field(0, ge=0, le=10000)
|
||||
setup_fee_note: str = ""
|
||||
plans: list[ManualPlan] = Field(min_length=1)
|
||||
region_surcharge_pct: dict[str, float] = {}
|
||||
updated_at: str = ""
|
||||
|
||||
|
||||
def _load() -> dict:
|
||||
try:
|
||||
return json.loads(STORE.read_text())
|
||||
except (FileNotFoundError, json.JSONDecodeError):
|
||||
return {}
|
||||
|
||||
|
||||
def get_sheet(provider: dict) -> tuple[dict, bool]:
|
||||
"""Return (sheet, is_default)."""
|
||||
saved = _load().get(provider["id"])
|
||||
if saved:
|
||||
return saved, False
|
||||
return copy.deepcopy(provider["manual_defaults"]), True
|
||||
|
||||
|
||||
def save_sheet(provider: dict, sheet: ManualSheet) -> dict:
|
||||
data = _load()
|
||||
d = sheet.model_dump()
|
||||
d["updated_at"] = time.strftime("%Y-%m-%d %H:%M UTC", time.gmtime())
|
||||
known = {r["code"] for r in provider["regions"]}
|
||||
d["region_surcharge_pct"] = {k: v for k, v in d["region_surcharge_pct"].items() if k in known}
|
||||
data[provider["id"]] = d
|
||||
DATA_DIR.mkdir(parents=True, exist_ok=True)
|
||||
tmp = STORE.with_suffix(".tmp")
|
||||
tmp.write_text(json.dumps(data, indent=2))
|
||||
tmp.replace(STORE)
|
||||
return d
|
||||
|
||||
|
||||
def reset_sheet(provider: dict):
|
||||
data = _load()
|
||||
if data.pop(provider["id"], None) is not None:
|
||||
tmp = STORE.with_suffix(".tmp")
|
||||
tmp.write_text(json.dumps(data, indent=2))
|
||||
tmp.replace(STORE)
|
||||
|
||||
|
||||
def apply(provider: dict) -> dict:
|
||||
"""Return a copy of provider with plans/regions/setup fee built from its price sheet."""
|
||||
sheet, is_default = get_sheet(provider)
|
||||
fx = sheet["fx"] if sheet["currency"] != "USD" else 1.0
|
||||
p = copy.copy(provider)
|
||||
p["plans"] = [
|
||||
dict(model=f"{pl['name']} ({pl['code']})" if pl.get("code") else pl["name"],
|
||||
vcpu=pl["vcpu"], ram_gb=pl["ram_gb"], disk_gb=pl["disk_gb"], price=round(pl["price"] * fx, 2),
|
||||
cpu_type=pl.get("cpu_type", "shared"), arch="x86_64", tag=None, note=pl.get("note", ""))
|
||||
for pl in sheet["plans"]
|
||||
]
|
||||
pct = sheet.get("region_surcharge_pct", {})
|
||||
p["regions"] = [dict(r, mult=1 + pct.get(r["code"], 0) / 100) for r in provider["regions"]]
|
||||
if sheet.get("setup_fee"):
|
||||
p["setup_fee"] = dict(usd=round(sheet["setup_fee"] * fx, 2),
|
||||
note=f"{sheet['currency']} {sheet['setup_fee']:.2f} one-time. {sheet.get('setup_fee_note', '')}".strip())
|
||||
else:
|
||||
p.pop("setup_fee", None)
|
||||
p["price_source"] = f"manual sheet {sheet.get('updated_at', '')}" + (" (defaults)" if is_default else "")
|
||||
return p
|
||||
Reference in New Issue
Block a user