Include some initial profiles to be installed via migration

This commit is contained in:
Jeremy Stretch 2025-03-28 16:16:44 -04:00
parent 9bc2ad4a25
commit 5de244fbd8
7 changed files with 201 additions and 0 deletions

View File

@ -0,0 +1,42 @@
import json
from pathlib import Path
from django.db import migrations
DATA_FILES_PATH = Path(__file__).parent / 'initial_data' / 'module_type_profiles'
def load_initial_data(apps, schema_editor):
"""
Load initial ModuleTypeProfile objects from file.
"""
ModuleTypeProfile = apps.get_model('dcim', 'ModuleTypeProfile')
initial_profiles = (
'cpu',
'fan',
'gpu',
'hard_disk',
'memory',
'power_supply'
)
for name in initial_profiles:
file_path = DATA_FILES_PATH / f'{name}.json'
with file_path.open('r') as f:
data = json.load(f)
try:
ModuleTypeProfile.objects.create(**data)
except Exception as e:
print(f"Error loading data from {file_path}")
raise e
class Migration(migrations.Migration):
dependencies = [
('dcim', '0204_moduletypeprofile'),
]
operations = [
migrations.RunPython(load_initial_data),
]

View File

@ -0,0 +1,20 @@
{
"name": "CPU",
"schema": {
"properties": {
"architecture": {
"type": "string",
"title": "Architecture"
},
"speed": {
"type": "number",
"title": "Speed",
"description": "Clock speed in GHz"
},
"cores": {
"type": "integer",
"description": "Number of cores present"
}
}
}
}

View File

@ -0,0 +1,12 @@
{
"name": "Fan",
"schema": {
"properties": {
"rpm": {
"type": "integer",
"title": "RPM",
"description": "Fan speed (RPM)"
}
}
}
}

View File

@ -0,0 +1,28 @@
{
"name": "GPU",
"schema": {
"properties": {
"interface": {
"type": "string",
"enum": [
"PCIe 4.0",
"PCIe 4.0 x8",
"PCIe 4.0 x16",
"PCIe 5.0 x16"
]
},
"gpu" : {
"type": "string",
"title": "GPU"
},
"memory": {
"type": "integer",
"title": "Memory (GB)",
"description": "Total memory capacity (in GB)"
}
},
"required": [
"memory"
]
}
}

View File

@ -0,0 +1,29 @@
{
"name": "Hard disk",
"schema": {
"properties": {
"type": {
"type": "string",
"title": "Disk type",
"enum": [
"HD",
"SSD",
"NVME"
],
"default": "SSD"
},
"size": {
"type": "integer",
"title": "Size (GB)",
"description": "Raw disk capacity"
},
"speed": {
"type": "integer",
"title": "Speed (RPM)"
}
},
"required": [
"size"
]
}
}

View File

@ -0,0 +1,36 @@
{
"name": "Memory",
"schema": {
"properties": {
"class": {
"type": "string",
"title": "Memory class",
"enum": [
"DDR3",
"DDR4",
"DDR5"
],
"default": "DDR5"
},
"size": {
"type": "integer",
"title": "Size (GB)",
"description": "Raw capacity of the module"
},
"data_rate": {
"type": "integer",
"title": "Data rate",
"description": "Speed in MT/s"
},
"ecc": {
"type": "boolean",
"title": "ECC",
"description": "Error-correcting code is enabled"
}
},
"required": [
"class",
"size"
]
}
}

View File

@ -0,0 +1,34 @@
{
"name": "Power supply",
"schema": {
"properties": {
"input_current": {
"type": "string",
"title": "Current type",
"enum": [
"AC",
"DC"
],
"default": "AC"
},
"input_voltage": {
"type": "integer",
"title": "Voltage",
"default": 120
},
"wattage": {
"type": "integer",
"description": "Available output power (watts)"
},
"hot_swappable": {
"type": "boolean",
"title": "Hot-swappable",
"default": false
}
},
"required": [
"input_current",
"input_voltage"
]
}
}