forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusbcontroller.go
107 lines (92 loc) · 3.6 KB
/
usbcontroller.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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"github.com/stmcginnis/gofish/common"
)
// USBController shall represent a USB controller in a Redfish implementation.
type USBController 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"`
// Description provides a description of this resource.
Description string
// Manufacturer shall contain the name of the organization responsible for producing the USB controller. This
// organization may be the entity from which the USB controller is purchased, but this is not necessarily true.
Manufacturer string
// Model shall contain the manufacturer-provided model information of this USB 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 USB 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 USB controller.
SKU string
// SerialNumber shall contain a manufacturer-allocated number that identifies the USB controller.
SerialNumber string
// SparePartNumber shall contain the spare part number of the USB controller.
SparePartNumber string
// Status shall contain any status or health properties of the resource.
Status common.Status
pcieDevice string
processors []string
// ProcessorsCount is the number of processors that can use this USB controller.
ProcessorsCount int
}
// UnmarshalJSON unmarshals a USBController object from the raw JSON.
func (usbcontroller *USBController) UnmarshalJSON(b []byte) error {
type temp USBController
type Links struct {
PCIeDevice common.Link
Processors common.Links
ProcessorsCount int `json:"[email protected]"`
}
var t struct {
temp
Links Links
Ports common.Link
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
// Extract the links to other entities for later
*usbcontroller = USBController(t.temp)
usbcontroller.pcieDevice = t.Links.PCIeDevice.String()
usbcontroller.processors = t.Links.Processors.ToStrings()
usbcontroller.ports = t.Ports.String()
return nil
}
// PCIeDevice gets the PCIeDevice for this USB controller.
func (usbcontroller *USBController) PCIeDevice() (*PCIeDevice, error) {
if usbcontroller.pcieDevice == "" {
return nil, nil
}
return GetPCIeDevice(usbcontroller.GetClient(), usbcontroller.pcieDevice)
}
// Processors gets the processors that can utilize this USB controller.
func (usbcontroller *USBController) Processors() ([]*Processor, error) {
return common.GetObjects[Processor](usbcontroller.GetClient(), usbcontroller.processors)
}
// Ports gets the ports of the USB controller.
func (usbcontroller *USBController) Ports() ([]*Port, error) {
return ListReferencedPorts(usbcontroller.GetClient(), usbcontroller.ports)
}
// GetUSBController will get a USBController instance from the service.
func GetUSBController(c common.Client, uri string) (*USBController, error) {
return common.GetObject[USBController](c, uri)
}
// ListReferencedUSBControllers gets the collection of USBController from
// a provided reference.
func ListReferencedUSBControllers(c common.Client, link string) ([]*USBController, error) {
return common.GetCollectionObjects[USBController](c, link)
}