Skip to content

Commit

Permalink
according to the 1.4 PCIeFunctions standard has been moved (#240)
Browse files Browse the repository at this point in the history
Co-authored-by: Maksim Kovshov <[email protected]>
  • Loading branch information
Muyk33rus and Maksim Kovshov authored Mar 21, 2023
1 parent 4c03e55 commit 7a1a92f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 39 deletions.
2 changes: 1 addition & 1 deletion common/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (c *Collection) UnmarshalJSON(b []byte) error {

// Swordfish has them at the root
if len(c.ItemLinks) == 0 &&
(t.Count > 0 || t.ODataCount > 0) {
(t.Count > 0 || t.ODataCount > 0 || len(t.Members) > 0) {
c.ItemLinks = t.Members.ToStrings()
}

Expand Down
38 changes: 9 additions & 29 deletions redfish/pciedevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ type PCIeDevice struct {
ChassisCount int
// PCIeFunctions shall be a reference to the resources that this device
// exposes and shall reference a resource of type PCIeFunction.
pcieFunctions []string
// PCIeFunctionsCount is the number of PCIeFunctions.
PCIeFunctionsCount int
pcieFunctions string
// rawData holds the original serialized JSON so we can compare updates.
rawData []byte
}
Expand All @@ -96,15 +94,14 @@ type PCIeDevice struct {
func (pciedevice *PCIeDevice) UnmarshalJSON(b []byte) error {
type temp PCIeDevice
type links struct {
Chassis common.Links
ChassisCount int `json:"[email protected]"`
PCIeFunctions common.Links
PCIeFunctionsCount int `json:"[email protected]"`
Chassis common.Links
ChassisCount int `json:"[email protected]"`
}
var t struct {
temp
Assembly common.Link
Links links
Assembly common.Link
PCIeFunctions common.Link
Links links
}

err := json.Unmarshal(b, &t)
Expand All @@ -118,8 +115,7 @@ func (pciedevice *PCIeDevice) UnmarshalJSON(b []byte) error {
pciedevice.assembly = t.Assembly.String()
pciedevice.chassis = t.Links.Chassis.ToStrings()
pciedevice.ChassisCount = t.Links.ChassisCount
pciedevice.pcieFunctions = t.Links.PCIeFunctions.ToStrings()
pciedevice.PCIeFunctionsCount = t.Links.PCIeFunctionsCount
pciedevice.pcieFunctions = t.PCIeFunctions.String()

// This is a read/write object, so we need to save the raw object data for later
pciedevice.rawData = b
Expand Down Expand Up @@ -241,22 +237,6 @@ func (pciedevice *PCIeDevice) Chassis() ([]*Chassis, error) {
}

// PCIeFunctions get the PCIe functions that this device exposes.
func (pciedevice *PCIeDevice) PCIeFunctions() ([]*PCIeDevice, error) {
var result []*PCIeDevice

collectionError := common.NewCollectionError()
for _, funcLink := range pciedevice.pcieFunctions {
pciFunction, err := GetPCIeDevice(pciedevice.Client, funcLink)
if err != nil {
collectionError.Failures[funcLink] = err
} else {
result = append(result, pciFunction)
}
}

if collectionError.Empty() {
return result, nil
}

return result, collectionError
func (pciedevice *PCIeDevice) PCIeFunctions() ([]*PCIeFunction, error) {
return ListReferencedPCIeFunctions(pciedevice.Client, pciedevice.pcieFunctions)
}
13 changes: 4 additions & 9 deletions redfish/pciedevice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,13 @@ var pcieDeviceBody = `{
"Chassis": [{
"@odata.id": "/redfish/v1/Chassis/Chassis-1"
}],
"[email protected]": 1,
"PCIeFunctions": [{
"@odata.id": "/redfish/v1/Functions/1"
},
{
"@odata.id": "/redfish/v1/Functions/2"
}
],
"[email protected]": 1
"[email protected]": 1
},
"Manufacturer": "Acme Inc",
"Model": "A1",
"PCIeFunctions": {
"@odata.id": "/redfish/v1/Systems/system/PCIeDevices/AAABBCC/PCIeFunctions"
},
"PCIeInterface": {
"LanesInUse": 32,
"MaxLanes": 32,
Expand Down

0 comments on commit 7a1a92f

Please sign in to comment.