Skip to content

Commit 4c78fdc

Browse files
authored
Merge pull request #396 from rackerlabs/flavor-schema
feat: flavor schema for ironic hw detect
2 parents 14522e7 + 51b9a1c commit 4c78fdc

File tree

6 files changed

+118
-13
lines changed

6 files changed

+118
-13
lines changed

docs/schema/flavor.schema.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../schema/flavor.schema.json

python/ironic-understack/ironic_understack/flavor_spec.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,24 @@
66
from ironic_understack.machine import Machine
77

88

9+
@dataclass
10+
class PciSpec:
11+
vendor_id: str
12+
device_id: str
13+
sub_vendor_id: str
14+
sub_device_id: str
15+
16+
917
@dataclass
1018
class FlavorSpec:
1119
name: str
1220
manufacturer: str
1321
model: str
1422
memory_gb: int
1523
cpu_cores: int
16-
cpu_models: list[str]
24+
cpu_model: str
1725
drives: list[int]
26+
pci: list[PciSpec]
1827

1928
@staticmethod
2029
def from_yaml(yaml_str: str) -> "FlavorSpec":
@@ -25,8 +34,9 @@ def from_yaml(yaml_str: str) -> "FlavorSpec":
2534
model=data["model"],
2635
memory_gb=data["memory_gb"],
2736
cpu_cores=data["cpu_cores"],
28-
cpu_models=data["cpu_models"],
37+
cpu_model=data.get("cpu_model", data.get("cpu_models", [""]).pop()),
2938
drives=data["drives"],
39+
pci=data.get("pci", []),
3040
)
3141

3242
@staticmethod
@@ -67,7 +77,7 @@ def score_machine(self, machine: Machine):
6777
if (
6878
machine.memory_gb == self.memory_gb
6979
and machine.disk_gb in self.drives
70-
and machine.cpu in self.cpu_models
80+
and machine.cpu == self.cpu_model
7181
):
7282
return 100
7383

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

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

8696
# Rule 5 and 6: Rank based on exact matches or excess capacity

python/ironic-understack/ironic_understack/tests/test_flavor_spec.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ def valid_yaml():
1414
model: PowerEdge R7615
1515
memory_gb: 7777
1616
cpu_cores: 245
17-
cpu_models:
18-
- AMD EPYC 9254 245-Core Processor
17+
cpu_model: AMD EPYC 9254 245-Core Processor
1918
drives:
2019
- 960
2120
- 960
@@ -50,7 +49,7 @@ def test_from_yaml(valid_yaml):
5049
assert spec.model == "PowerEdge R7615"
5150
assert spec.memory_gb == 7777
5251
assert spec.cpu_cores == 245
53-
assert spec.cpu_models == ["AMD EPYC 9254 245-Core Processor"]
52+
assert spec.cpu_model == "AMD EPYC 9254 245-Core Processor"
5453
assert spec.drives == [960, 960]
5554

5655

@@ -119,26 +118,29 @@ def flavors():
119118
model="Fake Machine",
120119
memory_gb=100,
121120
cpu_cores=13,
122-
cpu_models=["AMD EPYC 9254 245-Core Processor"],
121+
cpu_model="AMD EPYC 9254 245-Core Processor",
123122
drives=[500, 500],
123+
pci=[],
124124
),
125125
FlavorSpec(
126126
name="medium",
127127
manufacturer="Dell",
128128
model="Fake Machine",
129129
memory_gb=200,
130130
cpu_cores=15,
131-
cpu_models=["AMD EPYC 9254 245-Core Processor"],
131+
cpu_model="AMD EPYC 9254 245-Core Processor",
132132
drives=[1500, 1500],
133+
pci=[],
133134
),
134135
FlavorSpec(
135136
name="large",
136137
manufacturer="Dell",
137138
model="Fake Machine",
138139
memory_gb=400,
139140
cpu_cores=27,
140-
cpu_models=["AMD EPYC 9254 245-Core Processor"],
141+
cpu_model="AMD EPYC 9254 245-Core Processor",
141142
drives=[1800, 1800],
143+
pci=[],
142144
),
143145
]
144146

python/ironic-understack/ironic_understack/tests/test_matcher.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,29 @@ def sample_flavors():
1313
model="Fake Machine",
1414
memory_gb=4,
1515
cpu_cores=2,
16-
cpu_models=["x86"],
16+
cpu_model="x86",
1717
drives=[20],
18+
pci=[],
1819
),
1920
FlavorSpec(
2021
name="medium",
2122
manufacturer="Dell",
2223
model="Fake Machine",
2324
memory_gb=8,
2425
cpu_cores=4,
25-
cpu_models=["x86"],
26+
cpu_model="x86",
2627
drives=[40],
28+
pci=[],
2729
),
2830
FlavorSpec(
2931
name="large",
3032
manufacturer="Dell",
3133
model="Fake Machine",
3234
memory_gb=16,
3335
cpu_cores=8,
34-
cpu_models=["x86"],
36+
cpu_model="x86",
3537
drives=[80],
38+
pci=[],
3639
),
3740
]
3841

schema/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@
55
```bash
66
curl -o argo-workflows.json https://raw.githubusercontent.com/argoproj/argo-workflows/master/api/jsonschema/schema.json
77
```
8+
9+
## flavor.schema
10+
11+
Used to define hardware identification / mapping for Ironic hardware to Nova flavors.
12+
The flavors hook uses these files to set properties automatically on the nodes.

schema/flavor.schema.json

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://rackerlabs.github.io/understack/schema/flavor.schema.json",
4+
"title": "UnderStack Hardware Flavor",
5+
"description": "Server flavor configuration schema",
6+
"type": "object",
7+
"properties": {
8+
"name": {
9+
"description": "Flavor name for specified configuration (ie gp01.s)",
10+
"type": "string"
11+
},
12+
"manufacturer": {
13+
"description": "Manufacturer of the hardware chassis",
14+
"type": "string"
15+
},
16+
"model": {
17+
"description": "Model of the hardware chassis",
18+
"type": "string"
19+
},
20+
"cpu_cores": {
21+
"description": "Total CPU cores.",
22+
"type": "number"
23+
},
24+
"cpu_model": {
25+
"description": "Processor model",
26+
"type": "string"
27+
},
28+
"cpu_models": {
29+
"description": "Processor models",
30+
"type": "array",
31+
"items": {
32+
"type": "string",
33+
"description": "Processor model"
34+
},
35+
"minItems": 1,
36+
"maxItems": 1
37+
},
38+
"memory_gb": {
39+
"description": "Total memory in GB",
40+
"type": "number"
41+
},
42+
"memory_modules": {
43+
"description": "Memory modules",
44+
"type": "array",
45+
"items": {
46+
"type": "number",
47+
"description": "Capacity in GB"
48+
}
49+
},
50+
"drives": {
51+
"description": "Drives",
52+
"type": "array",
53+
"items": {
54+
"type": "number",
55+
"description": "Capacity in GB"
56+
}
57+
},
58+
"pci": {
59+
"description": "PCI devices",
60+
"type": "array",
61+
"items": {
62+
"type": "object",
63+
"description": "PCI device",
64+
"properties": {
65+
"vendor_id": {
66+
"type": "string"
67+
},
68+
"device_id": {
69+
"type": "string"
70+
},
71+
"sub_vendor_id": {
72+
"type": "string"
73+
},
74+
"sub_device_id": {
75+
"type": "string"
76+
}
77+
},
78+
"required": ["vendor_id", "device_id", "sub_vendor_id", "sub_device_id"]
79+
80+
}
81+
}
82+
},
83+
"required": [ "name", "manufacturer", "model", "cpu_cores", "cpu_models", "memory_gb", "drives" ]
84+
}

0 commit comments

Comments
 (0)