diff --git a/app/data/metal.json b/app/data/metal.json new file mode 100644 index 0000000..89fbdb1 --- /dev/null +++ b/app/data/metal.json @@ -0,0 +1,292 @@ +[ + { + "name": "akita", + "location": "Tokyo", + "vendor": "Minisforum MS-01", + "cpu": 24, + "memory": "32GB", + "storage": "1TB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "chiba", + "location": "Tokyo", + "vendor": "Minisforum MS-01", + "cpu": 24, + "memory": "32GB", + "storage": "1TB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "ehime", + "location": "Tokyo", + "vendor": "Minisforum MS-01", + "cpu": 24, + "memory": "32GB", + "storage": "1TB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "fukuoka", + "location": "Tokyo", + "vendor": "Minisforum MS-01", + "cpu": 24, + "memory": "32GB", + "storage": "1TB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "kanagawa", + "location": "Tokyo", + "vendor": "Minisforum MS-01", + "cpu": 24, + "memory": "32GB", + "storage": "1TB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "kumamoto", + "location": "Tokyo", + "vendor": "Minisforum MS-01", + "cpu": 24, + "memory": "32GB", + "storage": "1TB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "okayama", + "location": "Tokyo", + "vendor": "Minisforum MS-01", + "cpu": 24, + "memory": "32GB", + "storage": "1TB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "okinawa", + "location": "Tokyo", + "vendor": "Minisforum MS-01", + "cpu": 24, + "memory": "32GB", + "storage": "1TB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "osaka", + "location": "Tokyo", + "vendor": "Minisforum MS-01", + "cpu": 24, + "memory": "32GB", + "storage": "1TB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "saitama", + "location": "Tokyo", + "vendor": "Minisforum MS-01", + "cpu": 24, + "memory": "32GB", + "storage": "1TB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "osaka", + "location": "Tokyo", + "vendor": "Minisforum MS-01", + "cpu": 24, + "memory": "32GB", + "storage": "1TB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "saitama", + "location": "Tokyo", + "vendor": "Minisforum MS-01", + "cpu": 24, + "memory": "32GB", + "storage": "1TB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "shizuoka", + "location": "Tokyo", + "vendor": "Minisforum MS-01", + "cpu": 24, + "memory": "32GB", + "storage": "1TB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "yamagata", + "location": "Tokyo", + "vendor": "Minisforum MS-01", + "cpu": 24, + "memory": "32GB", + "storage": "1TB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "adatara", + "location": "Tokyo", + "vendor": "OrangePi 5 ARM", + "cpu": 8, + "memory": "16GB", + "storage": "128GB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "arashima", + "location": "Tokyo", + "vendor": "OrangePi 5 ARM", + "cpu": 8, + "memory": "16GB", + "storage": "128GB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "asahi", + "location": "Tokyo", + "vendor": "OrangePi 5 ARM", + "cpu": 8, + "memory": "16GB", + "storage": "128GB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "aso", + "location": "Tokyo", + "vendor": "OrangePi 5 ARM", + "cpu": 8, + "memory": "16GB", + "storage": "128GB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "azuma", + "location": "Tokyo", + "vendor": "OrangePi 5 ARM", + "cpu": 8, + "memory": "16GB", + "storage": "128GB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "daisen", + "location": "Tokyo", + "vendor": "OrangePi 5 ARM", + "cpu": 8, + "memory": "16GB", + "storage": "128GB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "horoshiri", + "location": "Tokyo", + "vendor": "OrangePi 5 ARM", + "cpu": 8, + "memory": "16GB", + "storage": "128GB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "nantai", + "location": "Tokyo", + "vendor": "OrangePi 5 ARM", + "cpu": 8, + "memory": "16GB", + "storage": "128GB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "kirishima", + "location": "Tokyo", + "vendor": "OrangePi 5 ARM", + "cpu": 8, + "memory": "16GB", + "storage": "128GB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "ontake", + "location": "Tokyo", + "vendor": "OrangePi 5 ARM", + "cpu": 8, + "memory": "16GB", + "storage": "128GB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "rausu", + "location": "Tokyo", + "vendor": "OrangePi 5 ARM", + "cpu": 8, + "memory": "16GB", + "storage": "128GB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "rishiri", + "location": "Tokyo", + "vendor": "OrangePi 5 ARM", + "cpu": 8, + "memory": "16GB", + "storage": "128GB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "shari", + "location": "Tokyo", + "vendor": "OrangePi 5 ARM", + "cpu": 8, + "memory": "16GB", + "storage": "128GB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "yotei", + "location": "Tokyo", + "vendor": "OrangePi 5 ARM", + "cpu": 8, + "memory": "16GB", + "storage": "128GB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + }, + { + "name": "zao", + "location": "Tokyo", + "vendor": "OrangePi 5 ARM", + "cpu": 8, + "memory": "16GB", + "storage": "128GB", + "time_on_duty": 1000, + "initial_cost": 1000.0 + } + ] diff --git a/app/data/vm.json b/app/data/vm.json new file mode 100644 index 0000000..40c0593 --- /dev/null +++ b/app/data/vm.json @@ -0,0 +1,456 @@ +[ + { + "name": "cax-41-1", + "location": "Helsinki", + "cpu": 16, + "memory": "32GB", + "storage": "320GB SSD", + "type": "cax-2xlarge" + }, + { + "name": "cax-41-2", + "location": "Helsinki", + "cpu": 16, + "memory": "32GB", + "storage": "320GB SSD", + "type": "cax-2xlarge" + }, + { + "name": "ccx-63", + "location": "Germany", + "cpu": 48, + "memory": "192GB", + "storage": "960GB SSD", + "type": "cx-6xlarge" + }, + { + "name": "cpx-41-1", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "240GB SSD", + "type": "cx-xlarge" + }, + { + "name": "cpx-41-2", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "240GB SSD", + "type": "cx-xlarge" + }, + { + "name": "cpx-41-3", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "240GB SSD", + "type": "cx-xlarge" + }, + { + "name": "cpx-41-4", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "240GB SSD", + "type": "cx-xlarge" + }, + { + "name": "cpx-41-5", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "240GB SSD", + "type": "cx-xlarge" + }, + { + "name": "cpx-41-6", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "240GB SSD", + "type": "cx-xlarge" + }, + { + "name": "cpx-41-7", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "240GB SSD", + "type": "cx-xlarge" + }, + { + "name": "cpx-41-8", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "240GB SSD", + "type": "cx-xlarge" + }, + { + "name": "cpx-41-9", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "240GB SSD", + "type": "cx-xlarge" + }, + { + "name": "cpx-41-10", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "240GB SSD", + "type": "cx-xlarge" + }, + { + "name": "cx-22-1", + "location": "Helsinki", + "cpu": 2, + "memory": "4GB", + "storage": "40GB SSD", + "type": "cx-medium" + }, + { + "name": "cx-22-2", + "location": "Helsinki", + "cpu": 2, + "memory": "4GB", + "storage": "40GB SSD", + "type": "cx-medium" + }, + { + "name": "cx-22-3", + "location": "Helsinki", + "cpu": 2, + "memory": "4GB", + "storage": "40GB SSD", + "type": "cx-medium" + }, + { + "name": "cx-22-4", + "location": "Helsinki", + "cpu": 2, + "memory": "4GB", + "storage": "40GB SSD", + "type": "cx-medium" + }, + { + "name": "cx-22-5", + "location": "Helsinki", + "cpu": 2, + "memory": "4GB", + "storage": "40GB SSD", + "type": "cx-medium" + }, + { + "name": "cx-22-6", + "location": "Helsinki", + "cpu": 2, + "memory": "4GB", + "storage": "40GB SSD", + "type": "cx-medium" + }, + { + "name": "cx-22-7", + "location": "Helsinki", + "cpu": 2, + "memory": "4GB", + "storage": "40GB SSD", + "type": "cx-medium" + }, + { + "name": "cx-22-8", + "location": "Helsinki", + "cpu": 2, + "memory": "4GB", + "storage": "40GB SSD", + "type": "cx-medium" + }, + { + "name": "cx-22-9", + "location": "Helsinki", + "cpu": 2, + "memory": "4GB", + "storage": "40GB SSD", + "type": "cx-medium" + }, + { + "name": "cx-22-10", + "location": "Helsinki", + "cpu": 2, + "memory": "4GB", + "storage": "40GB SSD", + "type": "cx-medium" + }, + { + "name": "cx-42-1", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB SSD", + "type": "cx-xlarge" + }, + { + "name": "cx-42-2", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB SSD", + "type": "cx-xlarge" + }, + { + "name": "cx-42-3", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB SSD", + "type": "cx-xlarge" + }, + { + "name": "cx-42-4", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB SSD", + "type": "cx-xlarge" + }, + { + "name": "cx-42-5", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB SSD", + "type": "cx-xlarge" + }, + { + "name": "cx-42-6", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB SSD", + "type": "cx-xlarge" + }, + { + "name": "cx-42-7", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB SSD", + "type": "cx-xlarge" + }, + { + "name": "cx-42-8", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB SSD", + "type": "cx-xlarge" + }, + { + "name": "cx-42-9", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB SSD", + "type": "cx-xlarge" + }, + { + "name": "cx-42-10", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB SSD", + "type": "cx-xlarge" + }, + { + "name": "cx-42-11", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB SSD", + "type": "cx-xlarge" + }, + { + "name": "cx-42-gawa-1", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB" + }, + { + "name": "cx-42-gawa-2", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB" + }, + { + "name": "cx-42-gawa-3", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB" + }, + { + "name": "cx-42-gawa-4", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB" + }, + { + "name": "cx-42-gawa-5", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB" + }, + { + "name": "cx-42-gawa-6", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB" + }, + { + "name": "cx-42-gawa-7", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB" + }, + { + "name": "cx-42-gawa-8", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB" + }, + { + "name": "cx-42-gawa-9", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB" + }, + { + "name": "cx-42-gawa-10", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB" + }, + { + "name": "cx-42-yama-1", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB" + }, + { + "name": "cx-42-yama-2", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB" + }, + { + "name": "cx-42-yama-3", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB" + }, + { + "name": "cx-42-yama-4", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB" + }, + { + "name": "cx-42-yama-5", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB" + }, + { + "name": "cx-42-yama-6", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB" + }, + { + "name": "cx-42-yama-7", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB" + }, + { + "name": "cx-42-yama-8", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB" + }, + { + "name": "cx-42-yama-9", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB" + }, + { + "name": "cx-42-yama-10", + "location": "Helsinki", + "cpu": 8, + "memory": "16GB", + "storage": "160GB" + }, + { + "name": "cx-52-1", + "location": "Helsinki", + "cpu": 16, + "memory": "32GB", + "storage": "320GB" + }, + { + "name": "cx-52-2", + "location": "Helsinki", + "cpu": 16, + "memory": "32GB", + "storage": "320GB" + }, + { + "name": "cx-52-3", + "location": "Helsinki", + "cpu": 16, + "memory": "32GB", + "storage": "320GB" + }, + { + "name": "cx-52-4", + "location": "Helsinki", + "cpu": 16, + "memory": "32GB", + "storage": "320GB" + }, + { + "name": "cx-52-5", + "location": "Helsinki", + "cpu": 16, + "memory": "32GB", + "storage": "320GB" + }, + { + "name": "cx-52-6", + "location": "Helsinki", + "cpu": 16, + "memory": "32GB", + "storage": "320GB" + } + ] diff --git a/app/main.py b/app/main.py index 5b1dc43..413ba70 100644 --- a/app/main.py +++ b/app/main.py @@ -1,11 +1,76 @@ +import json +import os +import logging from fastapi import FastAPI -from database import init_db +from database import init_db, insert_metal_node, insert_virtual_machine from fastapi.middleware.cors import CORSMiddleware from routes import metal, vm, k8s, export, think +from pydantic import BaseModel, ValidationError + +class MetalNode(BaseModel): + name: str + location: str + vendor: str + cpu: int + memory: str + storage: str + time_on_duty: int + initial_cost: float + +class VirtualMachine(BaseModel): + name: str + location: str + cpu: int + memory: str + storage: str + vm_type: str app = FastAPI() -init_db() +METAL_JSON = "data/metal.json" +VM_JSON = "data/vm.json" + +logger = logging.getLogger("uvicorn") + +@app.on_event("startup") +async def startup_event(): + init_db() + + if os.path.exists(METAL_JSON): + with open(METAL_JSON, "r") as file: + metal_nodes = json.load(file) + for node in metal_nodes: + try: + validated_node = MetalNode(**node) + insert_metal_node( + name=validated_node.name, + location=validated_node.location, + vendor=validated_node.vendor, + cpu=validated_node.cpu, + memory=validated_node.memory, + storage=validated_node.storage, + time_on_duty=validated_node.time_on_duty, + initial_cost=validated_node.initial_cost + ) + except ValidationError as e: + logger.error(f"Invalid metal node data: {e}") + + if os.path.exists(VM_JSON): + with open(VM_JSON, "r") as file: + vms = json.load(file) + for vm in vms: + try: + validated_vm = VirtualMachine(**vm) + insert_virtual_machine( + name=validated_vm.name, + location=validated_vm.location, + cpu=validated_vm.cpu, + memory=validated_vm.memory, + storage=validated_vm.storage, + vm_type=validated_vm.vm_type + ) + except ValidationError as e: + logger.error(f"Invalid VM data: {e}") # Include routes app.include_router(metal.router)