forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcieslots.go
157 lines (137 loc) · 4.88 KB
/
pcieslots.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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"github.com/stmcginnis/gofish/common"
)
type SlotTypes string
const (
// Full-Length PCIe slot.
FullLength SlotTypes = "FullLength"
// Half-Length PCIe slot.
HalfLength SlotTypes = "HalfLength"
// Low-Profile or Slim PCIe slot.
LowProfile SlotTypes = "LowProfile"
// PCIe M.2 slot.
M2 SlotTypes = "M2"
// Mini PCIe slot.
Mini SlotTypes = "Mini"
// (v1.2+) Open Compute Project 3.0 large form factor slot.
OCP3Large SlotTypes = "OCP3Large"
// (v1.2+) Open Compute Project 3.0 small form factor slot.
OCP3Small SlotTypes = "OCP3Small"
// An OEM-specific slot.
OEM SlotTypes = "OEM"
// (v1.3+) U.2 / SFF-8639 slot or bay.
U2 SlotTypes = "U2"
)
// PCIeSlot shall contain the definition for a PCIe Slot for a Redfish implementation.
type PCIeSlot struct {
// HotPluggable is an indication of whether this PCIe slot supports hotplug.
HotPluggable bool
// Lanes is the number of PCIe lanes supported by this slot.
Lanes int
// Location is the location of the PCIe slot.
Location common.Location
// LocationIndicatorActive is an indicator allowing an operator to physically locate this resource.
LocationIndicatorActive bool
// PCIeType is the PCIe specification supported by this slot.
PCIeType PCIeTypes
// SlotType is the PCIe slot type for this slot
SlotType SlotTypes
// Status shall contain any status or health properties of the resource.
Status common.Status
// PCIeDevice shall be an array of links to the PCIe devices contained in this slot.
pcieDevice []string
// PCIeDeviceCount is the number of PCIe devices contained in this slot.
PCIeDeviceCount int
// Processors shall be an array of links to the processors
// that are directly connected or directly bridged to this PCIe slot.
processors []string
// ProcessorsCount is the number of processors
// that are directly connected or directly bridged to this PCIe slot.
ProcessorsCount int
// OEMLinks are all OEM data under link section
OemLinks json.RawMessage
// 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
}
// UnmarshalJSON unmarshals a Slot object from the raw JSON.
func (slot *PCIeSlot) UnmarshalJSON(b []byte) error {
type temp PCIeSlot
type linkReference struct {
PCIeDevice common.Links
PCIeDeviceCount int `json:"[email protected]"`
Processors common.Links
ProcessorsCount int `json:"[email protected]"`
Oem json.RawMessage
}
var t struct {
temp
Links linkReference
}
if err := json.Unmarshal(b, &t); err != nil {
return err
}
*slot = PCIeSlot(t.temp)
slot.pcieDevice = t.Links.PCIeDevice.ToStrings()
slot.PCIeDeviceCount = t.Links.PCIeDeviceCount
slot.processors = t.Links.Processors.ToStrings()
slot.ProcessorsCount = t.Links.ProcessorsCount
slot.OemLinks = t.Links.Oem
return nil
}
// PCIeDevices gets the PCIe devices contained in this slot.
func (slot *PCIeSlot) PCIeDevice(c common.Client) ([]*PCIeDevice, error) {
return common.GetObjects[PCIeDevice](c, slot.pcieDevice)
}
// Processors gets the processors that are directly connected or directly bridged to this PCIe slot.
func (slot *PCIeSlot) Processors(c common.Client) ([]*Processor, error) {
return common.GetObjects[Processor](c, slot.processors)
}
// PCIeSlots is used to represent a PCIeSlots resource for a Redfish implementation.
// This schema has been deprecated in favor of the PCIeDevice schema.
// Empty PCIe slots should be represented by PCIeDevice resources using the `Absent`
// value of the State property within Status.
type PCIeSlots struct {
common.Entity
// ODataContext is the odata context.
ODataContext string `json:"@odata.context"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// Description provides a description of this resource.
Description string
// Slots is an array of PCI Slot information.
Slots []PCIeSlot
// 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
// OemActions contains all the vendor specific actions. It is vendor responsibility to parse this field accordingly
OemActions json.RawMessage
}
// UnmarshalJSON unmarshals a Slot object from the raw JSON.
func (pcieSlots *PCIeSlots) UnmarshalJSON(b []byte) error {
type temp PCIeSlots
type actions struct {
Oem json.RawMessage // OEM actions will be stored here
}
var t struct {
temp
Actions actions
}
if err := json.Unmarshal(b, &t); err != nil {
return err
}
*pcieSlots = PCIeSlots(t.temp)
pcieSlots.OemActions = t.Actions.Oem
return nil
}
// GetPCIeSlots will get a PCIeSlots instance from the chassis.
func GetPCIeSlots(c common.Client, uri string) (*PCIeSlots, error) {
return common.GetObject[PCIeSlots](c, uri)
}