Skip to content

Commit

Permalink
adds storage details to server crd
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhipfel committed Oct 14, 2024
1 parent 7ccca8c commit 2c56d44
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
45 changes: 45 additions & 0 deletions api/v1alpha1/server_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,32 @@ const (
ServerPoweringOffPowerState ServerPowerState = "PoweringOff"
)

// Capacity is a disk size in Bytes.
type Capacity int64

// Capacity multipliers.
const (
Byte Capacity = 1
KibiByte = Byte * 1024
KiloByte = Byte * 1000
MebiByte = KibiByte * 1024
MegaByte = KiloByte * 1000
GibiByte = MebiByte * 1024
GigaByte = MegaByte * 1000
TebiByte = GibiByte * 1024
TeraByte = GigaByte * 1000
)

// DiskType is a disk type, i.e. HDD, SSD, NVME.
type DiskType string

// DiskType constants.
const (
HDD DiskType = "HDD"
SSD DiskType = "SSD"
NVME DiskType = "NVME"
)

// BMCAccess defines the access details for the BMC.
type BMCAccess struct {
// Protocol specifies the protocol to be used for communicating with the BMC.
Expand Down Expand Up @@ -168,6 +194,9 @@ type ServerStatus struct {
// NetworkInterfaces is a list of network interfaces associated with the server.
NetworkInterfaces []NetworkInterface `json:"networkInterfaces,omitempty"`

// Storages is a list of storages (disk, SSD, etc.) associated with the server.
Storages []Storage `json:"storages,omitempty"`

BIOS BIOSSettings `json:"BIOS,omitempty"`

// Conditions represents the latest available observations of the server's current state.
Expand All @@ -192,6 +221,22 @@ type NetworkInterface struct {
MACAddress string `json:"macAddress"`
}

// Storage defines the details of one storage device
type Storage struct {
// Name is the name of the storage interface.
Name string `json:"name,omitempty"`
// Rotational specifies whether the storage device is rotational.
Rotational bool `json:"rotational,omitempty"`
// Type specifies the type of the storage device.
Type DiskType `json:"type,omitempty"`
// SizeBytes specifies the size of the storage device in bytes.
SizeBytes Capacity `json:"sizeBytes,omitempty"`
// Vendor specifies the vendor of the storage device.
Vendor string `json:"vendor,omitempty"`
// Model specifies the model of the storage device.
Model string `json:"model,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster
Expand Down
17 changes: 17 additions & 0 deletions bmc/bmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type BMC interface {
GetBiosVersion(systemUUID string) (string, error)

SetBootOrder(systemUUID string, order []string) error

GetStorages(systemUUID string) ([]Storage, error)
}

type Bios struct {
Expand Down Expand Up @@ -105,6 +107,21 @@ type Server struct {
SerialNumber string
}

type Storage struct {
// Name is the name of the storage interface.
Name string `json:"name,omitempty"`
// Rotational specifies whether the storage device is rotational.
Rotational bool `json:"rotational,omitempty"`
// Type specifies the type of the storage device.
Type redfish.FormFactor `json:"type,omitempty"`
// SizeBytes specifies the size of the storage device in bytes.
SizeBytes int64 `json:"sizeBytes,omitempty"`
// Vendor specifies the vendor of the storage device.
Vendor string `json:"vendor,omitempty"`
// Model specifies the model of the storage device.
Model string `json:"model,omitempty"`
}

// PowerState is the power state of the system.
type PowerState string

Expand Down
29 changes: 29 additions & 0 deletions bmc/redfish.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,35 @@ func (r *RedfishBMC) checkBiosAttributes(attrs map[string]string) (reset bool, e
return
}

func (r *RedfishBMC) GetStorages(systemUUID string) ([]Storage, error) {
system, err := r.getSystemByUUID(systemUUID)
if err != nil {
return nil, err
}
storage, err := system.Storage()
if err != nil {
return nil, err
}
storages := make([]Storage, 0, len(storage))
for _, s := range storage {
drives, err := s.Drives()
if err != nil {
return nil, err
}
for _, d := range drives {
storages = append(storages, Storage{
Name: d.Name,
Rotational: d.RotationSpeedRPM != 0,
Type: d.DriveFormFactor,
SizeBytes: d.CapacityBytes,
Vendor: d.Manufacturer,
Model: d.Model,
})
}
}
return storages, nil
}

func (r *RedfishBMC) getSystemByUUID(systemUUID string) (*redfish.ComputerSystem, error) {
service := r.client.GetService()
systems, err := service.Systems()
Expand Down

0 comments on commit 2c56d44

Please sign in to comment.