forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcable.go
293 lines (266 loc) · 12.3 KB
/
cable.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"reflect"
"github.com/stmcginnis/gofish/common"
)
type CableClass string
const (
// PowerCableClass is used for connecting to a power system.
PowerCableClass CableClass = "Power"
// NetworkCableClass is used for connecting to a networking system.
NetworkCableClass CableClass = "Network"
// StorageCableClass is used for connecting to a storage system.
StorageCableClass CableClass = "Storage"
// FanCableClass is used for connecting to a fan system.
FanCableClass CableClass = "Fan"
// PCIeCableClass is used for connecting to a PCIe endpoint.
PCIeCableClass CableClass = "PCIe"
// USBCableClass is used for connecting to a USB endpoint.
USBCableClass CableClass = "USB"
// VideoCableClass is used for connecting to a video system.
VideoCableClass CableClass = "Video"
// FabricCableClass is used for connecting to a fabric.
FabricCableClass CableClass = "Fabric"
// SerialCableClass is used for connecting to a serial endpoint.
SerialCableClass CableClass = "Serial"
// GeneralCableClass is used for providing general connectivity.
GeneralCableClass CableClass = "General"
)
type CableStatus string
const (
// NormalCableStatus shall indicate the cable is operating normally. The State property in Status shall contain the
// value 'Enabled' and the Health property in Status shall contain the value 'OK'.
NormalCableStatus CableStatus = "Normal"
// DegradedCableStatus shall indicate the cable is degraded. The State property in Status shall contain the value
// 'Enabled' and the Health property in Status shall contain the value 'Warning'.
DegradedCableStatus CableStatus = "Degraded"
// FailedCableStatus shall indicate the cable has failed. The State property in Status shall contain the value
// 'Enabled' and the Health property in Status shall contain the value 'Critical'.
FailedCableStatus CableStatus = "Failed"
// TestingCableStatus shall indicate the cable is under test. The State property in Status shall contain the value
// 'InTest'.
TestingCableStatus CableStatus = "Testing"
// DisabledCableStatus shall indicate the cable is disabled. The State property in Status shall contain the value
// 'Disabled'.
DisabledCableStatus CableStatus = "Disabled"
// SetByServiceCableStatus shall indicate the status for the cable is not defined by the user. If implemented, the
// service shall determine the value of the State and Health properties in Status.
SetByServiceCableStatus CableStatus = "SetByService"
)
type CableConnectorType string
const (
// ACPowerCableConnectorType This cable connects to an AC power connector.
ACPowerCableConnectorType CableConnectorType = "ACPower"
// DB9CableConnectorType This cable connects to a DB9 connector.
DB9CableConnectorType CableConnectorType = "DB9"
// DCPowerCableConnectorType This cable connects to a DC power connector.
DCPowerCableConnectorType CableConnectorType = "DCPower"
// DisplayPortCableConnectorType This cable connects to a DisplayPort power connector.
DisplayPortCableConnectorType CableConnectorType = "DisplayPort"
// HDMICableConnectorType This cable connects to an HDMI connector.
HDMICableConnectorType CableConnectorType = "HDMI"
// ICICableConnectorType This cable connects to an ICI connector.
ICICableConnectorType CableConnectorType = "ICI"
// IPASSCableConnectorType This cable connects to an IPASS connector.
IPASSCableConnectorType CableConnectorType = "IPASS"
// PCIeCableConnectorType This cable connects to a PCIe connector.
PCIeCableConnectorType CableConnectorType = "PCIe"
// ProprietaryCableConnectorType This cable connects to a proprietary connector.
ProprietaryCableConnectorType CableConnectorType = "Proprietary"
// RJ45CableConnectorType This cable connects to an RJ45 connector.
RJ45CableConnectorType CableConnectorType = "RJ45"
// SATACableConnectorType This cable connects to a SATA connector.
SATACableConnectorType CableConnectorType = "SATA"
// SCSICableConnectorType This cable connects to a SCSI connector.
SCSICableConnectorType CableConnectorType = "SCSI"
// SlimSASCableConnectorType This cable connects to a SlimSAS connector.
SlimSASCableConnectorType CableConnectorType = "SlimSAS"
// SFPCableConnectorType This cable connects to an SFP connector.
SFPCableConnectorType CableConnectorType = "SFP"
// SFPPlusCableConnectorType This cable connects to an SFPPlus connector.
SFPPlusCableConnectorType CableConnectorType = "SFPPlus"
// USBACableConnectorType This cable connects to a USB-A connector.
USBACableConnectorType CableConnectorType = "USBA"
// USBCCableConnectorType This cable connects to a USB-C connector.
USBCCableConnectorType CableConnectorType = "USBC"
// QSFPCableConnectorType This cable connects to a QSFP connector.
QSFPCableConnectorType CableConnectorType = "QSFP"
// CDFPCableConnectorType This cable connects to a CDFP connector.
CDFPCableConnectorType CableConnectorType = "CDFP"
// OSFPCableConnectorType This cable connects to an OSFP connector.
OSFPCableConnectorType CableConnectorType = "OSFP"
)
// Cable contains a simple cable for a Redfish implementation.
type Cable 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"`
// Assembly shall contain a link to a resource of type Assembly.
Assembly string
// AssetTag shall track the cable for inventory purposes.
AssetTag string
// CableClass shall contain the cable class for this cable.
CableClass CableClass
// CableStatus shall contain the user-reported status of this resource.
CableStatus CableStatus
// CableType shall contain a user-defined type for this cable.
CableType string
// Description provides a description of this resource.
Description string
// DownstreamConnectorTypes shall contain an array of connector types this cable supports.
DownstreamConnectorTypes []CableConnectorType
// DownstreamName shall contain any identifier for a downstream resource.
DownstreamName string
// LengthMeters shall contain the length of the cable in meters.
LengthMeters float64
// Location shall contain the location information of the associated assembly.
Location common.Location
// Manufacturer shall contain the name of the organization responsible for producing the cable. This organization
// might be the entity from whom the cable is purchased, but this is not necessarily true.
Manufacturer string
// Model shall contain the name by which the manufacturer generally refers to the cable.
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 part number assigned by the organization that is responsible for producing or
// manufacturing the cable.
PartNumber string
// SKU shall contain the stock-keeping unit (SKU) number for this cable.
SKU string
// SerialNumber shall contain the manufacturer-allocated number that identifies the cable.
SerialNumber string
// Status shall contain any status or health properties of the resource.
Status common.Status
// UpstreamConnectorTypes shall contain an array of connector types this cable supports.
UpstreamConnectorTypes []CableConnectorType
// UpstreamName shall contain any identifier for an upstream resource.
UpstreamName string
// UserDescription shall contain a user-defined description for this cable.
UserDescription string
// UserLabel shall contain a user-assigned label used to identify this resource. If a value has not been assigned
// by a user, the value of this property shall be an empty string.
UserLabel string
// Vendor shall contain the name of the company that provides the final product that includes this cable.
Vendor string
// rawData holds the original serialized JSON so we can compare updates.
rawData []byte
downstreamChassis []string
// DownstreamChassisCount is the number of physical downstream containers connected to this cable.
DownstreamChassisCount int
downstreamPorts []string
// DownstreamPortsCount is the number of physical downstream connections connected to this cable.
DownstreamPortsCount int
downstreamResources []string
// DownstreamResourcesCount is the number of physical downstream resources connected to this cable.
DownstreamResourcesCount int
upstreamChassis []string
// UpstreamChassisCount is the number of physical upstream containers connected to this cable.
UpstreamChassisCount int
upstreamPorts []string
// UpstreamPortsCount is the number of physical upstream connections connected to this cable.
UpstreamPortsCount int
upstreamResources []string
// UpstreamResourcesCount is the number of physical upstream resources connected to this cable.
UpstreamResourcesCount int
}
// UnmarshalJSON unmarshals a Cable object from the raw JSON.
func (cable *Cable) UnmarshalJSON(b []byte) error {
type temp Cable
type Links struct {
DownstreamChassis common.Links
DownstreamChassisCount int `json:"[email protected]"`
DownstreamPorts common.Links
DownstreamPortsCount int `json:"[email protected]"`
DownstreamResources common.Links
DownstreamResourcesCount int `json:"[email protected]"`
OEM json.RawMessage `json:"Oem"`
UpstreamChassis common.Links
UpstreamChassisCount int `json:"[email protected]"`
UpstreamPorts common.Links
UpstreamPortsCount int `json:"[email protected]"`
UpstreamResources common.Links
UpstreamResourcesCount int `json:"[email protected]"`
}
var t struct {
temp
Links Links
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
*cable = Cable(t.temp)
// Extract the links to other entities for later
cable.downstreamChassis = t.Links.DownstreamChassis.ToStrings()
cable.downstreamPorts = t.Links.DownstreamPorts.ToStrings()
cable.downstreamResources = t.Links.DownstreamResources.ToStrings()
cable.upstreamChassis = t.Links.UpstreamChassis.ToStrings()
cable.upstreamPorts = t.Links.UpstreamPorts.ToStrings()
cable.upstreamResources = t.Links.UpstreamResources.ToStrings()
// This is a read/write object, so we need to save the raw object data for later
cable.rawData = b
return nil
}
// DownstreamChassis gets the physical downstream containers connected to this cable.
func (cable *Cable) DownstreamChassis() ([]*Chassis, error) {
return common.GetObjects[Chassis](cable.GetClient(), cable.downstreamChassis)
}
// DownstreamPorts gets the physical downstream connections connected to this cable.
func (cable *Cable) DownstreamPorts() ([]*Port, error) {
return common.GetObjects[Port](cable.GetClient(), cable.downstreamPorts)
}
// UpstreamChassis gets the physical upstream containers connected to this cable.
func (cable *Cable) UpstreamChassis() ([]*Chassis, error) {
return common.GetObjects[Chassis](cable.GetClient(), cable.upstreamChassis)
}
// UpstreamPorts gets the physical upstream connections connected to this cable.
func (cable *Cable) UptreamPorts() ([]*Port, error) {
return common.GetObjects[Port](cable.GetClient(), cable.upstreamPorts)
}
// Update commits updates to this object's properties to the running system.
func (cable *Cable) Update() error {
// Get a representation of the object's original state so we can find what
// to update.
original := new(Cable)
original.UnmarshalJSON(cable.rawData)
readWriteFields := []string{
"AssetTag",
"CableClass",
"CableStatus",
"CableType",
"DownstreamConnectorTypes",
"DownstreamName",
"LengthMeters",
"Manufacturer",
"Model",
"PartNumber",
"SKU",
"SerialNumber",
"UpstreamConnectorTypes",
"UpstreamName",
"UserDescription",
"UserLabel",
"Vendor",
}
originalElement := reflect.ValueOf(original).Elem()
currentElement := reflect.ValueOf(cable).Elem()
return cable.Entity.Update(originalElement, currentElement, readWriteFields)
}
// GetCable will get a Cable instance from the service.
func GetCable(c common.Client, uri string) (*Cable, error) {
return common.GetObject[Cable](c, uri)
}
// ListReferencedCables gets the collection of Cable from
// a provided reference.
func ListReferencedCables(c common.Client, link string) ([]*Cable, error) {
return common.GetCollectionObjects[Cable](c, link)
}