Skip to content

Commit

Permalink
Merge pull request #396 from rackerlabs/flavor-schema
Browse files Browse the repository at this point in the history
feat: flavor schema for ironic hw detect
  • Loading branch information
cardoe authored Oct 24, 2024
2 parents 14522e7 + 51b9a1c commit 4c78fdc
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 13 deletions.
1 change: 1 addition & 0 deletions docs/schema/flavor.schema.json
18 changes: 14 additions & 4 deletions python/ironic-understack/ironic_understack/flavor_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@
from ironic_understack.machine import Machine


@dataclass
class PciSpec:
vendor_id: str
device_id: str
sub_vendor_id: str
sub_device_id: str


@dataclass
class FlavorSpec:
name: str
manufacturer: str
model: str
memory_gb: int
cpu_cores: int
cpu_models: list[str]
cpu_model: str
drives: list[int]
pci: list[PciSpec]

@staticmethod
def from_yaml(yaml_str: str) -> "FlavorSpec":
Expand All @@ -25,8 +34,9 @@ def from_yaml(yaml_str: str) -> "FlavorSpec":
model=data["model"],
memory_gb=data["memory_gb"],
cpu_cores=data["cpu_cores"],
cpu_models=data["cpu_models"],
cpu_model=data.get("cpu_model", data.get("cpu_models", [""]).pop()),
drives=data["drives"],
pci=data.get("pci", []),
)

@staticmethod
Expand Down Expand Up @@ -67,7 +77,7 @@ def score_machine(self, machine: Machine):
if (
machine.memory_gb == self.memory_gb
and machine.disk_gb in self.drives
and machine.cpu in self.cpu_models
and machine.cpu == self.cpu_model
):
return 100

Expand All @@ -80,7 +90,7 @@ def score_machine(self, machine: Machine):
return 0

# Rule 4: Machine must match the flavor on one of the CPU models exactly
if machine.cpu not in self.cpu_models:
if machine.cpu != self.cpu_model:
return 0

# Rule 5 and 6: Rank based on exact matches or excess capacity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ def valid_yaml():
model: PowerEdge R7615
memory_gb: 7777
cpu_cores: 245
cpu_models:
- AMD EPYC 9254 245-Core Processor
cpu_model: AMD EPYC 9254 245-Core Processor
drives:
- 960
- 960
Expand Down Expand Up @@ -50,7 +49,7 @@ def test_from_yaml(valid_yaml):
assert spec.model == "PowerEdge R7615"
assert spec.memory_gb == 7777
assert spec.cpu_cores == 245
assert spec.cpu_models == ["AMD EPYC 9254 245-Core Processor"]
assert spec.cpu_model == "AMD EPYC 9254 245-Core Processor"
assert spec.drives == [960, 960]


Expand Down Expand Up @@ -119,26 +118,29 @@ def flavors():
model="Fake Machine",
memory_gb=100,
cpu_cores=13,
cpu_models=["AMD EPYC 9254 245-Core Processor"],
cpu_model="AMD EPYC 9254 245-Core Processor",
drives=[500, 500],
pci=[],
),
FlavorSpec(
name="medium",
manufacturer="Dell",
model="Fake Machine",
memory_gb=200,
cpu_cores=15,
cpu_models=["AMD EPYC 9254 245-Core Processor"],
cpu_model="AMD EPYC 9254 245-Core Processor",
drives=[1500, 1500],
pci=[],
),
FlavorSpec(
name="large",
manufacturer="Dell",
model="Fake Machine",
memory_gb=400,
cpu_cores=27,
cpu_models=["AMD EPYC 9254 245-Core Processor"],
cpu_model="AMD EPYC 9254 245-Core Processor",
drives=[1800, 1800],
pci=[],
),
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,29 @@ def sample_flavors():
model="Fake Machine",
memory_gb=4,
cpu_cores=2,
cpu_models=["x86"],
cpu_model="x86",
drives=[20],
pci=[],
),
FlavorSpec(
name="medium",
manufacturer="Dell",
model="Fake Machine",
memory_gb=8,
cpu_cores=4,
cpu_models=["x86"],
cpu_model="x86",
drives=[40],
pci=[],
),
FlavorSpec(
name="large",
manufacturer="Dell",
model="Fake Machine",
memory_gb=16,
cpu_cores=8,
cpu_models=["x86"],
cpu_model="x86",
drives=[80],
pci=[],
),
]

Expand Down
5 changes: 5 additions & 0 deletions schema/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
```bash
curl -o argo-workflows.json https://raw.githubusercontent.com/argoproj/argo-workflows/master/api/jsonschema/schema.json
```

## flavor.schema

Used to define hardware identification / mapping for Ironic hardware to Nova flavors.
The flavors hook uses these files to set properties automatically on the nodes.
84 changes: 84 additions & 0 deletions schema/flavor.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://rackerlabs.github.io/understack/schema/flavor.schema.json",
"title": "UnderStack Hardware Flavor",
"description": "Server flavor configuration schema",
"type": "object",
"properties": {
"name": {
"description": "Flavor name for specified configuration (ie gp01.s)",
"type": "string"
},
"manufacturer": {
"description": "Manufacturer of the hardware chassis",
"type": "string"
},
"model": {
"description": "Model of the hardware chassis",
"type": "string"
},
"cpu_cores": {
"description": "Total CPU cores.",
"type": "number"
},
"cpu_model": {
"description": "Processor model",
"type": "string"
},
"cpu_models": {
"description": "Processor models",
"type": "array",
"items": {
"type": "string",
"description": "Processor model"
},
"minItems": 1,
"maxItems": 1
},
"memory_gb": {
"description": "Total memory in GB",
"type": "number"
},
"memory_modules": {
"description": "Memory modules",
"type": "array",
"items": {
"type": "number",
"description": "Capacity in GB"
}
},
"drives": {
"description": "Drives",
"type": "array",
"items": {
"type": "number",
"description": "Capacity in GB"
}
},
"pci": {
"description": "PCI devices",
"type": "array",
"items": {
"type": "object",
"description": "PCI device",
"properties": {
"vendor_id": {
"type": "string"
},
"device_id": {
"type": "string"
},
"sub_vendor_id": {
"type": "string"
},
"sub_device_id": {
"type": "string"
}
},
"required": ["vendor_id", "device_id", "sub_vendor_id", "sub_device_id"]

}
}
},
"required": [ "name", "manufacturer", "model", "cpu_cores", "cpu_models", "memory_gb", "drives" ]
}

0 comments on commit 4c78fdc

Please sign in to comment.