forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetworkadapter.go
300 lines (271 loc) · 10.7 KB
/
networkadapter.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
294
295
296
297
298
299
300
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"github.com/stmcginnis/gofish/common"
)
// ControllerCapabilities shall describe the capabilities of a controller.
type ControllerCapabilities struct {
// DataCenterBridging shall contain capability, status,
// and configuration values related to Data Center Bridging (DCB) for
// this controller.
DataCenterBridging struct {
Capable bool
}
// NPAR shall contain capability, status, and
// configuration values related to NIC partitioning for this controller.
NPAR struct {
// NparCapable shall indicate the ability of a
// controller to support NIC function partitioning.
NparCapable bool
// NparEnabled shall indicate whether or not NIC
// function partitioning is active on this controller.
NparEnabled bool
}
// NPIV shall contain N_Port ID Virtualization (NPIV)
// capabilties for this controller.
NPIV struct {
// MaxDeviceLogins shall be the maximum
// number of N_Port ID Virtualization (NPIV) logins allowed
// simultaneously from all ports on this controller.
MaxDeviceLogins int
// MaxPortLogins shall be the maximum
// number of N_Port ID Virtualization (NPIV) logins allowed per physical
// port on this controller.
MaxPortLogins int
}
// NetworkDeviceFunctionCount shall be the
// number of physical functions available on this controller.
NetworkDeviceFunctionCount int
// NetworkPortCount shall be the number of
// physical ports on this controller.
NetworkPortCount int
// VirtualizationOffload shall contain capability, status,
// and configuration values related to virtualization offload for this
// controller.
VirtualizationOffload struct {
// SRIOV shall contain Single-Root Input/Output Virtualization (SR-IOV)
// capabilities.
SRIOV struct {
//SRIOVVEPACapable shall be a boolean indicating whether this
// controller supports Single Root Input/Output Virtualization
// (SR-IOV) in Virtual Ethernet Port Aggregator (VEPA) mode.
SRIOVVEPACapable bool
}
// VirtualFunction shall describe the capability, status, and
// configuration values related to the virtual function for this controller.
VirtualFunction struct {
// DeviceMaxCount shall be the maximum number of Virtual Functions
// (VFs) supported by this controller.
DeviceMaxCount int
// MinAssignmentGroupSize shall be the minimum number of Virtual
// Functions (VFs) that can be allocated or moved between physical
// functions for this controller.
MinAssignmentGroupSize int
// NetworkPortMaxCount shall be the maximum number of Virtual
// Functions (VFs) supported per network port for this controller.
NetworkPortMaxCount int
}
}
}
// Controllers shall describe a network controller ASIC that makes up part of a
// NetworkAdapter.
type Controllers struct {
// ControllerCapabilities shall contain the capabilities of this controller.
ControllerCapabilities ControllerCapabilities
// FirmwarePackageVersion shall be the version number of the user-facing
// firmware package.
FirmwarePackageVersion string
// Location shall contain location information of the associated network
// adapter controller. TODO: Needs to be a Location struct.
//Location string
// PCIeInterface is used to connect this PCIe-based controller to its host.
PCIeInterface PCIeInterface
// NetworkDeviceFunctions shall be an array of references of type
// NetworkDeviceFunction that represent the Network Device Functions
// associated with this Network Controller.
networkDeviceFunctions []string
// NetworkDeviceFunctionsCount is the number of network device functions.
NetworkDeviceFunctionsCount int
// NetworkPorts shall be an array of references of type NetworkPort that
// represent the Network Ports associated with this Network Controller.
networkPorts []string
// NetworkPortsCount is the number of network ports.
NetworkPortsCount int
// PCIeDevices shall be an array of references of type PCIeDevice that
// represent the PCI-e Devices associated with this Network Controller.
pcieDevices []string
// PCIeDevicesCount is the number of PCIeDevices.
PCIeDevicesCount int
}
// UnmarshalJSON unmarshals a Controllers object from the raw JSON.
func (controllers *Controllers) UnmarshalJSON(b []byte) error {
type temp Controllers
type links struct {
NetworkPorts common.Links
NetworkPortsCount int `json:"[email protected]"`
NetworkDeviceFunctions common.Links
NetworkDeviceFunctionsCount int `json:"[email protected]"`
PCIeDevice common.Link
PCIeDevicesCount int `json:"[email protected]"`
}
var t struct {
temp
Links links
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
// Extract the links to other entities for later
*controllers = Controllers(t.temp)
controllers.networkPorts = t.Links.NetworkPorts.ToStrings()
controllers.NetworkPortsCount = t.Links.NetworkPortsCount
controllers.networkDeviceFunctions = t.Links.NetworkDeviceFunctions.ToStrings()
controllers.NetworkDeviceFunctionsCount = t.Links.NetworkDeviceFunctionsCount
controllers.pcieDevices = t.Links.NetworkDeviceFunctions.ToStrings()
controllers.PCIeDevicesCount = t.Links.NetworkDeviceFunctionsCount
return nil
}
// DataCenterBridging shall describe the capability, status,
// and configuration values related to Data Center Bridging (DCB) for a
// controller.
type DataCenterBridging struct {
// Capable shall be a boolean indicating whether this controller is capable
// of Data Center Bridging (DCB).
Capable bool
}
// NPIV shall contain N_Port ID Virtualization (NPIV) capabilties for a
// controller.
type NPIV struct {
// MaxDeviceLogins shall be the maximum number of N_Port ID Virtualization
// (NPIV) logins allowed simultaneously from all ports on this controller.
MaxDeviceLogins int
// MaxPortLogins shall be the maximum number of N_Port ID Virtualization
// (NPIV) logins allowed per physical port on this controller.
MaxPortLogins int
}
// A NetworkAdapter represents the physical network adapter capable of
// connecting to a computer network. Examples include but are not limited to
// Ethernet, Fibre Channel, and converged network adapters.
type NetworkAdapter struct {
common.Entity
// ODataContext is the odata context.
ODataContext string `json:"@odata.context"`
// ODataEtag is the odata etag.
ODataEtag string `json:"@odata.etag"`
// ODataID is the odata identifier.
ODataID string `json:"@odata.id"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// Assembly shall be a link to a resource of type Assembly.
assembly string
// Controllers shall contain the set of network controllers ASICs that make
// up this NetworkAdapter.
Controllers []Controllers
// Description provides a description of this resource.
Description string
// Manufacturer shall contain a value that represents the manufacturer of
// the network adapter.
Manufacturer string
// Model shall contain the information about how the manufacturer references
// this network adapter.
Model string
// NetworkDeviceFunctions shall be a link to a collection of type
// NetworkDeviceFunctionCollection.
networkDeviceFunctions string
// NetworkPorts shall be a link to a collection of type NetworkPortCollection.
networkPorts string
// PartNumber shall contain the part number for the network adapter as
// defined by the manufacturer.
PartNumber string
// SKU shall contain the Stock Keeping Unit (SKU) for the network adapter.
SKU string
// SerialNumber shall contain the serial number for the network adapter.
SerialNumber string
// Status shall contain any status or health properties of the resource.
Status common.Status
// resetSettingsToDefaultTarget is the URL for sending a ResetSettingsToDefault action
resetSettingsToDefaultTarget string
}
// UnmarshalJSON unmarshals a NetworkAdapter object from the raw JSON.
func (networkadapter *NetworkAdapter) UnmarshalJSON(b []byte) error {
type temp NetworkAdapter
type actions struct {
ResetSettingsToDefault struct {
Target string
} `json:"#NetworkAdapter.ResetSettingsToDefault"`
}
var t struct {
temp
Assembly common.Link
NetworkDeviceFunctions common.Link
NetworkPorts common.Link
Actions actions
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
// Extract the links to other entities for later
*networkadapter = NetworkAdapter(t.temp)
networkadapter.assembly = string(t.Assembly)
networkadapter.networkDeviceFunctions = string(t.NetworkDeviceFunctions)
networkadapter.networkPorts = string(t.NetworkPorts)
networkadapter.resetSettingsToDefaultTarget = t.Actions.ResetSettingsToDefault.Target
return nil
}
// GetNetworkAdapter will get a NetworkAdapter instance from the Redfish service.
func GetNetworkAdapter(c common.Client, uri string) (*NetworkAdapter, error) {
resp, err := c.Get(uri)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var networkAdapter NetworkAdapter
err = json.NewDecoder(resp.Body).Decode(&networkAdapter)
if err != nil {
return nil, err
}
networkAdapter.SetClient(c)
return &networkAdapter, nil
}
// ListReferencedNetworkAdapter gets the collection of Chassis from a provided reference.
func ListReferencedNetworkAdapter(c common.Client, link string) ([]*NetworkAdapter, error) {
var result []*NetworkAdapter
links, err := common.GetCollection(c, link)
if err != nil {
return result, err
}
for _, networkAdapterLink := range links.ItemLinks {
networkAdapter, err := GetNetworkAdapter(c, networkAdapterLink)
if err != nil {
return result, err
}
result = append(result, networkAdapter)
}
return result, nil
}
// Assembly gets this adapter's assembly.
func (networkadapter *NetworkAdapter) Assembly() (*Assembly, error) {
if networkadapter.assembly == "" {
return nil, nil
}
return GetAssembly(networkadapter.Client, networkadapter.assembly)
}
// NetworkDeviceFunctions gets the collection of NetworkDeviceFunctions of this network adapter
func (networkadapter *NetworkAdapter) NetworkDeviceFunctions() ([]*NetworkDeviceFunction, error) {
return ListReferencedNetworkDeviceFunctions(networkadapter.Client, networkadapter.networkDeviceFunctions)
}
// NetworkPorts gets the collection of NetworkPorts for this network adapter
func (networkadapter *NetworkAdapter) NetworkPorts() ([]*NetworkPort, error) {
return ListReferencedNetworkPorts(networkadapter.Client, networkadapter.networkPorts)
}
// ResetSettingsToDefault shall perform a reset of all active and pending
// settings back to factory default settings upon reset of the network adapter.
func (networkadapter *NetworkAdapter) ResetSettingsToDefault() error {
_, err := networkadapter.Client.Post(networkadapter.resetSettingsToDefaultTarget, nil)
return err
}