From ecc60dada3e9dd2e1e972b81032287bc2f2789d7 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Tue, 22 Sep 2020 10:13:01 +0200 Subject: [PATCH 1/2] Volume OperationApplyTimeSupport added --- redfish/storage.go | 6 ++++++ redfish/volume.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/redfish/storage.go b/redfish/storage.go index 8479901f..a9900fff 100644 --- a/redfish/storage.go +++ b/redfish/storage.go @@ -187,6 +187,12 @@ func (storage *Storage) SetEncryptionKey(key string) error { return err } +// GetOperationApplyTimeValues returns the OperationApplyTime values applicable for this storage +func (storage *Storage) GetOperationApplyTimeValues() ([]common.OperationApplyTime, error) { + return AllowedVolumesUpdateApplyTimes(storage.Client, storage.volumes) + +} + // StorageController is used to represent a resource that represents a // storage controller in the Redfish specification. type StorageController struct { diff --git a/redfish/volume.go b/redfish/volume.go index 8a41daa4..106fb86d 100644 --- a/redfish/volume.go +++ b/redfish/volume.go @@ -192,6 +192,15 @@ type Volume struct { drives []string } +// Volumes is used to represent the volumes information related to a Storage +type Volumes struct { + common.Entity + // OperationApplyTimeSupport contains, among other things, the types + // of apply times the client is allowed request when performing a Create, + // Delete, or Action operation. + OperationApplyTimeSupport common.OperationApplyTimeSupport `json:"@Redfish.OperationApplyTimeSupport"` +} + // UnmarshalJSON unmarshals a Volume object from the raw JSON. func (volume *Volume) UnmarshalJSON(b []byte) error { type temp Volume @@ -273,3 +282,24 @@ func (volume *Volume) Drives() ([]*Drive, error) { return result, nil } + +// AllowedVolumesUpdateApplyTimes returns the set of allowed apply times to request when setting the volumes values +func AllowedVolumesUpdateApplyTimes(c common.Client, link string) ([]common.OperationApplyTime, error) { + resp, err := c.Get(link) + if err != nil { + return nil, err + } + defer resp.Body.Close() + var volumes Volumes + + err = json.NewDecoder(resp.Body).Decode(&volumes) + if err != nil { + return nil, err + } + + var applyTimes []common.OperationApplyTime + for _, v := range volumes.OperationApplyTimeSupport.SupportedValues { + applyTimes = append(applyTimes, v) + } + return applyTimes, nil +} From e576c2030bc2db103fd4de6f432da4b0865831d4 Mon Sep 17 00:00:00 2001 From: Miguel Sama Date: Wed, 23 Sep 2020 12:46:32 +0200 Subject: [PATCH 2/2] Removed Volumes struct --- redfish/volume.go | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/redfish/volume.go b/redfish/volume.go index 106fb86d..c21466c3 100644 --- a/redfish/volume.go +++ b/redfish/volume.go @@ -192,15 +192,6 @@ type Volume struct { drives []string } -// Volumes is used to represent the volumes information related to a Storage -type Volumes struct { - common.Entity - // OperationApplyTimeSupport contains, among other things, the types - // of apply times the client is allowed request when performing a Create, - // Delete, or Action operation. - OperationApplyTimeSupport common.OperationApplyTimeSupport `json:"@Redfish.OperationApplyTimeSupport"` -} - // UnmarshalJSON unmarshals a Volume object from the raw JSON. func (volume *Volume) UnmarshalJSON(b []byte) error { type temp Volume @@ -290,15 +281,17 @@ func AllowedVolumesUpdateApplyTimes(c common.Client, link string) ([]common.Oper return nil, err } defer resp.Body.Close() - var volumes Volumes + var temp struct { + OperationApplyTimeSupport common.OperationApplyTimeSupport `json:"@Redfish.OperationApplyTimeSupport"` + } - err = json.NewDecoder(resp.Body).Decode(&volumes) + err = json.NewDecoder(resp.Body).Decode(&temp) if err != nil { return nil, err } var applyTimes []common.OperationApplyTime - for _, v := range volumes.OperationApplyTimeSupport.SupportedValues { + for _, v := range temp.OperationApplyTimeSupport.SupportedValues { applyTimes = append(applyTimes, v) } return applyTimes, nil