forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathethernetinterface.go
479 lines (431 loc) · 20.3 KB
/
ethernetinterface.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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"reflect"
"github.com/stmcginnis/gofish/common"
)
type DHCPFallback string
const (
// StaticDHCPFallback shall fall back to a static address specified by IPv4StaticAddresses.
StaticDHCPFallback DHCPFallback = "Static"
// AutoConfigDHCPFallback shall fall back to an address generated by the implementation.
AutoConfigDHCPFallback DHCPFallback = "AutoConfig"
// NoneDHCPFallback shall continue trying to obtain an address without falling back to a fixed address.
NoneDHCPFallback DHCPFallback = "None"
)
// DHCPv6OperatingMode is the IPv6 DHCP mode.
type DHCPv6OperatingMode string
const (
// StatefulDHCPv6OperatingMode shall operate in stateful mode on this
// interface. DHCPv6 stateful mode is used to configure addresses, and
// when it is enabled, stateless mode is also implicitly enabled.
StatefulDHCPv6OperatingMode DHCPv6OperatingMode = "Stateful"
// StatelessDHCPv6OperatingMode shall operate in stateless mode on this
// interface. DHCPv6 stateless mode allows configuring the interface
// using DHCP options but does not configure addresses. It is always
// enabled by default whenever DHCPv6 Stateful mode is also enabled.
StatelessDHCPv6OperatingMode DHCPv6OperatingMode = "Stateless"
// DisabledDHCPv6OperatingMode shall be disabled for this interface.
DisabledDHCPv6OperatingMode DHCPv6OperatingMode = "Disabled"
)
// EthernetDeviceType is the device type.
type EthernetDeviceType string
const (
// PhysicalEthernetDeviceType shall indicate a physical traditional
// network interface.
PhysicalEthernetDeviceType EthernetDeviceType = "Physical"
// VirtualEthernetDeviceType shall indicate a network device function has
// multiple VLANs and is representing one of them as a virtual Ethernet
// interface. The NetworkDeviceFunction property within Links shall
// contain the locator for the parent network device function.
VirtualEthernetDeviceType EthernetDeviceType = "Virtual"
)
// LinkStatus is the interface link status.
type LinkStatus string
const (
// LinkUpLinkStatus The link is available for communication on this
// interface.
LinkUpLinkStatus LinkStatus = "LinkUp"
// NoLinkLinkStatus There is no link or connection detected on this
// interface.
NoLinkLinkStatus LinkStatus = "NoLink"
// LinkDownLinkStatus There is no link on this interface, but the
// interface is connected.
LinkDownLinkStatus LinkStatus = "LinkDown"
)
type RoutingScope string
const (
// ExternalRoutingScope shall indicate this interface is externally accessible as if it were physically on the same
// network as the hosting system.
ExternalRoutingScope RoutingScope = "External"
// HostOnlyRoutingScope shall indicate this interface is only accessible to a dedicated interface on the hosting
// system.
HostOnlyRoutingScope RoutingScope = "HostOnly"
// InternalRoutingScope shall indicate this interface is only accessible to internal networking on the host, such
// as when virtual machines or containers are allowed to communicate with each other on the same host system as
// well as a dedicated interface on the hosting system.
InternalRoutingScope RoutingScope = "Internal"
// LimitedRoutingScope shall indicate this interface is accessible through IP translation provided by the hosting
// system, such as a NAT (network address translation).
LimitedRoutingScope RoutingScope = "Limited"
)
type TeamMode string
const (
// NoneTeamMode No teaming.
NoneTeamMode TeamMode = "None"
// RoundRobinTeamMode Packets are transmitted in sequential order from the teamed interfaces.
RoundRobinTeamMode TeamMode = "RoundRobin"
// ActiveBackupTeamMode One interface in the team is active and the others are kept in standby until a failure
// occurs.
ActiveBackupTeamMode TeamMode = "ActiveBackup"
// XORTeamMode Transmitting is determined based upon a hash policy.
XORTeamMode TeamMode = "XOR"
// BroadcastTeamMode Packets are transmitted on all interfaces in the team.
BroadcastTeamMode TeamMode = "Broadcast"
// IEEE8023adTeamMode The interfaces in the team create an IEEE802.3ad link aggregation group.
IEEE8023adTeamMode TeamMode = "IEEE802_3ad"
// AdaptiveTransmitLoadBalancingTeamMode Packets are transmitted based upon the current load of each interface in
// the team.
AdaptiveTransmitLoadBalancingTeamMode TeamMode = "AdaptiveTransmitLoadBalancing"
// AdaptiveLoadBalancingTeamMode Packets are transmitted and received based upon the current load of each interface
// in the team.
AdaptiveLoadBalancingTeamMode TeamMode = "AdaptiveLoadBalancing"
)
// DHCPv4Configuration describes the configuration of DHCP v4.
type DHCPv4Configuration struct {
// DHCPEnabled shall indicate whether DHCP v4 is enabled for this
// EthernetInterface.
DHCPEnabled bool
// FallbackAddress shall contain the fallback address method of DHCPv4.
FallbackAddress DHCPFallback `json:",omitempty"`
// UseDNSServers shall indicate whether the interface will use
// DHCPv4-supplied DNS servers.
UseDNSServers bool `json:",omitempty"`
// UseDomainName shall indicate whether the interface will use a
// DHCPv4-supplied domain name.
UseDomainName bool `json:",omitempty"`
// UseGateway shall indicate whether the interface will use a
// DHCPv4-supplied gateway.
UseGateway bool `json:",omitempty"`
// UseNTPServers shall indicate whether the interface will use
// DHCPv4-supplied NTP servers.
UseNTPServers bool `json:",omitempty"`
// UseStaticRoutes shall indicate whether the interface will use a
// DHCPv4-supplied static routes.
UseStaticRoutes bool `json:",omitempty"`
}
// DHCPv6Configuration describes the configuration of DHCP v6.
type DHCPv6Configuration struct {
// OperatingMode is used to configure addresses, and when it is enabled,
// stateless mode is also implicitly enabled.
OperatingMode DHCPv6OperatingMode
// UseDNSServers shall indicate whether the interface will use
// DHCPv6-supplied DNS servers.
UseDNSServers bool
// UseDomainName shall indicate whether the interface will use a domain name
// supplied through DHCPv6 stateless mode.
UseDomainName bool
// UseNTPServers shall indicate whether the interface will use
// DHCPv6-supplied NTP servers.
UseNTPServers bool
// UseRapidCommit shall indicate whether the interface will use DHCPv6 rapid
// commit mode for stateful mode address assignments.
UseRapidCommit bool
}
// EthernetInterface is used to represent NIC resources.
type EthernetInterface struct {
common.Entity
// ODataContext is the odata context.
ODataContext string `json:"@odata.context"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// AutoNeg shall be true if auto negotiation of speed and duplex is enabled
// on this interface and false if it is disabled.
AutoNeg bool
// DHCPv4 shall contain the configuration of DHCP v4.
DHCPv4 DHCPv4Configuration
// DHCPv6 shall contain the configuration of DHCP v6.
DHCPv6 DHCPv6Configuration
// Description provides a description of this resource.
Description string
// EthernetInterfaceType shall contain the type of interface.
EthernetInterfaceType EthernetDeviceType
// FQDN shall be the fully qualified domain name for this interface.
FQDN string
// FullDuplex shall represent the duplex status of the Ethernet connection
// on this interface.
FullDuplex bool
// HostName shall be host name for this interface.
HostName string
// IPv4Addresses is used to represent the IPv4 connection characteristics
// for this interface. It is recommended that this property be regarded as
// read-only, with configuration of static addresses performed by
// updating the values within IPv4StaticAddresses. Services may reject
// updates to this array for this reason.
IPv4Addresses []IPv4Address
// IPv4StaticAddresses is used to represent all IPv4 static addresses
// assigned (but not necessarily in use) to this interface. Addresses in
// use by this interface shall also appear in the IPv4Addresses property.
IPv4StaticAddresses []IPv4Address
// IPv6AddressPolicyTable is used to represent the Address Selection
// Policy Table as defined in RFC 6724.
IPv6AddressPolicyTable []IPv6AddressPolicyEntry
// IPv6Addresses is used to represent the IPv6 connection characteristics
// for this interface.
IPv6Addresses []IPv6Address
// IPv6DefaultGateway shall be the current
// IPv6 default gateway address that is in use on this interface.
IPv6DefaultGateway string
// IPv6Enabled shall indicate whether IPv6 is enabled on this interface. If this property contains 'false', the
// interface shall not contain any assigned IPv6 addresses, shall not initiate DHCPv6 requests, and shall not send
// or process ICMPv6 packets. If this property is not present, but this interface contains other IPv6 properties,
// the value shall be assumed to be 'true'.
IPv6Enabled bool
// IPv6StaticAddresses is used to represent the IPv6 static connection
// characteristics for this interface.
IPv6StaticAddresses []IPv6StaticAddress
// IPv6StaticDefaultGateways is The values in this array shall represent
// the IPv6 static default gateway addresses for this interface.
IPv6StaticDefaultGateways []IPv6GatewayStaticAddress
// InterfaceEnabled shall be a boolean
// indicating whether this interface is enabled.
InterfaceEnabled bool
// LinkStatus shall be the link status of this interface (port).
LinkStatus LinkStatus
// MACAddress shall be the effective
// current MAC Address of this interface. If an assignable MAC address is
// not supported, this is a read only alias of the PermanentMACAddress.
MACAddress string
// MTUSize shall be the size in bytes of largest Protocol Data Unit (PDU)
// that can be passed in an Ethernet (MAC) frame on this interface.
MTUSize int
// MaxIPv6StaticAddresses shall indicate the number of array items supported
// by IPv6StaticAddresses.
MaxIPv6StaticAddresses int
// NameServers used on this interface.
NameServers []string
// Oem object used on this interface.
Oem json.RawMessage
// PermanentMACAddress shall be the Permanent MAC Address of this interface
// (port). This value is typically programmed during the manufacturing time.
// This address is not assignable.
PermanentMACAddress string
// RoutingScope shall contain the routing scope for this interface. This property shall only be present if this
// interface belongs to a virtual machine or container.
RoutingScope RoutingScope
// SpeedMbps shall be the link speed of the interface in Mbps.
SpeedMbps int
// StatelessAddressAutoConfig is This object shall contain the IPv4 and
// IPv6 Stateless Address Automatic Configuration (SLAAC) properties for
// this interface.
StatelessAddressAutoConfig StatelessAddressAutoConfiguration
// StaticNameServers is used when DHCP provisioning is not in enabled for
// name server configuration. As an implementation option they may also
// be used in addition to DHCP provided addresses, or in cases where the
// DHCP server provides no DNS assignments.
StaticNameServers []string
// Status shall contain any status or health properties
// of the resource.
Status common.Status
// TeamMode shall contain the team mode for this interface. If this property is not present, the value shall be
// assumed to be 'None'.
TeamMode TeamMode
// UefiDevicePath shall be the UEFI device path to the device which
// implements this interface (port).
UefiDevicePath string
// VLAN shall contain the VLAN for this interface. If this interface supports more than one VLAN, the VLAN property
// shall be absent and, instead, the VLANs call should be used instead.
VLAN VLAN
// VLANs is a collection of VLANs and is only used if the interface supports
// more than one VLANs, applies only if the interface supports more than one VLAN. If this property
// is present, the VLANEnabled and VLANId properties shall not be present.
// This property has been deprecated in favor of newer methods indicating multiple VLANs.
vlans string
affiliatedInterfaces []string
// AffiliatedInterfacesCount is the number of affiliated interfaces.
AffiliatedInterfacesCount int
// Chassis shall be a reference to a resource of type Chassis that represent
// the physical container associated with this Ethernet Interface.
chassis string
// Endpoints shall be a reference to the resources that this ethernet
// interface is associated with and shall reference a resource of type
// Endpoint.
endpoints []string
// EndpointsCount is the number of endpoints.
EndpointsCount int
// HostInterface is used by a host to communicate with a Manager.
hostInterface string
networkDeviceFunctions []string
// NetworkDeviceFunctionsCount are the number of network device functions associated with this interface.
NetworkDeviceFunctionsCount int
ports []string
// PortsCount is the number of ports associated with this interface.
PortsCount int
relatedInterfaces []string
// RelatedInterfacesCount is the number of related interfaces.
RelatedInterfacesCount int
// rawData holds the original serialized JSON so we can compare updates.
rawData []byte
}
// UnmarshalJSON unmarshals a EthernetInterface object from the raw JSON.
func (ethernetinterface *EthernetInterface) UnmarshalJSON(b []byte) error {
type temp EthernetInterface
type links struct {
// AffiliatedInterfaces shall contain an array of links to resources of type EthernetInterface that represent the
// Ethernet interfaces that are affiliated with this interface. EthernetInterface resources referenced in this
// property shall reference this resource in their RelatedInterfaces property.
AffiliatedInterfaces common.Links
AffiliatedInterfacesCount int `json:"[email protected]"`
Chassis common.Link
Endpoints common.Links
EndpointsCount int `json:"[email protected]"`
HostInterface common.Link
// NetworkDeviceFunctions shall contain an array of links to resources of type NetworkDeviceFunction.
NetworkDeviceFunctions common.Links
NetworkDeviceFunctionsCount int `json:"[email protected]"`
// Ports shall contain an array of links to resources of type Port that represent the ports providing this Ethernet
// interface. This property shall not be present if the Ethernet interface is not directly associated to a physical
// port.
Ports common.Links
PortsCount int `json:"[email protected]"`
// RelatedInterfaces shall contain an array of links to resources of type EthernetInterface. If TeamMode contains
// 'None', this property shall contain one member that represents the parent interface for the VLAN. For other
// values of TeamMode, this property shall contain the members of the team.
RelatedInterfaces common.Links
RelatedInterfacesCount int `json:"[email protected]"`
}
var t struct {
temp
Links links
VLANs common.Link
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
*ethernetinterface = EthernetInterface(t.temp)
// Extract the links to other entities for later
ethernetinterface.affiliatedInterfaces = t.Links.AffiliatedInterfaces.ToStrings()
ethernetinterface.AffiliatedInterfacesCount = t.Links.AffiliatedInterfacesCount
ethernetinterface.chassis = t.Links.Chassis.String()
ethernetinterface.endpoints = t.Links.Endpoints.ToStrings()
ethernetinterface.EndpointsCount = t.Links.EndpointsCount
ethernetinterface.hostInterface = t.Links.HostInterface.String()
ethernetinterface.networkDeviceFunctions = t.Links.NetworkDeviceFunctions.ToStrings()
ethernetinterface.NetworkDeviceFunctionsCount = t.Links.NetworkDeviceFunctionsCount
ethernetinterface.ports = t.Links.Ports.ToStrings()
ethernetinterface.PortsCount = t.Links.PortsCount
ethernetinterface.relatedInterfaces = t.Links.RelatedInterfaces.ToStrings()
ethernetinterface.RelatedInterfacesCount = t.Links.RelatedInterfacesCount
ethernetinterface.vlans = t.VLANs.String()
// This is a read/write object, so we need to save the raw object data for later
ethernetinterface.rawData = b
return nil
}
// Update commits updates to this object's properties to the running system.
func (ethernetinterface *EthernetInterface) Update() error {
// Get a representation of the object's original state so we can find what
// to update.
original := new(EthernetInterface)
err := original.UnmarshalJSON(ethernetinterface.rawData)
if err != nil {
return err
}
readWriteFields := []string{
"AutoNeg",
"DHCPv4",
"DHCPv6",
"FQDN",
"FullDuplex",
"HostName",
"IPv4StaticAddresses",
"IPv6AddressPolicyTable",
"IPv6Enabled",
"IPv6StaticAddresses",
"IPv6StaticDefaultGateways",
"InterfaceEnabled",
"MACAddress",
"MTUSize",
"SpeedMbps",
"StatelessAddressAutoConfig",
"StaticNameServers",
"TeamMode",
"VLAN",
}
originalElement := reflect.ValueOf(original).Elem()
currentElement := reflect.ValueOf(ethernetinterface).Elem()
return ethernetinterface.Entity.Update(originalElement, currentElement, readWriteFields)
}
// GetEthernetInterface will get a EthernetInterface instance from the service.
func GetEthernetInterface(c common.Client, uri string) (*EthernetInterface, error) {
return common.GetObject[EthernetInterface](c, uri)
}
// ListReferencedEthernetInterfaces gets the collection of EthernetInterface from
// a provided reference.
func ListReferencedEthernetInterfaces(c common.Client, link string) ([]*EthernetInterface, error) {
return common.GetCollectionObjects[EthernetInterface](c, link)
}
// IPv6AddressPolicyEntry describes and entry in the Address Selection Policy
// Table as defined in RFC 6724.
type IPv6AddressPolicyEntry struct {
// Label shall contain the IPv6 Label value for this table entry as defined
// in RFC 6724 section 2.1.
Label int
// Precedence shall contain the IPv6 Precedence value for this table entry
// as defined in RFC 6724 section 2.1.
Precedence int
// Prefix shall contain the IPv6 Address Prefix for this table entry as
// defined in RFC 6724 section 2.1.
Prefix string
}
// StatelessAddressAutoConfiguration describes the IPv4 and IPv6 Stateless
// Address Automatic Configuration (SLAAC) for this interface.
type StatelessAddressAutoConfiguration struct {
// IPv4AutoConfigEnabled shall indicate whether IPv4 Stateless Address
// Auto-Configuration (SLAAC) is enabled for this interface.
IPv4AutoConfigEnabled bool
// IPv6AutoConfigEnabled shall indicate whether IPv6 Stateless Address
// Auto-Configuration (SLAAC) is enabled for this interface.
IPv6AutoConfigEnabled bool
}
// VLAN gets the VLAN for this interface. If this interface supports more than one VLAN, the VLAN call
// will return nil and the VLANs call should be used instead.
func (ethernetinterface *EthernetInterface) VLANs() ([]*VLanNetworkInterface, error) {
return ListReferencedVLanNetworkInterfaces(ethernetinterface.GetClient(), ethernetinterface.vlans)
}
// AffiliatedInterfaces gets any ethernet interfaces that are affiliated with this interface.
func (ethernetinterface *EthernetInterface) AffiliatedInterfaces() ([]*EthernetInterface, error) {
return common.GetObjects[EthernetInterface](ethernetinterface.GetClient(), ethernetinterface.affiliatedInterfaces)
}
// Chassis gets the containing chassis.
func (ethernetinterface *EthernetInterface) Chassis() (*Chassis, error) {
if ethernetinterface.chassis == "" {
return nil, nil
}
return GetChassis(ethernetinterface.GetClient(), ethernetinterface.chassis)
}
// Endpoints gets any endpoints associated with this interface.
func (ethernetinterface *EthernetInterface) Endpoints() ([]*Endpoint, error) {
return common.GetObjects[Endpoint](ethernetinterface.GetClient(), ethernetinterface.endpoints)
}
// HostInterface gets the associated host interface.
func (ethernetinterface *EthernetInterface) HostInterface() (*HostInterface, error) {
if ethernetinterface.hostInterface == "" {
return nil, nil
}
return GetHostInterface(ethernetinterface.GetClient(), ethernetinterface.hostInterface)
}
// NetworkDeviceFunctions gets any device functions associated with this interface.
func (ethernetinterface *EthernetInterface) NetworkDeviceFunctions() ([]*NetworkDeviceFunction, error) {
return common.GetObjects[NetworkDeviceFunction](ethernetinterface.GetClient(), ethernetinterface.networkDeviceFunctions)
}
// Ports gets any ports associated with this interface.
func (ethernetinterface *EthernetInterface) Ports() ([]*Port, error) {
return common.GetObjects[Port](ethernetinterface.GetClient(), ethernetinterface.ports)
}