Skip to content

Commit 04bc696

Browse files
committed
Add disk type field to BMH Storage API.
Signed-off-by: s3rj1k <evasive.gyron@gmail.com>
1 parent a79a91b commit 04bc696

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

apis/metal3.io/v1alpha1/baremetalhost_types.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,16 @@ const (
442442
TeraByte = GigaByte * 1000
443443
)
444444

445+
// DiskType is a disk type, i.e. HDD, SSD, NVME.
446+
type DiskType string
447+
448+
// DiskType constants.
449+
const (
450+
HDD DiskType = "HDD"
451+
SSD DiskType = "SSD"
452+
NVME DiskType = "NVME"
453+
)
454+
445455
// CPU describes one processor on the host.
446456
type CPU struct {
447457
Arch string `json:"arch,omitempty"`
@@ -457,9 +467,17 @@ type Storage struct {
457467
// may not be stable across reboots.
458468
Name string `json:"name,omitempty"`
459469

460-
// Whether this disk represents rotational storage
470+
// Whether this disk represents rotational storage.
471+
// This field is not recommended for usage, please
472+
// prefer using 'Type' field instead, this field
473+
// will be deprecated eventually.
461474
Rotational bool `json:"rotational,omitempty"`
462475

476+
// Device type, one of: HDD, SSD, NVME.
477+
// +kubebuilder:validation:Optional
478+
// +kubebuilder:validation:Enum=HDD;SSD;NVME;
479+
Type DiskType `json:"type,omitempty"`
480+
463481
// The size of the disk in Bytes
464482
SizeBytes Capacity `json:"sizeBytes,omitempty"`
465483

config/crd/bases/metal3.io_baremetalhosts.yaml

+8-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ spec:
495495
description: The Linux device name of the disk, e.g. "/dev/sda". Note that this may not be stable across reboots.
496496
type: string
497497
rotational:
498-
description: Whether this disk represents rotational storage
498+
description: Whether this disk represents rotational storage. This field is not recommended for usage, please prefer using 'Type' field instead, this field will be deprecated eventually.
499499
type: boolean
500500
serialNumber:
501501
description: The serial number of the device
@@ -504,6 +504,13 @@ spec:
504504
description: The size of the disk in Bytes
505505
format: int64
506506
type: integer
507+
type:
508+
description: 'Device type, one of: HDD, SSD, NVME.'
509+
enum:
510+
- HDD
511+
- SSD
512+
- NVME
513+
type: string
507514
vendor:
508515
description: The name of the vendor of the device
509516
type: string

config/render/capm3.yaml

+8-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ spec:
493493
description: The Linux device name of the disk, e.g. "/dev/sda". Note that this may not be stable across reboots.
494494
type: string
495495
rotational:
496-
description: Whether this disk represents rotational storage
496+
description: Whether this disk represents rotational storage. This field is not recommended for usage, please prefer using 'Type' field instead, this field will be deprecated eventually.
497497
type: boolean
498498
serialNumber:
499499
description: The serial number of the device
@@ -502,6 +502,13 @@ spec:
502502
description: The size of the disk in Bytes
503503
format: int64
504504
type: integer
505+
type:
506+
description: 'Device type, one of: HDD, SSD, NVME.'
507+
enum:
508+
- HDD
509+
- SSD
510+
- NVME
511+
type: string
505512
vendor:
506513
description: The name of the vendor of the device
507514
type: string

pkg/provisioner/ironic/hardwaredetails/hardwaredetails.go

+13
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,25 @@ func getNICDetails(ifdata []introspection.InterfaceType,
9595
return nics
9696
}
9797

98+
func getDiskType(diskdata introspection.RootDiskType) metal3v1alpha1.DiskType {
99+
if diskdata.Rotational {
100+
return metal3v1alpha1.HDD
101+
}
102+
103+
if strings.HasPrefix(diskdata.Name, "/dev/nvme") {
104+
return metal3v1alpha1.NVME
105+
}
106+
107+
return metal3v1alpha1.SSD
108+
}
109+
98110
func getStorageDetails(diskdata []introspection.RootDiskType) []metal3v1alpha1.Storage {
99111
storage := make([]metal3v1alpha1.Storage, len(diskdata))
100112
for i, disk := range diskdata {
101113
storage[i] = metal3v1alpha1.Storage{
102114
Name: disk.Name,
103115
Rotational: disk.Rotational,
116+
Type: getDiskType(disk),
104117
SizeBytes: metal3v1alpha1.Capacity(disk.Size),
105118
Vendor: disk.Vendor,
106119
Model: disk.Model,

0 commit comments

Comments
 (0)