File: types_system_info_params.go

package info (click to toggle)
golang-github-bougou-go-ipmi 0.7.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,880 kB
  • sloc: makefile: 38
file content (436 lines) | stat: -rw-r--r-- 13,939 bytes parent folder | download
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
package ipmi

import (
	"fmt"
)

type SystemInfoParamSelector uint8

const (
	SystemInfoParamSelector_SetInProgress         SystemInfoParamSelector = 0
	SystemInfoParamSelector_SystemFirmwareVersion SystemInfoParamSelector = 1
	SystemInfoParamSelector_SystemName            SystemInfoParamSelector = 2
	SystemInfoParamSelector_PrimaryOSName         SystemInfoParamSelector = 3
	SystemInfoParamSelector_OSName                SystemInfoParamSelector = 4
	SystemInfoParamSelector_OSVersion             SystemInfoParamSelector = 5
	SystemInfoParamSelector_BMCURL                SystemInfoParamSelector = 6
	SystemInfoParamSelector_ManagementURL         SystemInfoParamSelector = 7
)

func (paramSelector SystemInfoParamSelector) String() string {
	m := map[SystemInfoParamSelector]string{
		SystemInfoParamSelector_SetInProgress:         "Set In Progress",
		SystemInfoParamSelector_SystemFirmwareVersion: "System Firmware Version",
		SystemInfoParamSelector_SystemName:            "System Name",
		SystemInfoParamSelector_PrimaryOSName:         "Primary OS Name",
		SystemInfoParamSelector_OSName:                "OS Name",
		SystemInfoParamSelector_OSVersion:             "OS Version",
		SystemInfoParamSelector_BMCURL:                "BMC URL",
		SystemInfoParamSelector_ManagementURL:         "Management URL",
	}
	s, ok := m[paramSelector]
	if ok {
		return s
	}
	return "Unknown"
}

type SystemInfoParameter interface {
	SystemInfoParameter() (paramSelector SystemInfoParamSelector, setSelector uint8, blockSelector uint8)
	Parameter
}

var (
	_ SystemInfoParameter = (*SystemInfoParam_SetInProgress)(nil)
	_ SystemInfoParameter = (*SystemInfoParam_SystemFirmwareVersion)(nil)
	_ SystemInfoParameter = (*SystemInfoParam_SystemName)(nil)
	_ SystemInfoParameter = (*SystemInfoParam_PrimaryOSName)(nil)
	_ SystemInfoParameter = (*SystemInfoParam_OSName)(nil)
	_ SystemInfoParameter = (*SystemInfoParam_OSVersion)(nil)
	_ SystemInfoParameter = (*SystemInfoParam_BMCURL)(nil)
	_ SystemInfoParameter = (*SystemInfoParam_ManagementURL)(nil)
)

func isNilSystemInfoParamete(param SystemInfoParameter) bool {
	switch v := param.(type) {
	case *SystemInfoParam_SetInProgress:
		return v == nil
	case *SystemInfoParam_SystemFirmwareVersion:
		return v == nil
	case *SystemInfoParam_SystemName:
		return v == nil
	case *SystemInfoParam_PrimaryOSName:
		return v == nil
	case *SystemInfoParam_OSName:
		return v == nil
	case *SystemInfoParam_OSVersion:
		return v == nil
	case *SystemInfoParam_BMCURL:
		return v == nil
	case *SystemInfoParam_ManagementURL:
		return v == nil
	default:
		return false
	}
}

type SystemInfoParams struct {
	SetInProgress          *SystemInfoParam_SetInProgress
	SystemFirmwareVersions []*SystemInfoParam_SystemFirmwareVersion
	SystemNames            []*SystemInfoParam_SystemName
	PrimaryOSNames         []*SystemInfoParam_PrimaryOSName
	OSNames                []*SystemInfoParam_OSName
	OSVersions             []*SystemInfoParam_OSVersion
	BMCURLs                []*SystemInfoParam_BMCURL
	ManagementURLs         []*SystemInfoParam_ManagementURL
}

type SystemInfo struct {
	SetInProgress         SetInProgressState
	SystemFirmwareVersion string
	SystemName            string
	PrimaryOSName         string
	OSName                string
	OSVersion             string
	BMCURL                string
	ManagementURL         string
}

func (systemInfoParams *SystemInfoParams) ToSystemInfo() *SystemInfo {
	systemInfo := &SystemInfo{
		SetInProgress: systemInfoParams.SetInProgress.Value,
	}

	systemInfo.SystemFirmwareVersion, _, _, _ = getSystemInfoStringMeta(convertToInterfaceSlice(systemInfoParams.SystemFirmwareVersions))
	systemInfo.SystemName, _, _, _ = getSystemInfoStringMeta(convertToInterfaceSlice(systemInfoParams.SystemNames))
	systemInfo.PrimaryOSName, _, _, _ = getSystemInfoStringMeta(convertToInterfaceSlice(systemInfoParams.PrimaryOSNames))
	systemInfo.OSName, _, _, _ = getSystemInfoStringMeta(convertToInterfaceSlice(systemInfoParams.OSNames))
	systemInfo.OSVersion, _, _, _ = getSystemInfoStringMeta(convertToInterfaceSlice(systemInfoParams.OSVersions))
	systemInfo.BMCURL, _, _, _ = getSystemInfoStringMeta(convertToInterfaceSlice(systemInfoParams.BMCURLs))
	systemInfo.ManagementURL, _, _, _ = getSystemInfoStringMeta(convertToInterfaceSlice(systemInfoParams.ManagementURLs))

	return systemInfo
}

func (systemInfoParams *SystemInfoParams) Format() string {
	format := func(param SystemInfoParameter) string {
		if isNilSystemInfoParamete(param) {
			return ""
		}
		paramSelector, _, _ := param.SystemInfoParameter()
		content := param.Format()
		if content[len(content)-1] != '\n' {
			content += "\n"
		}
		return fmt.Sprintf("[%02d] %-24s : %s", paramSelector, paramSelector.String(), content)
	}

	formatArray := func(params []interface{}) string {
		if len(params) == 0 {
			return ""
		}
		out := ""
		for _, param := range params {
			v, ok := param.(SystemInfoParameter)
			if ok {
				out += format(v)
			}
		}
		s, stringDataRaw, stringDataType, stringDataLength := getSystemInfoStringMeta(params)

		return "" +
			fmt.Sprintf("String Data Type   : %d\n", stringDataType) +
			fmt.Sprintf("String Data Length : %d\n", stringDataLength) +
			fmt.Sprintf("String Data Raw    : %v\n", stringDataRaw) +
			fmt.Sprintf("String Data        : %s\n", s)
	}

	out := ""
	out += format(systemInfoParams.SetInProgress)
	out += formatArray(convertToInterfaceSlice(systemInfoParams.SystemFirmwareVersions))
	out += formatArray(convertToInterfaceSlice(systemInfoParams.SystemNames))
	out += formatArray(convertToInterfaceSlice(systemInfoParams.PrimaryOSNames))
	out += formatArray(convertToInterfaceSlice(systemInfoParams.OSNames))
	out += formatArray(convertToInterfaceSlice(systemInfoParams.OSVersions))
	out += formatArray(convertToInterfaceSlice(systemInfoParams.BMCURLs))
	out += formatArray(convertToInterfaceSlice(systemInfoParams.ManagementURLs))

	return out
}

func (systemInfo *SystemInfo) Format() string {
	return "" +
		fmt.Sprintf("Set In Progress         : %s\n", systemInfo.SetInProgress) +
		fmt.Sprintf("System Firmware Version : %s\n", systemInfo.SystemFirmwareVersion) +
		fmt.Sprintf("System Name             : %s\n", systemInfo.SystemName) +
		fmt.Sprintf("Primary OS Name         : %s\n", systemInfo.PrimaryOSName) +
		fmt.Sprintf("OS Name                 : %s\n", systemInfo.OSName) +
		fmt.Sprintf("OS Version              : %s\n", systemInfo.OSVersion) +
		fmt.Sprintf("BMC URL                 : %s\n", systemInfo.BMCURL) +
		fmt.Sprintf("Management URL          : %s\n", systemInfo.ManagementURL)
}

type SystemInfoParam_SetInProgress struct {
	Value SetInProgressState
}

func (p *SystemInfoParam_SetInProgress) SystemInfoParameter() (paramSelector SystemInfoParamSelector, setSelector uint8, blockSelector uint8) {
	return SystemInfoParamSelector_SetInProgress, 0, 0
}

func (p *SystemInfoParam_SetInProgress) Pack() []byte {
	return []byte{uint8(p.Value)}
}

func (p *SystemInfoParam_SetInProgress) Unpack(data []byte) error {
	if len(data) < 1 {
		return ErrUnpackedDataTooShortWith(len(data), 1)
	}
	p.Value = SetInProgressState(data[0])
	return nil
}

func (p *SystemInfoParam_SetInProgress) Format() string {
	return p.Value.String()
}

type SystemInfoParam_SystemFirmwareVersion struct {
	SetSelector uint8
	BlockData   []byte
}

func (p *SystemInfoParam_SystemFirmwareVersion) SystemInfoParameter() (paramSelector SystemInfoParamSelector, setSelector uint8, blockSelector uint8) {
	return SystemInfoParamSelector_SystemFirmwareVersion, p.SetSelector, 0
}

func (p *SystemInfoParam_SystemFirmwareVersion) Pack() []byte {
	out := make([]byte, 1+len(p.BlockData))
	packUint8(p.SetSelector, out, 0)
	packBytes(p.BlockData[:], out, 1)
	return out
}

func (p *SystemInfoParam_SystemFirmwareVersion) Unpack(data []byte) error {
	if len(data) < 1+len(p.BlockData) {
		return ErrUnpackedDataTooShortWith(len(data), 1+len(p.BlockData))
	}
	p.SetSelector = data[0]

	if len(data) > 1 {
		p.BlockData = make([]byte, len(data)-1)
		copy(p.BlockData[:], data[1:])
	}
	return nil
}

func (p *SystemInfoParam_SystemFirmwareVersion) Format() string {
	return "" +
		fmt.Sprintf("Set Selector : %d\n", p.SetSelector) +
		fmt.Sprintf("Block Data   : %02x\n", p.BlockData)
}

type SystemInfoParam_SystemName struct {
	SetSelector uint8
	BlockData   []byte
}

func (p *SystemInfoParam_SystemName) SystemInfoParameter() (paramSelector SystemInfoParamSelector, setSelector uint8, blockSelector uint8) {
	return SystemInfoParamSelector_SystemName, p.SetSelector, 0
}

func (p *SystemInfoParam_SystemName) Pack() []byte {
	out := make([]byte, 1+len(p.BlockData))
	packUint8(p.SetSelector, out, 0)
	packBytes(p.BlockData[:], out, 1)
	return out
}

func (p *SystemInfoParam_SystemName) Unpack(data []byte) error {
	if len(data) < 1+len(p.BlockData) {
		return ErrUnpackedDataTooShortWith(len(data), 1+len(p.BlockData))
	}
	p.SetSelector = data[0]

	if len(data) > 1 {
		p.BlockData = make([]byte, len(data)-1)
		copy(p.BlockData[:], data[1:])
	}
	return nil
}

func (p *SystemInfoParam_SystemName) Format() string {
	return "" +
		fmt.Sprintf("Set Selector : %d\n", p.SetSelector) +
		fmt.Sprintf("Block Data   : %02x\n", p.BlockData)
}

type SystemInfoParam_PrimaryOSName struct {
	SetSelector uint8
	BlockData   []byte
}

func (p *SystemInfoParam_PrimaryOSName) SystemInfoParameter() (paramSelector SystemInfoParamSelector, setSelector uint8, blockSelector uint8) {
	return SystemInfoParamSelector_PrimaryOSName, p.SetSelector, 0
}

func (p *SystemInfoParam_PrimaryOSName) Pack() []byte {
	out := make([]byte, 1+len(p.BlockData))
	packUint8(p.SetSelector, out, 0)
	packBytes(p.BlockData[:], out, 1)
	return out
}

func (p *SystemInfoParam_PrimaryOSName) Unpack(data []byte) error {
	if len(data) < 1+len(p.BlockData) {
		return ErrUnpackedDataTooShortWith(len(data), 1+len(p.BlockData))
	}
	p.SetSelector = data[0]
	if len(data) > 1 {
		p.BlockData = make([]byte, len(data)-1)
		copy(p.BlockData[:], data[1:])
	}
	return nil
}

func (p *SystemInfoParam_PrimaryOSName) Format() string {
	return "" +
		fmt.Sprintf("Set Selector : %d\n", p.SetSelector) +
		fmt.Sprintf("Block Data   : %02x\n", p.BlockData)
}

type SystemInfoParam_OSName struct {
	SetSelector uint8
	BlockData   []byte
}

func (p *SystemInfoParam_OSName) SystemInfoParameter() (paramSelector SystemInfoParamSelector, setSelector uint8, blockSelector uint8) {
	return SystemInfoParamSelector_OSName, p.SetSelector, 0
}

func (p *SystemInfoParam_OSName) Pack() []byte {
	out := make([]byte, 1+len(p.BlockData))
	packUint8(p.SetSelector, out, 0)
	packBytes(p.BlockData[:], out, 1)
	return out
}

func (p *SystemInfoParam_OSName) Unpack(data []byte) error {
	if len(data) < 1+len(p.BlockData) {
		return ErrUnpackedDataTooShortWith(len(data), 1+len(p.BlockData))
	}
	p.SetSelector = data[0]

	if len(data) > 1 {
		p.BlockData = make([]byte, len(data)-1)
		copy(p.BlockData[:], data[1:])
	}
	return nil
}

func (p *SystemInfoParam_OSName) Format() string {
	return "" +
		fmt.Sprintf("Set Selector : %d\n", p.SetSelector) +
		fmt.Sprintf("Block Data   : %02x\n", p.BlockData)
}

type SystemInfoParam_OSVersion struct {
	SetSelector uint8
	BlockData   []byte
}

func (p *SystemInfoParam_OSVersion) SystemInfoParameter() (paramSelector SystemInfoParamSelector, setSelector uint8, blockSelector uint8) {
	return SystemInfoParamSelector_OSVersion, p.SetSelector, 0
}

func (p *SystemInfoParam_OSVersion) Pack() []byte {
	out := make([]byte, 1+len(p.BlockData))
	packUint8(p.SetSelector, out, 0)
	packBytes(p.BlockData[:], out, 1)
	return out
}

func (p *SystemInfoParam_OSVersion) Unpack(data []byte) error {
	if len(data) < 1+len(p.BlockData) {
		return ErrUnpackedDataTooShortWith(len(data), 1+len(p.BlockData))
	}
	p.SetSelector = data[0]
	if len(data) > 1 {
		p.BlockData = make([]byte, len(data)-1)
		copy(p.BlockData[:], data[1:])
	}
	return nil
}

func (p *SystemInfoParam_OSVersion) Format() string {
	return "" +
		fmt.Sprintf("Set Selector : %d\n", p.SetSelector) +
		fmt.Sprintf("Block Data   : %02x\n", p.BlockData)
}

type SystemInfoParam_BMCURL struct {
	SetSelector uint8
	BlockData   []byte
}

func (p *SystemInfoParam_BMCURL) SystemInfoParameter() (paramSelector SystemInfoParamSelector, setSelector uint8, blockSelector uint8) {
	return SystemInfoParamSelector_BMCURL, p.SetSelector, 0
}

func (p *SystemInfoParam_BMCURL) Pack() []byte {
	out := make([]byte, 1+len(p.BlockData))
	packUint8(p.SetSelector, out, 0)
	packBytes(p.BlockData[:], out, 1)
	return out
}

func (p *SystemInfoParam_BMCURL) Unpack(data []byte) error {
	if len(data) < 1+len(p.BlockData) {
		return ErrUnpackedDataTooShortWith(len(data), 1+len(p.BlockData))
	}
	p.SetSelector = data[0]
	if len(data) > 1 {
		p.BlockData = make([]byte, len(data)-1)
		copy(p.BlockData[:], data[1:])
	}
	return nil
}

func (p *SystemInfoParam_BMCURL) Format() string {
	return "" +
		fmt.Sprintf("Set Selector : %d\n", p.SetSelector) +
		fmt.Sprintf("Block Data   : %02x\n", p.BlockData)
}

type SystemInfoParam_ManagementURL struct {
	SetSelector uint8
	BlockData   []byte
}

func (p *SystemInfoParam_ManagementURL) SystemInfoParameter() (paramSelector SystemInfoParamSelector, setSelector uint8, blockSelector uint8) {
	return SystemInfoParamSelector_ManagementURL, p.SetSelector, 0
}

func (p *SystemInfoParam_ManagementURL) Pack() []byte {
	out := make([]byte, 1+len(p.BlockData))
	packUint8(p.SetSelector, out, 0)
	packBytes(p.BlockData[:], out, 1)
	return out
}

func (p *SystemInfoParam_ManagementURL) Unpack(data []byte) error {
	if len(data) < 1+len(p.BlockData) {
		return ErrUnpackedDataTooShortWith(len(data), 1+len(p.BlockData))
	}
	p.SetSelector = data[0]
	if len(data) > 1 {
		p.BlockData = make([]byte, len(data)-1)
		copy(p.BlockData[:], data[1:])
	}
	return nil
}

func (p *SystemInfoParam_ManagementURL) Format() string {
	return "" +
		fmt.Sprintf("Set Selector : %d\n", p.SetSelector) +
		fmt.Sprintf("Block Data   : %02x\n", p.BlockData)
}