diff --git a/redfish/eventdestination.go b/redfish/eventdestination.go index fbf25a9b..469ed93c 100644 --- a/redfish/eventdestination.go +++ b/redfish/eventdestination.go @@ -459,7 +459,7 @@ func sendCreateEventDestinationRequest( resp, err := c.Post(uri, s) if err != nil { - return + return err.Error(), err } defer resp.Body.Close() diff --git a/redfish/networkadapter.go b/redfish/networkadapter.go index 06ce31b3..46b29b8c 100644 --- a/redfish/networkadapter.go +++ b/redfish/networkadapter.go @@ -75,9 +75,11 @@ type ControllerCapabilities struct { } } -// Controllers shall describe a network controller ASIC that makes up part of a +// Controller shall describe a network controller ASIC that makes up part of a // NetworkAdapter. -type Controllers struct { +type Controller struct { + common.Entity + // ControllerCapabilities shall contain the capabilities of this controller. ControllerCapabilities ControllerCapabilities // FirmwarePackageVersion shall be the version number of the user-facing @@ -109,15 +111,15 @@ type Controllers struct { PCIeDevicesCount int } -// UnmarshalJSON unmarshals a Controllers object from the raw JSON. -func (controllers *Controllers) UnmarshalJSON(b []byte) error { - type temp Controllers +// UnmarshalJSON unmarshals a Controller object from the raw JSON. +func (controller *Controller) UnmarshalJSON(b []byte) error { + type temp Controller type links struct { NetworkPorts common.Links NetworkPortsCount int `json:"EthernetInterfaces@odata.count"` NetworkDeviceFunctions common.Links NetworkDeviceFunctionsCount int `json:"NetworkDeviceFunctions@odata.count"` - PCIeDevice common.Link + PCIeDevices common.Links PCIeDevicesCount int `json:"PCIeDevices@odata.count"` } @@ -132,17 +134,80 @@ func (controllers *Controllers) UnmarshalJSON(b []byte) error { } // Extract the links to other entities for later - *controllers = Controllers(t.temp) - controllers.networkPorts = t.Links.NetworkPorts.ToStrings() - controllers.NetworkPortsCount = t.Links.NetworkPortsCount - controllers.networkDeviceFunctions = t.Links.NetworkDeviceFunctions.ToStrings() - controllers.NetworkDeviceFunctionsCount = t.Links.NetworkDeviceFunctionsCount - controllers.pcieDevices = t.Links.NetworkDeviceFunctions.ToStrings() - controllers.PCIeDevicesCount = t.Links.NetworkDeviceFunctionsCount + *controller = Controller(t.temp) + controller.networkPorts = t.Links.NetworkPorts.ToStrings() + controller.NetworkPortsCount = t.Links.NetworkPortsCount + controller.networkDeviceFunctions = t.Links.NetworkDeviceFunctions.ToStrings() + controller.NetworkDeviceFunctionsCount = t.Links.NetworkDeviceFunctionsCount + controller.pcieDevices = t.Links.PCIeDevices.ToStrings() + controller.PCIeDevicesCount = t.Links.NetworkDeviceFunctionsCount return nil } +// PCIeDevices gets all PCIeDevices for this controller. +func (controller *Controller) PCIeDevices() ([]*PCIeDevice, error) { + var result []*PCIeDevice + + collectionError := common.NewCollectionError() + for _, pciedeviceLink := range controller.pcieDevices { + pciedevice, err := GetPCIeDevice(controller.GetClient(), pciedeviceLink) + if err != nil { + collectionError.Failures[pciedeviceLink] = err + } else { + result = append(result, pciedevice) + } + } + + if collectionError.Empty() { + return result, nil + } + + return result, collectionError +} + +// NetworkDeviceFunction gets all NetworkDeviceFunction for this controller. +func (controller *Controller) NetworkDeviceFunctions() ([]*NetworkDeviceFunction, error) { + var result []*NetworkDeviceFunction + + collectionError := common.NewCollectionError() + for _, networkDeviceLink := range controller.networkDeviceFunctions { + networkDeviceFunction, err := GetNetworkDeviceFunction(controller.GetClient(), networkDeviceLink) + if err != nil { + collectionError.Failures[networkDeviceLink] = err + } else { + result = append(result, networkDeviceFunction) + } + } + + if collectionError.Empty() { + return result, nil + } + + return result, collectionError +} + +// NetworkPorts gets all NetworkPorts for this controller. +func (controller *Controller) NetworkPorts() ([]*NetworkPort, error) { + var result []*NetworkPort + + collectionError := common.NewCollectionError() + for _, networkPortLink := range controller.networkPorts { + networkPort, err := GetNetworkPort(controller.GetClient(), networkPortLink) + if err != nil { + collectionError.Failures[networkPortLink] = err + } else { + result = append(result, networkPort) + } + } + + if collectionError.Empty() { + return result, nil + } + + return result, collectionError +} + // DataCenterBridging shall describe the capability, status, // and configuration values related to Data Center Bridging (DCB) for a // controller. @@ -176,9 +241,9 @@ type NetworkAdapter struct { ODataType string `json:"@odata.type"` // Assembly shall be a link to a resource of type Assembly. assembly string - // Controllers shall contain the set of network controllers ASICs that make + // Controller shall contain the set of network controllers ASICs that make // up this NetworkAdapter. - Controllers []Controllers + controllers []*Controller // Description provides a description of this resource. Description string // Manufacturer shall contain a value that represents the manufacturer of @@ -218,6 +283,7 @@ func (networkadapter *NetworkAdapter) UnmarshalJSON(b []byte) error { Assembly common.Link NetworkDeviceFunctions common.Link NetworkPorts common.Link + Controllers []*Controller Actions actions } @@ -232,7 +298,7 @@ func (networkadapter *NetworkAdapter) UnmarshalJSON(b []byte) error { networkadapter.networkDeviceFunctions = t.NetworkDeviceFunctions.String() networkadapter.networkPorts = t.NetworkPorts.String() networkadapter.resetSettingsToDefaultTarget = t.Actions.ResetSettingsToDefault.Target - + networkadapter.controllers = t.Controllers return nil } @@ -308,3 +374,10 @@ func (networkadapter *NetworkAdapter) NetworkPorts() ([]*NetworkPort, error) { func (networkadapter *NetworkAdapter) ResetSettingsToDefault() error { return networkadapter.Post(networkadapter.resetSettingsToDefaultTarget, nil) } + +func (networkadapter *NetworkAdapter) Controllers() []*Controller { + for i := range networkadapter.controllers { + networkadapter.controllers[i].SetClient(networkadapter.GetClient()) + } + return networkadapter.controllers +} diff --git a/redfish/networkadapter_test.go b/redfish/networkadapter_test.go index 7cab0654..6e95e8d6 100644 --- a/redfish/networkadapter_test.go +++ b/redfish/networkadapter_test.go @@ -52,11 +52,7 @@ var networkAdapterBody = strings.NewReader( "NetworkDeviceFunctions@odata.count": 1, "NetworkPorts": [{ "@odata.id": "/redfish/v1/NetworkAdapters/Port-1" - }, - { - "@odata.id": "/redfish/v1/NetworkAdapters/Port-2" - } - ], + }], "NetworkPorts@odata.count": 2, "PCIeDevices": [{ "@odata.id": "/redfish/v1/NetworkAdapters/PCIeDevice-1" @@ -108,21 +104,31 @@ func TestNetworkAdapter(t *testing.T) { t.Errorf("Received invalid name: %s", result.Name) } - if !result.Controllers[0].ControllerCapabilities.DataCenterBridging.Capable { + if !result.controllers[0].ControllerCapabilities.DataCenterBridging.Capable { t.Error("DCB should be enabled") } - if result.Controllers[0].ControllerCapabilities.NPIV.MaxDeviceLogins != 1024 { + if result.controllers[0].ControllerCapabilities.NPIV.MaxDeviceLogins != 1024 { t.Errorf("Received incorrect Controller NPIC max device logins: %d", - result.Controllers[0].ControllerCapabilities.NPIV.MaxDeviceLogins) + result.controllers[0].ControllerCapabilities.NPIV.MaxDeviceLogins) + } + + if result.controllers[0].PCIeInterface.MaxPCIeType != Gen4PCIeTypes { + t.Errorf("Received incorrect max PCIe type: %s", result.controllers[0].PCIeInterface.MaxPCIeType) } - if result.Controllers[0].PCIeInterface.MaxPCIeType != Gen4PCIeTypes { - t.Errorf("Received incorrect max PCIe type: %s", result.Controllers[0].PCIeInterface.MaxPCIeType) + if result.controllers[0].PCIeInterface.PCIeType != Gen4PCIeTypes { + t.Errorf("Received incorrect PCIe type: %s", result.controllers[0].PCIeInterface.PCIeType) } - if result.Controllers[0].PCIeInterface.PCIeType != Gen4PCIeTypes { - t.Errorf("Received incorrect PCIe type: %s", result.Controllers[0].PCIeInterface.PCIeType) + if PCIeTypes(result.controllers[0].pcieDevices[0]) != "/redfish/v1/NetworkAdapters/PCIeDevice-1" { + t.Errorf("Received incorrect PCIeDevice Link: %s", "/redfish/v1/NetworkAdapters/PCIeDevice-1") + } + if PCIeTypes(result.controllers[0].networkPorts[0]) != "/redfish/v1/NetworkAdapters/Port-1" { + t.Errorf("Received incorrect NetworkPorts Link: %s", "/redfish/v1/NetworkAdapters/Port-1") + } + if PCIeTypes(result.controllers[0].networkDeviceFunctions[0]) != "/redfish/v1/NetworkAdapters/DeviceFunction-1" { + t.Errorf("Received incorrect NetworkDeviceFunctions Link: %s", "/redfish/v1/NetworkAdapters/DeviceFunction-1") } if result.resetSettingsToDefaultTarget != "/redfish/v1/NetworkAdapter/Actions/NetworkAdapter.ResetSettingsToDefault" {