diff --git a/common/collection.go b/common/collection.go index c7fdfe40..859ff355 100644 --- a/common/collection.go +++ b/common/collection.go @@ -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() } diff --git a/redfish/pciedevice.go b/redfish/pciedevice.go index 3ea70a2c..4c5204fe 100644 --- a/redfish/pciedevice.go +++ b/redfish/pciedevice.go @@ -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 } @@ -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:"Chassis@odata.count"` - PCIeFunctions common.Links - PCIeFunctionsCount int `json:"PCIeFunctions@odata.count"` + Chassis common.Links + ChassisCount int `json:"Chassis@odata.count"` } var t struct { temp - Assembly common.Link - Links links + Assembly common.Link + PCIeFunctions common.Link + Links links } err := json.Unmarshal(b, &t) @@ -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 @@ -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) } diff --git a/redfish/pciedevice_test.go b/redfish/pciedevice_test.go index 04a3a34b..d56470c4 100644 --- a/redfish/pciedevice_test.go +++ b/redfish/pciedevice_test.go @@ -29,18 +29,13 @@ var pcieDeviceBody = `{ "Chassis": [{ "@odata.id": "/redfish/v1/Chassis/Chassis-1" }], - "Chassis@odata.count": 1, - "PCIeFunctions": [{ - "@odata.id": "/redfish/v1/Functions/1" - }, - { - "@odata.id": "/redfish/v1/Functions/2" - } - ], - "PCIeFunctions@odata.count": 1 + "Chassis@odata.count": 1 }, "Manufacturer": "Acme Inc", "Model": "A1", + "PCIeFunctions": { + "@odata.id": "/redfish/v1/Systems/system/PCIeDevices/AAABBCC/PCIeFunctions" + }, "PCIeInterface": { "LanesInUse": 32, "MaxLanes": 32,