Skip to content

Commit

Permalink
Merge pull request #139 from stmcginnis/drives
Browse files Browse the repository at this point in the history
Add Chassis Drives linkage
  • Loading branch information
stmcginnis authored May 1, 2021
2 parents dd98a92 + fd923ee commit 7ddb6f9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 19 deletions.
52 changes: 35 additions & 17 deletions redfish/chassis.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ type Chassis struct {
DepthMm float64
// Description provides a description of this resource.
Description string
// Drives shall contain an array of links to resources
// of type Drive that are in this chassis.
// Office description is not right, it is a link to a collection.
drives string
// DrivesCount is the number of drives attached to this chassis.
DrivesCount int `json:"[email protected]"`
// EnvironmentalClass shall contain the ASHRAE
// Environmental Class for this chassis, as defined by ASHRAE Thermal
// Guidelines for Data Processing Environments. These classes define
Expand Down Expand Up @@ -247,6 +253,7 @@ func (chassis *Chassis) UnmarshalJSON(b []byte) error {

var t struct {
temp
Drives common.Link
Thermal common.Link
Power common.Link
NetworkAdapters common.Link
Expand All @@ -262,6 +269,8 @@ func (chassis *Chassis) UnmarshalJSON(b []byte) error {
*chassis = Chassis(t.temp)

// Extract the links to other entities for later
fmt.Printf("+++++ Drives: %v\n", t.Drives)
chassis.drives = string(t.Drives)
chassis.thermal = string(t.Thermal)
chassis.power = string(t.Power)
chassis.networkAdapters = string(t.NetworkAdapters)
Expand Down Expand Up @@ -335,25 +344,41 @@ func ListReferencedChassis(c common.Client, link string) ([]*Chassis, error) {
return result, nil
}

// Thermal gets the thermal temperature and cooling information for the chassis
func (chassis *Chassis) Thermal() (*Thermal, error) {
if chassis.thermal == "" {
// Drives gets the drives attached to the storage controllers that this
// resource represents.
func (chassis *Chassis) Drives() ([]*Drive, error) {
if chassis.drives == "" {
return nil, nil
}

resp, err := chassis.Client.Get(chassis.thermal)
drives, err := common.GetCollection(chassis.Client, chassis.drives)
if err != nil {
return nil, err
}
defer resp.Body.Close()

var thermal Thermal
err = json.NewDecoder(resp.Body).Decode(&thermal)
var result []*Drive
for _, driveLink := range drives.ItemLinks {
drive, err := GetDrive(chassis.Client, driveLink)
if err != nil {
return result, nil
}
result = append(result, drive)
}
return result, nil
}

// Thermal gets the thermal temperature and cooling information for the chassis
func (chassis *Chassis) Thermal() (*Thermal, error) {
if chassis.thermal == "" {
return nil, nil
}

thermal, err := GetThermal(chassis.Client, chassis.thermal)
if err != nil {
return nil, err
}

return &thermal, nil
return thermal, nil
}

// Power gets the power information for the chassis
Expand All @@ -362,19 +387,12 @@ func (chassis *Chassis) Power() (*Power, error) {
return nil, nil
}

resp, err := chassis.Client.Get(chassis.power)
if err != nil {
return nil, err
}
defer resp.Body.Close()

var power Power
err = json.NewDecoder(resp.Body).Decode(&power)
power, err := GetPower(chassis.Client, chassis.power)
if err != nil {
return nil, err
}

return &power, nil
return power, nil
}

// ComputerSystems returns the collection of systems from this chassis
Expand Down
7 changes: 7 additions & 0 deletions redfish/chassis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ var chassisBody = `{
"State": "Enabled",
"Health": "OK"
},
"Drives": {
"@odata.id": "/redfish/v1/Chassis/Chassis-1/Drives"
},
"Thermal": {
"@odata.id": "/redfish/v1/Chassis/Chassis-1/Thermal"
},
Expand Down Expand Up @@ -130,6 +133,10 @@ func TestChassis(t *testing.T) {
t.Errorf("Received invalid health status: %s", result.Status.Health)
}

if result.drives != "/redfish/v1/Chassis/Chassis-1/Drives" {
t.Errorf("Received invalid drive reference: %s", result.drives)
}

if result.thermal != "/redfish/v1/Chassis/Chassis-1/Thermal" {
t.Errorf("Received invalid thermal reference: %s", result.thermal)
}
Expand Down
4 changes: 2 additions & 2 deletions tools/gen_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

# Set correct name for python3 executable. Some platforms just call it python
# while others call it python3.
PYTHON="python"
PYTHON="python3"

# Find the schema document name by going here:
#
# https://www.dmtf.org/standards/redfish
#
# Inspect the url for the schema you want - for example, the 2020.1 update
# document is "DSP8010_2020.1.zip" on this page. The base name then is:
schemadoc="DSP8010_2020.1"
schemadoc="DSP8010_2020.4"

# Check if filename provided on the command line
if [[ "$#" -eq 1 ]]; then
Expand Down

0 comments on commit 7ddb6f9

Please sign in to comment.