forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhostinterface.go
252 lines (219 loc) · 10.4 KB
/
hostinterface.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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"reflect"
"github.com/stmcginnis/gofish/common"
)
// AuthenticationMode is the method used for authentication.
type AuthenticationMode string
const (
// AuthNoneAuthenticationMode Requests without any sort of authentication
// are allowed.
AuthNoneAuthenticationMode AuthenticationMode = "AuthNone"
// BasicAuthAuthenticationMode Requests using HTTP Basic Authentication
// are allowed.
BasicAuthAuthenticationMode AuthenticationMode = "BasicAuth"
// RedfishSessionAuthAuthenticationMode Requests using Redfish Session
// Authentication are allowed.
RedfishSessionAuthAuthenticationMode AuthenticationMode = "RedfishSessionAuth"
// OemAuthAuthenticationMode Requests using OEM authentication mechanisms
// are allowed.
OemAuthAuthenticationMode AuthenticationMode = "OemAuth"
)
// HostInterfaceType is the type of network interface.
type HostInterfaceType string
const (
// NetworkHostInterfaceHostInterfaceType This interface is a Network Host
// Interface.
NetworkHostInterfaceHostInterfaceType HostInterfaceType = "NetworkHostInterface"
)
type CredentialBootstrapping struct {
// EnableAfterReset shall indicate whether credential bootstrapping is enabled after a reset for this interface. If
// 'true', services shall set the Enabled property to 'true' after a reset of the host or the service.
EnableAfterReset bool
// Enabled shall indicate whether credential bootstrapping is enabled for this interface.
Enabled bool
// RoleID shall contain the ID property of the role resource that is used for the bootstrap account created for
// this interface.
RoleID string
}
// HostInterface is used to represent Host Interface resources as part of
// the Redfish specification.
type HostInterface struct {
common.Entity
// ODataContext is the odata context.
ODataContext string `json:"@odata.context"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// AuthNoneRoleID is used when no authentication on this interface is
// performed. This property shall be absent if AuthNone is not supported
// by the service for the AuthenticationModes property.
AuthNoneRoleID string `json:"AuthNoneRoleId"`
// AuthenticationModes shall be an array consisting of the authentication
// modes allowed on this interface.
AuthenticationModes []AuthenticationMode
// CredentialBootstrapping shall contain settings for the Redfish Host Interface Specification-defined 'credential
// bootstrapping via IPMI commands' feature for this interface. This property shall be absent if credential
// bootstrapping is not supported by the service.
CredentialBootstrapping CredentialBootstrapping
// Description provides a description of this resource.
Description string
// ExternallyAccessible is used by external clients, and this property
// will have the value set to true.
ExternallyAccessible bool
// FirmwareAuthEnabled shall be a boolean
// indicating whether firmware authentication for this interface is
// enabled.
// This property has been deprecated in favor of newer methods of negotiating credentials.
FirmwareAuthEnabled bool
// FirmwareAuthRoleID shall be the ID of the Role resource that is
// configured for firmware authentication on this interface.
// This property has been deprecated in favor of newer methods of negotiating credentials.
FirmwareAuthRoleID string `json:"FirmwareAuthRoleId"`
// HostEthernetInterfaces shall be a link to a collection of type
// EthernetInterfaceCollection that Computer Systems use as the Host
// Interface to this Manager.
hostEthernetInterfaces string
// HostInterfaceType shall be an enumeration describing type of the interface.
HostInterfaceType HostInterfaceType
// InterfaceEnabled shall be a boolean indicating whether this interface is
// enabled.
InterfaceEnabled bool
// KernelAuthEnabled shall be a boolean indicating whether kernel
// authentication for this interface is enabled.
// This property has been deprecated in favor of newer methods of negotiating credentials.
KernelAuthEnabled bool
// KernelAuthRoleID shall be the ID of the Role resource that is configured
// for kernel authentication on this interface.
// This property has been deprecated in favor of newer methods of negotiating credentials.
KernelAuthRoleID string `json:"KernelAuthRoleId"`
// ManagerEthernetInterface is used by this Manager as the HostInterface.
managerEthernetInterface string
// NetworkProtocol shall contain a reference to a resource of type
// ManagerNetworkProtocol which represents the network services for this
// Manager.
networkProtocol string
// Status is This property shall contain any status or health properties
// of the resource.
Status common.Status
// AuthNoneRole shall be a link to a Role object instance, and should
// reference the object identified by property AuthNoneRoleId. This property
// shall be absent if AuthNone is not supported by the service for the
// AuthenticationModes property.
authNoneRole string
// ComputerSystems shall be an array of references to resources of type
// ComputerSystem that are connected to this HostInterface.
computerSystems []string
// ComputerSystemsCount is the number of computer systems.
ComputerSystemsCount int
// CredentialBootstrappingRole shall contain a link to a resource of type Role, and should
// link to the resource identified by the RoleId property within CredentialBootstrapping.
// This property shall be absent if the Redfish Host Interface Specification-defined
// 'credential bootstrapping via IPMI commands' feature is not supported by the service.
credentialBootstrappingRole string
// FirmwareAuthRole shall be a link to a Role object instance, and should
// reference the object identified by property FirmwareAuthRoleID.
// This property has been deprecated in favor of newer methods of negotiating credentials.
firmwareAuthRole string
// KernelAuthRole shall be a link to a Role object instance, and should
// reference the object identified by property KernelAuthRoleId.
// This property has been deprecated in favor of newer methods of negotiating credentials.
kernelAuthRole string
// rawData holds the original serialized JSON so we can compare updates.
rawData []byte
}
// UnmarshalJSON unmarshals a HostInterface object from the raw JSON.
func (hostinterface *HostInterface) UnmarshalJSON(b []byte) error {
type temp HostInterface
type links struct {
AuthNoneRole common.Link
ComputerSystems common.Links
ComputerSystemsCount int `json:"[email protected]"`
CredentialBootstrappingRole common.Link
FirmwareAuthRole common.Link
KernelAuthRole common.Link
}
var t struct {
temp
Links links
HostEthernetInterfaces common.Link
ManagerEthernetInterface common.Link
NetworkProtocol common.Link
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
*hostinterface = HostInterface(t.temp)
// Extract the links to other entities for later
hostinterface.authNoneRole = t.Links.AuthNoneRole.String()
hostinterface.computerSystems = t.Links.ComputerSystems.ToStrings()
hostinterface.ComputerSystemsCount = t.Links.ComputerSystemsCount
hostinterface.credentialBootstrappingRole = t.Links.CredentialBootstrappingRole.String()
hostinterface.firmwareAuthRole = t.Links.FirmwareAuthRole.String()
hostinterface.kernelAuthRole = t.Links.KernelAuthRole.String()
hostinterface.hostEthernetInterfaces = t.HostEthernetInterfaces.String()
hostinterface.managerEthernetInterface = t.ManagerEthernetInterface.String()
hostinterface.networkProtocol = t.NetworkProtocol.String()
// This is a read/write object, so we need to save the raw object data for later
hostinterface.rawData = b
return nil
}
// Update commits updates to this object's properties to the running system.
func (hostinterface *HostInterface) Update() error {
// Get a representation of the object's original state so we can find what
// to update.
original := new(HostInterface)
err := original.UnmarshalJSON(hostinterface.rawData)
if err != nil {
return err
}
readWriteFields := []string{
"AuthNoneRoleId",
"AuthenticationModes",
"InterfaceEnabled",
}
originalElement := reflect.ValueOf(original).Elem()
currentElement := reflect.ValueOf(hostinterface).Elem()
return hostinterface.Entity.Update(originalElement, currentElement, readWriteFields)
}
// GetHostInterface will get a HostInterface instance from the service.
func GetHostInterface(c common.Client, uri string) (*HostInterface, error) {
return common.GetObject[HostInterface](c, uri)
}
// ListReferencedHostInterfaces gets the collection of HostInterface from
// a provided reference.
func ListReferencedHostInterfaces(c common.Client, link string) ([]*HostInterface, error) {
return common.GetCollectionObjects[HostInterface](c, link)
}
// ComputerSystems references the ComputerSystems that this host interface is associated with.
func (hostinterface *HostInterface) ComputerSystems() ([]*ComputerSystem, error) {
return common.GetObjects[ComputerSystem](hostinterface.GetClient(), hostinterface.computerSystems)
}
// HostEthernetInterfaces gets the network interface controllers or cards (NICs)
// that a Computer System uses to communicate with this Host Interface.
func (hostinterface *HostInterface) HostEthernetInterfaces() ([]*EthernetInterface, error) {
return ListReferencedEthernetInterfaces(hostinterface.GetClient(), hostinterface.hostEthernetInterfaces)
}
// ManagerNetworkInterfaces gets the network interface controllers or cards
// (NIC) that this Manager uses for network communication with this Host Interface.
func (hostinterface *HostInterface) ManagerNetworkInterfaces() ([]*EthernetInterface, error) {
return ListReferencedEthernetInterfaces(hostinterface.GetClient(), hostinterface.managerEthernetInterface)
}
// AuthRoleNone gets the role that contains the privileges on this host interface when no authentication is performed.
func (hostinterface *HostInterface) AuthNoneRole() (*Role, error) {
if hostinterface.authNoneRole == "" {
return nil, nil
}
return GetRole(hostinterface.GetClient(), hostinterface.authNoneRole)
}
// CredentialBootstrappingRole gets the role that contains the privileges for the bootstrap account created for this interface.
func (hostinterface *HostInterface) CredentialBootstrappingRole() (*Role, error) {
if hostinterface.credentialBootstrappingRole == "" {
return nil, nil
}
return GetRole(hostinterface.GetClient(), hostinterface.credentialBootstrappingRole)
}