-
Notifications
You must be signed in to change notification settings - Fork 105
/
graphicscontroller.go
212 lines (181 loc) · 6.68 KB
/
graphicscontroller.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"reflect"
"github.com/stmcginnis/gofish/common"
)
// GraphicsController shall represent a graphics output device in a Redfish implementation.
type GraphicsController struct {
common.Entity
// ODataContext is the odata context.
ODataContext string `json:"@odata.context"`
// ODataEtag is the odata etag.
ODataEtag string `json:"@odata.etag"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// AssetTag shall contain the user-assigned asset tag, which is an identifying string that tracks the drive for
// inventory purposes.
AssetTag string
// BiosVersion shall contain the version string of the currently installed and running BIOS or firmware for the
// graphics controller.
BiosVersion string
// Description provides a description of this resource.
Description string
// DriverVersion shall contain the version string of the currently loaded driver for this graphics controller.
DriverVersion string
// Location shall contain the location information of the associated graphics controller.
Location common.Location
// Manufacturer shall contain the name of the organization responsible for producing the graphics controller. This
// organization may be the entity from which the graphics controller is purchased, but this is not necessarily
// true.
Manufacturer string
// Model shall contain the manufacturer-provided model information of this graphics controller.
Model string
// Oem shall contain the OEM extensions. All values for properties that this object contains shall conform to the
// Redfish Specification-described requirements.
OEM json.RawMessage `json:"Oem"`
// PartNumber shall contain the manufacturer-provided part number for the graphics controller.
PartNumber string
// Ports shall contain a link to a resource collection of type PortCollection.
ports string
// SKU shall contain the SKU number for this graphics controller.
SKU string
// SerialNumber shall contain a manufacturer-allocated number that identifies the graphics controller.
SerialNumber string
// SparePartNumber shall contain the spare part number of the graphics controller.
SparePartNumber string
// Status shall contain any status or health properties of the resource.
Status common.Status
// rawData holds the original serialized JSON so we can compare updates.
rawData []byte
pcieDevice string
processors []string
// ProcessorsCount is the number of processors trhat this graphics controller contains.
ProcessorsCount int
}
// UnmarshalJSON unmarshals a GraphicsController object from the raw JSON.
func (graphicscontroller *GraphicsController) UnmarshalJSON(b []byte) error {
type temp GraphicsController
type Links struct {
// PCIeDevice shall contain a link to a resource of type PCIeDevice that represents this graphics controller.
PCIeDevice common.Link
// Processors shall contain an array of links to resources of type Processor that represent the processors that
// this graphics controller contains.
Processors common.Links
ProcessorsCount int `json:"Processors@odata.count"`
}
var t struct {
temp
Ports common.Link
Links Links
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
*graphicscontroller = GraphicsController(t.temp)
// Extract the links to other entities for later
graphicscontroller.ports = t.Ports.String()
graphicscontroller.pcieDevice = t.Links.PCIeDevice.String()
graphicscontroller.processors = t.Links.Processors.ToStrings()
graphicscontroller.ProcessorsCount = t.Links.ProcessorsCount
// This is a read/write object, so we need to save the raw object data for later
graphicscontroller.rawData = b
return nil
}
// Ports get the ports associated with this graphics controller.
func (graphicscontroller *GraphicsController) Ports() ([]*Port, error) {
return ListReferencedPorts(graphicscontroller.GetClient(), graphicscontroller.ports)
}
// PCIeDevice gets the PCIeDevice for this graphics controller.
func (graphicscontroller *GraphicsController) PCIeDevice() (*PCIeDevice, error) {
if graphicscontroller.pcieDevice == "" {
return nil, nil
}
return GetPCIeDevice(graphicscontroller.GetClient(), graphicscontroller.pcieDevice)
}
// Processors gets this graphics controllers processors.
func (graphicscontroller *GraphicsController) Processors() ([]*Processor, error) {
var result []*Processor
collectionError := common.NewCollectionError()
for _, uri := range graphicscontroller.processors {
unit, err := GetProcessor(graphicscontroller.GetClient(), uri)
if err != nil {
collectionError.Failures[uri] = err
} else {
result = append(result, unit)
}
}
if collectionError.Empty() {
return result, nil
}
return result, collectionError
}
// Update commits updates to this object's properties to the running system.
func (graphicscontroller *GraphicsController) Update() error {
// Get a representation of the object's original state so we can find what
// to update.
original := new(GraphicsController)
original.UnmarshalJSON(graphicscontroller.rawData)
readWriteFields := []string{
"AssetTag",
}
originalElement := reflect.ValueOf(original).Elem()
currentElement := reflect.ValueOf(graphicscontroller).Elem()
return graphicscontroller.Entity.Update(originalElement, currentElement, readWriteFields)
}
// GetGraphicsController will get a GraphicsController instance from the service.
func GetGraphicsController(c common.Client, uri string) (*GraphicsController, error) {
resp, err := c.Get(uri)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var graphicscontroller GraphicsController
err = json.NewDecoder(resp.Body).Decode(&graphicscontroller)
if err != nil {
return nil, err
}
graphicscontroller.SetClient(c)
return &graphicscontroller, nil
}
// ListReferencedGraphicsControllers gets the collection of GraphicsController from
// a provided reference.
func ListReferencedGraphicsControllers(c common.Client, link string) ([]*GraphicsController, error) {
var result []*GraphicsController
if link == "" {
return result, nil
}
type GetResult struct {
Item *GraphicsController
Link string
Error error
}
ch := make(chan GetResult)
collectionError := common.NewCollectionError()
get := func(link string) {
graphicscontroller, err := GetGraphicsController(c, link)
ch <- GetResult{Item: graphicscontroller, 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
}