forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
memorydomain.go
138 lines (116 loc) · 3.47 KB
/
memorydomain.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"github.com/stmcginnis/gofish/common"
)
// MemoryDomain is used to represent Memory Domains.
type MemoryDomain struct {
common.Entity
// ODataContext is the odata context.
ODataContext string `json:"@odata.context"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// AllowsBlockProvisioning shall indicate if this Memory Domain supports the
// creation of Blocks of memory.
AllowsBlockProvisioning bool
// AllowsMemoryChunkCreation shall indicate if this Memory Domain supports
// the creation of Memory Chunks.
AllowsMemoryChunkCreation bool
// AllowsMirroring shall indicate if this Memory Domain supports the
// creation of Memory Chunks with mirroring enabled.
AllowsMirroring bool
// AllowsSparing shall indicate if this Memory Domain supports the creation
// of Memory Chunks with sparing enabled.
AllowsSparing bool
// Description provides a description of this resource.
Description string
// InterleavableMemorySets shall represent the interleave sets for the
// memory chunk.
InterleavableMemorySets []MemorySet
// memoryChunks shall be a link to a collection of type MemoryChunkCollection.
memoryChunks string
}
// UnmarshalJSON unmarshals a MemoryDomain object from the raw JSON.
func (memorydomain *MemoryDomain) UnmarshalJSON(b []byte) error {
type temp MemoryDomain
var t struct {
temp
MemoryChunks common.Link
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
// Extract the links to other entities for later
*memorydomain = MemoryDomain(t.temp)
memorydomain.memoryChunks = t.MemoryChunks.String()
return nil
}
// GetMemoryDomain will get a MemoryDomain instance from the service.
func GetMemoryDomain(c common.Client, uri string) (*MemoryDomain, error) {
var memoryDomain MemoryDomain
return &memoryDomain, memoryDomain.Get(c, uri, &memoryDomain)
}
// ListReferencedMemoryDomains gets the collection of MemoryDomain from
// a provided reference.
func ListReferencedMemoryDomains(c common.Client, link string) ([]*MemoryDomain, error) { //nolint:dupl
var result []*MemoryDomain
if link == "" {
return result, nil
}
type GetResult struct {
Item *MemoryDomain
Link string
Error error
}
ch := make(chan GetResult)
collectionError := common.NewCollectionError()
get := func(link string) {
memorydomain, err := GetMemoryDomain(c, link)
ch <- GetResult{Item: memorydomain, Link: link, Error: err}
}
go func() {
err := common.CollectList(get, c, link)
if err != nil {
collectionError.Failures[link] = err
}
close(ch)
}()
for r := range ch {
if r.Error != nil {
collectionError.Failures[r.Link] = r.Error
} else {
result = append(result, r.Item)
}
}
if collectionError.Empty() {
return result, nil
}
return result, collectionError
}
// MemorySet shall represent the interleave sets for a memory chunk.
type MemorySet struct {
// MemorySet shall be links to objects of type Memory.
memorySet []string
// MemorySetCount is the number of memory sets.
MemorySetCount int `json:"MemorySet@odata.count"`
}
// UnmarshalJSON unmarshals a MemorySet object from the raw JSON.
func (memoryset *MemorySet) UnmarshalJSON(b []byte) error {
type temp MemorySet
var t struct {
temp
MemorySet common.Links
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
// Extract the links to other entities for later
*memoryset = MemorySet(t.temp)
memoryset.memorySet = t.MemorySet.ToStrings()
return nil
}