Skip to content

Commit

Permalink
Add Supermicro OEM Manager subobjects (#372)
Browse files Browse the repository at this point in the history
This adds a few of the objects that are linked off of the OEM links for
a Manager.

Signed-off-by: Sean McGinnis <[email protected]>
  • Loading branch information
stmcginnis authored Oct 16, 2024
1 parent ca10211 commit 13dccf5
Show file tree
Hide file tree
Showing 32 changed files with 1,814 additions and 3 deletions.
68 changes: 68 additions & 0 deletions oem/smc/fanmode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// SPDX-License-Identifier: BSD-3-Clause
//

package smc

import (
"encoding/json"
"reflect"

"github.com/stmcginnis/gofish/common"
)

// FanMode is an instance of a FanMode object.
type FanMode struct {
common.Entity

Mode string
AllowableModes []string `json:"[email protected]"`

// RawData holds the original serialized JSON so we can compare updates.
RawData []byte
}

// UnmarshalJSON unmarshals a FanMode object from the raw JSON.
func (i *FanMode) UnmarshalJSON(b []byte) error {
type temp FanMode
var t struct {
temp
}

err := json.Unmarshal(b, &t)
if err != nil {
return err
}

*i = FanMode(t.temp)

// This is a read/write object, so we need to save the raw object data for later
i.RawData = b

return nil
}

// Update commits updates to this object's properties to the running system.
func (i *FanMode) Update() error {
// Get a representation of the object's original state so we can find what
// to update.
orig := new(FanMode)
err := orig.UnmarshalJSON(i.RawData)
if err != nil {
return err
}

readWriteFields := []string{
"Mode",
}

originalElement := reflect.ValueOf(orig).Elem()
currentElement := reflect.ValueOf(i).Elem()

return i.Entity.Update(originalElement, currentElement, readWriteFields)
}

// GetFanMode will get a FanMode instance from the service.
func GetFanMode(c common.Client, uri string) (*FanMode, error) {
return common.GetObject[FanMode](c, uri)
}
46 changes: 46 additions & 0 deletions oem/smc/fanmode_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// SPDX-License-Identifier: BSD-3-Clause
//

package smc

import (
"encoding/json"
"strings"
"testing"
)

var fanModeBody = `{
"@odata.type": "#FanMode.v1_0_1.FanMode",
"@odata.id": "/redfish/v1/Managers/1/Oem/Supermicro/FanMode",
"Name": "FanMode",
"Id": "Fan Mode",
"Mode": "HeavyIO",
"[email protected]": [
"FullSpeed",
"Optimal",
"HeavyIO"
],
"@odata.etag": "\"753bafbafcb8047326ec2c269ad52111\""
}`

// TestFanMode tests the parsing of FanMode objects.
func TestFanMode(t *testing.T) {
var result FanMode
err := json.NewDecoder(strings.NewReader(fanModeBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}

if result.ID != "Fan Mode" {
t.Errorf("Received invalid ID: %s", result.ID)
}

if result.Mode != "HeavyIO" {
t.Errorf("Invalid fan mode: %s", result.Mode)
}

if len(result.AllowableModes) != 3 {
t.Errorf("Unexpected allowable modes: %v", result.AllowableModes)
}
}
68 changes: 68 additions & 0 deletions oem/smc/ikvm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// SPDX-License-Identifier: BSD-3-Clause
//

package smc

import (
"encoding/json"
"reflect"

"github.com/stmcginnis/gofish/common"
)

// IKVM is an instance of a IKVM object.
type IKVM struct {
common.Entity

CurrentInterface string `json:"Current Interface"`
URI string

// RawData holds the original serialized JSON so we can compare updates.
RawData []byte
}

// UnmarshalJSON unmarshals a IKVM object from the raw JSON.
func (i *IKVM) UnmarshalJSON(b []byte) error {
type temp IKVM
var t struct {
temp
}

err := json.Unmarshal(b, &t)
if err != nil {
return err
}

*i = IKVM(t.temp)

// This is a read/write object, so we need to save the raw object data for later
i.RawData = b

return nil
}

// Update commits updates to this object's properties to the running system.
func (i *IKVM) Update() error {
// Get a representation of the object's original state so we can find what
// to update.
orig := new(IKVM)
err := orig.UnmarshalJSON(i.RawData)
if err != nil {
return err
}

readWriteFields := []string{
"CurrentInterface",
}

originalElement := reflect.ValueOf(orig).Elem()
currentElement := reflect.ValueOf(i).Elem()

return i.Entity.Update(originalElement, currentElement, readWriteFields)
}

// GetIKVM will get a IKVM instance from the service.
func GetIKVM(c common.Client, uri string) (*IKVM, error) {
return common.GetObject[IKVM](c, uri)
}
42 changes: 42 additions & 0 deletions oem/smc/ikvm_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// SPDX-License-Identifier: BSD-3-Clause
//

package smc

import (
"encoding/json"
"strings"
"testing"
)

var iKVMBody = `{
"@odata.type": "#IKVM.v1_0_2.IKVM",
"@odata.id": "/redfish/v1/Managers/1/Oem/Supermicro/IKVM",
"Id": "IKVM",
"Name": "IKVM",
"Current interface": "HTML 5",
"URI": "/redfish/VVGBkzp32dNpSOI.IKVM",
"@odata.etag": "\"916e58e6235aa0579147a3114560a596\""
}`

// TestIKVM tests the parsing of IKVM objects.
func TestIKVM(t *testing.T) {
var result IKVM
err := json.NewDecoder(strings.NewReader(iKVMBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}

if result.ID != "IKVM" {
t.Errorf("Received invalid ID: %s", result.ID)
}

if result.CurrentInterface != "HTML 5" {
t.Errorf("Invalid current interface: %s", result.CurrentInterface)
}

if result.URI != "/redfish/VVGBkzp32dNpSOI.IKVM" {
t.Errorf("Invalid URI: %s", result.URI)
}
}
89 changes: 89 additions & 0 deletions oem/smc/ipaccesscontrol.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//
// SPDX-License-Identifier: BSD-3-Clause
//

package smc

import (
"encoding/json"
"reflect"

"github.com/stmcginnis/gofish/common"
)

type FilterRulePolicy string

const (
FilterRulePolicyAllow FilterRulePolicy = "Allow"
FilterRulePolicyDeny FilterRulePolicy = "Deny"
)

// FilterRule represents an individual filter rule.
type FilterRule struct {
common.Entity
Address string
PrefixLength int
Policy FilterRulePolicy
}

// IPAccessControl is an instance of an IPAccessControl object.
type IPAccessControl struct {
common.Entity

Enabled bool `json:"ServiceEnabled"`
filterRules string

// RawData holds the original serialized JSON so we can compare updates.
RawData []byte
}

// UnmarshalJSON unmarshals a IPAccessControl object from the raw JSON.
func (i *IPAccessControl) UnmarshalJSON(b []byte) error {
type temp IPAccessControl
var t struct {
temp
FilterRules common.Link `json:"FilterRules"`
}

err := json.Unmarshal(b, &t)
if err != nil {
return err
}

*i = IPAccessControl(t.temp)
i.filterRules = t.FilterRules.String()

// This is a read/write object, so we need to save the raw object data for later
i.RawData = b

return nil
}

// Update commits updates to this object's properties to the running system.
func (i *IPAccessControl) Update() error {
// Get a representation of the object's original state so we can find what
// to update.
orig := new(IPAccessControl)
err := orig.UnmarshalJSON(i.RawData)
if err != nil {
return err
}

readWriteFields := []string{
"Enabled",
}

originalElement := reflect.ValueOf(orig).Elem()
currentElement := reflect.ValueOf(i).Elem()

return i.Entity.Update(originalElement, currentElement, readWriteFields)
}

func (i *IPAccessControl) FilterRules() ([]*FilterRule, error) {
return common.GetCollectionObjects[FilterRule](i.GetClient(), i.filterRules)
}

// GetIPAccessControl will get a IPAccessControl instance from the service.
func GetIPAccessControl(c common.Client, uri string) (*IPAccessControl, error) {
return common.GetObject[IPAccessControl](c, uri)
}
44 changes: 44 additions & 0 deletions oem/smc/ipaccesscontrol_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// SPDX-License-Identifier: BSD-3-Clause
//

package smc

import (
"encoding/json"
"strings"
"testing"
)

var ipAccessControlBody = `{
"@odata.type": "#IPAccessControl.v1_0_1.IPAccessControl",
"@odata.id": "/redfish/v1/Managers/1/Oem/Supermicro/IPAccessControl",
"Id": "IP Access Control",
"Name": "IP Access Control",
"ServiceEnabled": true,
"FilterRules": {
"@odata.id": "/redfish/v1/Managers/1/Oem/Supermicro/IPAccessControl/FilterRules"
},
"@odata.etag": "\"ecbaa3f8ca55261d32edce302b8e3ddd\""
}`

// TestIPAccessControl tests the parsing of IPAccessControl objects.
func TestIPAccessControl(t *testing.T) {
var result IPAccessControl
err := json.NewDecoder(strings.NewReader(ipAccessControlBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}

if result.ID != "IP Access Control" {
t.Errorf("Received invalid ID: %s", result.ID)
}

if !result.Enabled {
t.Errorf("Invalid enable state: %t", result.Enabled)
}

if result.filterRules != "/redfish/v1/Managers/1/Oem/Supermicro/IPAccessControl/FilterRules" {
t.Errorf("Invalid filter rule link: %s", result.filterRules)
}
}
Loading

0 comments on commit 13dccf5

Please sign in to comment.